Skip to content

Using explicit inclusion in schema_filter causes unexpected behavior when diffing database #1327

@thsmrtone1

Description

@thsmrtone1

Bug Report

Q A
BC Break yes/no
Version 3.5.5
  • Azure SQL Database (reproduces on docker MSSQL Server 2019)
  • sqlsrv driver
  • DBAL 3.5.3
  • DoctrineMigrationsBundle 3.2.2
  • doctrine migrations 3.5.5
  • ORM 2.14.1

Summary

Perhaps I've stumbled upon unsupported usage of schema_filter. If so, please let me know. Please note that this example is using a MSSQL database, which seems to use "schemas" much differently than other platforms. I have not tested on other platforms.

I'm trying to use the schema_filter config parameter to limit my project to one specific schema (instead of excluding a number of schemas). For example:

# doctrine.yaml
doctrine:
  dbal:
    schema_filter: ~^my_schema.~

All entities have been defined with both a schema and table name, for example:

#[ORM\Entity()]
#[ORM\Table(name: 'my_table', schema: 'my_schema')]
class MyTable {
  // ...
}

For the purposes of this bug report, assume that my_table already exists in my_schema in the database.

When executing bin/console doctrine:migrations:diff, I would expect a blank migration to be created, since there are no changes needed, however a migration is being created containing the following:

$this->addSql('DROP TABLE my_schema.my_table');

It appears that the issue is likely caused by this line in DiffGenerator::createToSchema():

foreach ($toSchema->getTables() as $table) {
    $tableName = $table->getName();

    if ($schemaAssetsFilter($this->resolveTableName($tableName))) {  // <--- Issue here
        continue;
    }

    $toSchema->dropTable($tableName);
}

When $tableName is "my_schema.my_table", then resolveTableName() will remove "my_schema." from the name. RegexSchemaAssetFilter will then return false because it does not match the schema_filter in the config, thus making the migration drop the table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions