1414
1515use function method_exists ;
1616use function preg_match ;
17- use function strpos ;
18- use function substr ;
1917
2018/**
2119 * The DiffGenerator class is responsible for comparing two Doctrine\DBAL\Schema\Schema instances and generating a
@@ -46,14 +44,22 @@ public function generate(
4644 bool $ checkDbPlatform = true ,
4745 bool $ fromEmptySchema = false ,
4846 ): string {
47+ $ toSchema = $ this ->createToSchema ();
48+
4949 if ($ filterExpression !== null ) {
50+ // whitelist assets we already know about in $toSchema, use the existing $filterExpression otherwise
51+ // @see https://github.com/doctrine/orm/pull/7875
5052 $ this ->dbalConfiguration ->setSchemaAssetsFilter (
51- static function ($ assetName ) use ($ filterExpression) {
53+ static function ($ assetName ) use ($ filterExpression, $ toSchema ): bool {
5254 if ($ assetName instanceof AbstractAsset) {
5355 $ assetName = $ assetName ->getName ();
5456 }
5557
56- return preg_match ($ filterExpression , $ assetName );
58+ if ($ toSchema ->hasTable ($ assetName ) || $ toSchema ->hasSequence ($ assetName )) {
59+ return true ;
60+ }
61+
62+ return (bool ) preg_match ($ filterExpression , $ assetName );
5763 },
5864 );
5965 }
@@ -62,8 +68,6 @@ static function ($assetName) use ($filterExpression) {
6268 ? $ this ->createEmptySchema ()
6369 : $ this ->createFromSchema ();
6470
65- $ toSchema = $ this ->createToSchema ();
66-
6771 // prior to DBAL 4.0, the schema name was set to the first element in the search path,
6872 // which is not necessarily the default schema name
6973 if (
@@ -119,35 +123,6 @@ private function createFromSchema(): Schema
119123
120124 private function createToSchema (): Schema
121125 {
122- $ toSchema = $ this ->schemaProvider ->createSchema ();
123-
124- $ schemaAssetsFilter = $ this ->dbalConfiguration ->getSchemaAssetsFilter ();
125-
126- if ($ schemaAssetsFilter !== null ) {
127- foreach ($ toSchema ->getTables () as $ table ) {
128- $ tableName = $ table ->getName ();
129-
130- if ($ schemaAssetsFilter ($ this ->resolveTableName ($ tableName ))) {
131- continue ;
132- }
133-
134- $ toSchema ->dropTable ($ tableName );
135- }
136- }
137-
138- return $ toSchema ;
139- }
140-
141- /**
142- * Resolve a table name from its fully qualified name. The `$name` argument
143- * comes from Doctrine\DBAL\Schema\Table#getName which can sometimes return
144- * a namespaced name with the form `{namespace}.{tableName}`. This extracts
145- * the table name from that.
146- */
147- private function resolveTableName (string $ name ): string
148- {
149- $ pos = strpos ($ name , '. ' );
150-
151- return $ pos === false ? $ name : substr ($ name , $ pos + 1 );
126+ return $ this ->schemaProvider ->createSchema ();
152127 }
153128}
0 commit comments