既存の postgres データベースに接続して、Symfony プロジェクトでdoctrineを使用しています。
DB にはいくつかのスキーマがありますが、symfony アプリは独自のスキーマしか使用しません。最初Entity
に作成したクラスは次のとおりです。
namespace Belka\TestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="app_auth.User", schema="app_auth")
*/
class User {
/**
* @ORM\Column(type="string")
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
private $username;
/**
* @ORM\Column(type="string")
*/
private $email;
/**
* @ORM\Column(type="string")
*/
private $password;
}
ご覧のEntity
とおり、 は独自の schema を指定していますapp_auth
。次に、マイグレーション バンドルを使用してみました。したがって、自分のスキーマ以外は考慮しないように、インストールして構成しました。
の抜粋config.yml
:
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
schema_filter: ~^app_auth\..*~
の抜粋config_dev.yml
:
doctrine_migrations:
dir_name: "%kernel.root_dir%/../.container/update/DoctrineMigrations"
namespace: Application\Migrations
table_name: "app_auth.migration_versions"
name: Application Migrations
そして、私は差分を実行します:
php app/console doctrine:migrations:diff
残念ながら、生成された移行クラスは次のとおりです。
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160422171409 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SCHEMA app_auth');
}
}
私の構成の何が問題になっていますか?