Skip to content

Commit 97f7232

Browse files
committed
Merge branch '4.3.x' into 5.0.x
2 parents 660cc2e + 7ca7250 commit 97f7232

14 files changed

+267
-265
lines changed

src/Platforms/AbstractMySQLPlatform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ protected function supportsColumnCollation(): bool
226226
*/
227227
public function getColumnTypeSQLSnippet(string $tableAlias, string $databaseName): string
228228
{
229-
return $tableAlias . '.COLUMN_TYPE';
229+
return $tableAlias . '.DATA_TYPE';
230230
}
231231

232232
/**

src/Platforms/MariaDBPlatform.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias, string $databaseName
4848
// The check for `CONSTRAINT_SCHEMA = $databaseName` is mandatory here to prevent performance issues
4949
return <<<SQL
5050
IF(
51-
$tableAlias.COLUMN_TYPE = 'longtext'
51+
$tableAlias.DATA_TYPE = 'longtext'
5252
AND EXISTS(
5353
SELECT * FROM information_schema.CHECK_CONSTRAINTS $subQueryAlias
5454
WHERE $subQueryAlias.CONSTRAINT_SCHEMA = $databaseName
@@ -60,7 +60,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias, string $databaseName
6060
)
6161
),
6262
'json',
63-
$tableAlias.COLUMN_TYPE
63+
$tableAlias.DATA_TYPE
6464
)
6565
SQL;
6666
}

src/Platforms/PostgreSQLPlatform.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,7 @@ protected function initializeDoctrineTypeMappings(): void
709709
'bytea' => Types::BLOB,
710710
'char' => Types::STRING,
711711
'date' => Types::DATE_MUTABLE,
712-
'datetime' => Types::DATETIME_MUTABLE,
713712
'decimal' => Types::DECIMAL,
714-
'double' => Types::FLOAT,
715713
'double precision' => Types::FLOAT,
716714
'float' => Types::FLOAT,
717715
'float4' => Types::SMALLFLOAT,
@@ -740,7 +738,6 @@ protected function initializeDoctrineTypeMappings(): void
740738
'tsvector' => Types::TEXT,
741739
'uuid' => Types::GUID,
742740
'varchar' => Types::STRING,
743-
'year' => Types::DATE_MUTABLE,
744741
'_varchar' => Types::STRING,
745742
];
746743
}

src/Schema/AbstractSchemaManager.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ public function listTables(): array
293293
->setName(
294294
OptionallyQualifiedName::quoted($unqualifiedName, $qualifier),
295295
)
296-
->setColumns($this->_getPortableTableColumnList($tableColumns))
296+
->setColumns(
297+
...array_values($this->_getPortableTableColumnList($tableColumns)),
298+
)
297299
->setIndexes(
298-
$this->_getPortableTableIndexesList(
300+
...array_values($this->_getPortableTableIndexesList(
299301
$indexColumnsByTable[$schemaNameKey][$unqualifiedName] ?? [],
300-
),
302+
)),
301303
);
302304

303305
if (isset($primaryKeyColumnsByTable[$schemaNameKey][$unqualifiedName])) {
@@ -310,9 +312,9 @@ public function listTables(): array
310312

311313
if (isset($foreignKeyColumnsByTable[$schemaNameKey][$unqualifiedName])) {
312314
$editor->setForeignKeyConstraints(
313-
$this->_getPortableTableForeignKeysList(
315+
...array_values($this->_getPortableTableForeignKeysList(
314316
$foreignKeyColumnsByTable[$schemaNameKey][$unqualifiedName],
315-
),
317+
)),
316318
);
317319
}
318320

@@ -598,10 +600,10 @@ public function introspectTable(string $name): Table
598600

599601
return Table::editor()
600602
->setName($tableName)
601-
->setColumns($columns)
603+
->setColumns(...array_values($columns))
602604
->setPrimaryKeyConstraint($this->getTablePrimaryKeyConstraint($name))
603-
->setIndexes($this->listTableIndexes($name))
604-
->setForeignKeyConstraints($this->listTableForeignKeys($name))
605+
->setIndexes(...array_values($this->listTableIndexes($name)))
606+
->setForeignKeyConstraints(...array_values($this->listTableForeignKeys($name)))
605607
->setOptions($this->getTableOptions($tableName))
606608
->create();
607609
}

src/Schema/Exception/InvalidTableDefinition.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public static function nameNotSet(): self
1313
{
1414
return new self('Table name is not set.');
1515
}
16+
17+
public static function columnsNotSet(): self
18+
{
19+
return new self('Table columns are not set.');
20+
}
1621
}

src/Schema/MySQLSchemaManager.php

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
use function func_get_arg;
2626
use function func_num_args;
2727
use function implode;
28-
use function is_string;
2928
use function preg_match;
3029
use function preg_match_all;
3130
use function sprintf;
3231
use function str_contains;
33-
use function strtok;
34-
use function strtolower;
3532
use function strtr;
3633

3734
use const CASE_LOWER;
@@ -114,44 +111,24 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
114111
{
115112
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
116113

117-
$dbType = strtolower($tableColumn['column_type']);
118-
$dbType = strtok($dbType, '(), ');
119-
assert(is_string($dbType));
120-
121-
$length = $tableColumn['length'] ?? strtok('(), ');
122-
123-
$fixed = false;
124-
114+
$dbType = $tableColumn['data_type'];
115+
$length = null;
125116
$scale = 0;
126117
$precision = null;
118+
$fixed = false;
119+
$values = [];
127120

128121
$type = $this->platform->getDoctrineTypeMapping($dbType);
129122

130-
$values = [];
131-
132123
switch ($dbType) {
133124
case 'char':
134-
case 'binary':
135-
$fixed = true;
125+
case 'varchar':
126+
$length = $tableColumn['character_maximum_length'];
136127
break;
137128

138-
case 'float':
139-
case 'double':
140-
case 'real':
141-
case 'numeric':
142-
case 'decimal':
143-
if (
144-
preg_match(
145-
'([A-Za-z]+\(([0-9]+),([0-9]+)\))',
146-
$tableColumn['column_type'],
147-
$match,
148-
) === 1
149-
) {
150-
$precision = (int) $match[1];
151-
$scale = (int) $match[2];
152-
$length = null;
153-
}
154-
129+
case 'binary':
130+
case 'varbinary':
131+
$length = $tableColumn['character_octet_length'];
155132
break;
156133

157134
case 'tinytext':
@@ -178,14 +155,24 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
178155
$length = AbstractMySQLPlatform::LENGTH_LIMIT_MEDIUMBLOB;
179156
break;
180157

181-
case 'tinyint':
182-
case 'smallint':
183-
case 'mediumint':
184-
case 'int':
185-
case 'integer':
186-
case 'bigint':
187-
case 'year':
188-
$length = null;
158+
case 'float':
159+
case 'double':
160+
case 'real':
161+
case 'numeric':
162+
case 'decimal':
163+
$precision = $tableColumn['numeric_precision'];
164+
165+
if (isset($tableColumn['numeric_scale'])) {
166+
$scale = $tableColumn['numeric_scale'];
167+
}
168+
169+
break;
170+
}
171+
172+
switch ($dbType) {
173+
case 'char':
174+
case 'binary':
175+
$fixed = true;
189176
break;
190177

191178
case 'enum':
@@ -200,7 +187,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
200187
}
201188

202189
$options = [
203-
'length' => $length !== null ? (int) $length : null,
190+
'length' => $length,
204191
'unsigned' => str_contains($tableColumn['column_type'], 'unsigned'),
205192
'fixed' => $fixed,
206193
'default' => $columnDefault,
@@ -348,7 +335,12 @@ protected function selectTableColumns(string $databaseName, ?OptionallyQualified
348335
SELECT
349336
c.TABLE_NAME AS %s,
350337
c.COLUMN_NAME,
351-
%s AS COLUMN_TYPE,
338+
%s AS DATA_TYPE,
339+
c.COLUMN_TYPE,
340+
c.CHARACTER_MAXIMUM_LENGTH,
341+
c.CHARACTER_OCTET_LENGTH,
342+
c.NUMERIC_PRECISION,
343+
c.NUMERIC_SCALE,
352344
c.IS_NULLABLE,
353345
c.COLUMN_DEFAULT,
354346
c.EXTRA,

0 commit comments

Comments
 (0)