I did a migration after of created my database structure using make:entity
command :
$ symfony console make:migration
Now, I want to migrate to a specific schema into my PostgresSQL
database.
In the documentation of Symfony says:
MANUAL TABLES. It is a common use case, that in addition to your generated database structure based on your doctrine entities you might need custom tables. By default, such tables will be removed by the doctrine:migrations:diff
command. If you follow a specific scheme you can configure doctrine/dbal to ignore those tables. Let’s say all custom tables will be prefixed by t_. In this case, you just have to add the following configuration option to your doctrine configuration:
doctrine: dbal: schema_filter: ~^(?!t_)~
I understand that schema_filter
is a filter applied to table names (only tables?) through a regular expression. Well, but schema_filter
no reference the schemas created into a PostgreSQL
database.
Then how can I migrate to a specific schema into a database?
When I execute the command:
$ symfony console make:migration
it creates a migration file that contains a class with the functions 'up' and 'down', both with a parameter $schema
. Here a fragment:
public function up(Schema $schema) : void
{
// this up() 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 SEQUENCE division_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
This parameter can't assign a value when it is declared. Must be null.
Is it possible to use it to migrate to a specific schema?
Well, while I find a way, I did it like this:
public function up(Schema $schema) : void { // this up() 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 SEQUENCE my_schema_name.division_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
I mean that I write the schema name in all migration code generate by the command.
But I still believe that is possible to do it in another way. If yes then how?
I forgot it. Migration fails when I try with this line before of first sentence:
$this->addSql('SET search_path TO my_schema_name');
Also I try assigning the schema name to the parameter $schema:
$schema = 'my_schema_name'
It didn't work either.