diff --git a/UPGRADE.md b/UPGRADE.md index 1e91fc70e42..33158ab7441 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,10 @@ awareness about deprecated code. # Upgrade to 3.5 +## Deprecated "unique" and "check" column properties. + +The "unique" and "check" column properties have been deprecated. Use unique constraints to define unique columns. + ## Deprecated relying on the default precision and scale of decimal columns. Relying on the default precision and scale of decimal columns provided by the DBAL is deprecated. diff --git a/docs/en/reference/schema-representation.rst b/docs/en/reference/schema-representation.rst index 9e5aaa4bca3..3c25dfbfa51 100644 --- a/docs/en/reference/schema-representation.rst +++ b/docs/en/reference/schema-representation.rst @@ -107,9 +107,6 @@ The following options are considered to be fully portable across all database pl - **customSchemaOptions** (array): Additional options for the column that are supported by all vendors: - - **unique** (boolean): Whether to automatically add a unique constraint for the column. - Defaults to ``false``. - Common options ^^^^^^^^^^^^^^ @@ -138,5 +135,3 @@ The following options are completely vendor specific and absolutely not portable on MySQL. - **collation** (string): The collation to use for the column. Supported by MySQL, PostgreSQL, Sqlite and SQL Server. - - **check** (string): The check constraint clause to add to the column. - Defaults to ``null``. diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 3265532fbe4..49966e7aa73 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -2887,10 +2887,29 @@ public function getColumnDeclarationSQL($name, array $column) $notnull = ! empty($column['notnull']) ? ' NOT NULL' : ''; - $unique = ! empty($column['unique']) ? - ' ' . $this->getUniqueFieldDeclarationSQL() : ''; + if (! empty($column['unique'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5656', + 'The usage of the "unique" column property is deprecated. Use unique constraints instead.', + ); + + $unique = ' ' . $this->getUniqueFieldDeclarationSQL(); + } else { + $unique = ''; + } - $check = ! empty($column['check']) ? ' ' . $column['check'] : ''; + if (! empty($column['check'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5656', + 'The usage of the "check" column property is deprecated.', + ); + + $check = ' ' . $column['check']; + } else { + $check = ''; + } $typeDecl = $column['type']->getSQLDeclaration($column, $this); $declaration = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation; diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index 35165c9464a..fdd88588376 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -1012,11 +1012,29 @@ public function getColumnDeclarationSQL($name, array $column) $notnull = $column['notnull'] ? ' NOT NULL' : ' NULL'; } - $unique = ! empty($column['unique']) ? - ' ' . $this->getUniqueFieldDeclarationSQL() : ''; + if (! empty($column['unique'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5656', + 'The usage of the "unique" column property is deprecated. Use unique constraints instead.', + ); + + $unique = ' ' . $this->getUniqueFieldDeclarationSQL(); + } else { + $unique = ''; + } - $check = ! empty($column['check']) ? - ' ' . $column['check'] : ''; + if (! empty($column['check'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5656', + 'The usage of the "check" column property is deprecated.', + ); + + $check = ' ' . $column['check']; + } else { + $check = ''; + } $typeDecl = $column['type']->getSQLDeclaration($column, $this); $columnDef = $typeDecl . $default . $notnull . $unique . $check; diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index 0e4d1ee34b1..bc1155b42b4 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -1645,11 +1645,29 @@ public function getColumnDeclarationSQL($name, array $column) $notnull = ! empty($column['notnull']) ? ' NOT NULL' : ''; - $unique = ! empty($column['unique']) ? - ' ' . $this->getUniqueFieldDeclarationSQL() : ''; + if (! empty($column['unique'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5656', + 'The usage of the "unique" column property is deprecated. Use unique constraints instead.', + ); + + $unique = ' ' . $this->getUniqueFieldDeclarationSQL(); + } else { + $unique = ''; + } - $check = ! empty($column['check']) ? - ' ' . $column['check'] : ''; + if (! empty($column['check'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5656', + 'The usage of the "check" column property is deprecated.', + ); + + $check = ' ' . $column['check']; + } else { + $check = ''; + } $typeDecl = $column['type']->getSQLDeclaration($column, $this); $columnDef = $typeDecl . $collation . $notnull . $unique . $check;