Skip to content

Merge 4.3.x up into 5.0.x #6938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 1, 2025
Merged
2 changes: 1 addition & 1 deletion src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected function supportsColumnCollation(): bool
*/
public function getColumnTypeSQLSnippet(string $tableAlias, string $databaseName): string
{
return $tableAlias . '.COLUMN_TYPE';
return $tableAlias . '.DATA_TYPE';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/MariaDBPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias, string $databaseName
// The check for `CONSTRAINT_SCHEMA = $databaseName` is mandatory here to prevent performance issues
return <<<SQL
IF(
$tableAlias.COLUMN_TYPE = 'longtext'
$tableAlias.DATA_TYPE = 'longtext'
AND EXISTS(
SELECT * FROM information_schema.CHECK_CONSTRAINTS $subQueryAlias
WHERE $subQueryAlias.CONSTRAINT_SCHEMA = $databaseName
Expand All @@ -60,7 +60,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias, string $databaseName
)
),
'json',
$tableAlias.COLUMN_TYPE
$tableAlias.DATA_TYPE
)
SQL;
}
Expand Down
3 changes: 0 additions & 3 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,7 @@ protected function initializeDoctrineTypeMappings(): void
'bytea' => Types::BLOB,
'char' => Types::STRING,
'date' => Types::DATE_MUTABLE,
'datetime' => Types::DATETIME_MUTABLE,
'decimal' => Types::DECIMAL,
'double' => Types::FLOAT,
'double precision' => Types::FLOAT,
'float' => Types::FLOAT,
'float4' => Types::SMALLFLOAT,
Expand Down Expand Up @@ -740,7 +738,6 @@ protected function initializeDoctrineTypeMappings(): void
'tsvector' => Types::TEXT,
'uuid' => Types::GUID,
'varchar' => Types::STRING,
'year' => Types::DATE_MUTABLE,
'_varchar' => Types::STRING,
];
}
Expand Down
18 changes: 10 additions & 8 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,13 @@ public function listTables(): array
->setName(
OptionallyQualifiedName::quoted($unqualifiedName, $qualifier),
)
->setColumns($this->_getPortableTableColumnList($tableColumns))
->setColumns(
...array_values($this->_getPortableTableColumnList($tableColumns)),
)
->setIndexes(
$this->_getPortableTableIndexesList(
...array_values($this->_getPortableTableIndexesList(
$indexColumnsByTable[$schemaNameKey][$unqualifiedName] ?? [],
),
)),
);

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

if (isset($foreignKeyColumnsByTable[$schemaNameKey][$unqualifiedName])) {
$editor->setForeignKeyConstraints(
$this->_getPortableTableForeignKeysList(
...array_values($this->_getPortableTableForeignKeysList(
$foreignKeyColumnsByTable[$schemaNameKey][$unqualifiedName],
),
)),
);
}

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

return Table::editor()
->setName($tableName)
->setColumns($columns)
->setColumns(...array_values($columns))
->setPrimaryKeyConstraint($this->getTablePrimaryKeyConstraint($name))
->setIndexes($this->listTableIndexes($name))
->setForeignKeyConstraints($this->listTableForeignKeys($name))
->setIndexes(...array_values($this->listTableIndexes($name)))
->setForeignKeyConstraints(...array_values($this->listTableForeignKeys($name)))
->setOptions($this->getTableOptions($tableName))
->create();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Schema/Exception/InvalidTableDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public static function nameNotSet(): self
{
return new self('Table name is not set.');
}

public static function columnsNotSet(): self
{
return new self('Table columns are not set.');
}
}
76 changes: 34 additions & 42 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
use function func_get_arg;
use function func_num_args;
use function implode;
use function is_string;
use function preg_match;
use function preg_match_all;
use function sprintf;
use function str_contains;
use function strtok;
use function strtolower;
use function strtr;

use const CASE_LOWER;
Expand Down Expand Up @@ -114,44 +111,24 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);

$dbType = strtolower($tableColumn['column_type']);
$dbType = strtok($dbType, '(), ');
assert(is_string($dbType));

$length = $tableColumn['length'] ?? strtok('(), ');

$fixed = false;

$dbType = $tableColumn['data_type'];
$length = null;
$scale = 0;
$precision = null;
$fixed = false;
$values = [];

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

$values = [];

switch ($dbType) {
case 'char':
case 'binary':
$fixed = true;
case 'varchar':
$length = $tableColumn['character_maximum_length'];
break;

case 'float':
case 'double':
case 'real':
case 'numeric':
case 'decimal':
if (
preg_match(
'([A-Za-z]+\(([0-9]+),([0-9]+)\))',
$tableColumn['column_type'],
$match,
) === 1
) {
$precision = (int) $match[1];
$scale = (int) $match[2];
$length = null;
}

case 'binary':
case 'varbinary':
$length = $tableColumn['character_octet_length'];
break;

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

case 'tinyint':
case 'smallint':
case 'mediumint':
case 'int':
case 'integer':
case 'bigint':
case 'year':
$length = null;
case 'float':
case 'double':
case 'real':
case 'numeric':
case 'decimal':
$precision = $tableColumn['numeric_precision'];

if (isset($tableColumn['numeric_scale'])) {
$scale = $tableColumn['numeric_scale'];
}

break;
}

switch ($dbType) {
case 'char':
case 'binary':
$fixed = true;
break;

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

$options = [
'length' => $length !== null ? (int) $length : null,
'length' => $length,
'unsigned' => str_contains($tableColumn['column_type'], 'unsigned'),
'fixed' => $fixed,
'default' => $columnDefault,
Expand Down Expand Up @@ -348,7 +335,12 @@ protected function selectTableColumns(string $databaseName, ?OptionallyQualified
SELECT
c.TABLE_NAME AS %s,
c.COLUMN_NAME,
%s AS COLUMN_TYPE,
%s AS DATA_TYPE,
c.COLUMN_TYPE,
c.CHARACTER_MAXIMUM_LENGTH,
c.CHARACTER_OCTET_LENGTH,
c.NUMERIC_PRECISION,
c.NUMERIC_SCALE,
c.IS_NULLABLE,
c.COLUMN_DEFAULT,
c.EXTRA,
Expand Down
Loading