|
14 | 14 |
|
15 | 15 | use function method_exists;
|
16 | 16 | use function preg_match;
|
17 |
| -use function strpos; |
18 |
| -use function substr; |
19 | 17 |
|
20 | 18 | /**
|
21 | 19 | * The DiffGenerator class is responsible for comparing two Doctrine\DBAL\Schema\Schema instances and generating a
|
@@ -46,24 +44,30 @@ public function generate(
|
46 | 44 | bool $checkDbPlatform = true,
|
47 | 45 | bool $fromEmptySchema = false,
|
48 | 46 | ): string {
|
| 47 | + $toSchema = $this->createToSchema(); |
| 48 | + |
49 | 49 | 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 |
50 | 52 | $this->dbalConfiguration->setSchemaAssetsFilter(
|
51 |
| - static function ($assetName) use ($filterExpression) { |
| 53 | + static function ($assetName) use ($filterExpression, $toSchema): bool { |
52 | 54 | if ($assetName instanceof AbstractAsset) {
|
53 | 55 | $assetName = $assetName->getName();
|
54 | 56 | }
|
55 | 57 |
|
56 |
| - return preg_match($filterExpression, $assetName); |
57 |
| - }, |
| 58 | + if ($toSchema->hasTable($assetName) || $toSchema->hasSequence($assetName)) { |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + return (bool) preg_match($filterExpression, $assetName); |
| 63 | + } |
58 | 64 | );
|
59 | 65 | }
|
60 | 66 |
|
61 | 67 | $fromSchema = $fromEmptySchema
|
62 | 68 | ? $this->createEmptySchema()
|
63 | 69 | : $this->createFromSchema();
|
64 | 70 |
|
65 |
| - $toSchema = $this->createToSchema(); |
66 |
| - |
67 | 71 | // prior to DBAL 4.0, the schema name was set to the first element in the search path,
|
68 | 72 | // which is not necessarily the default schema name
|
69 | 73 | if (
|
@@ -119,35 +123,6 @@ private function createFromSchema(): Schema
|
119 | 123 |
|
120 | 124 | private function createToSchema(): Schema
|
121 | 125 | {
|
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(); |
152 | 127 | }
|
153 | 128 | }
|
0 commit comments