Skip to content

Commit

Permalink
Merge pull request #5656 from morozov/deprecate-unique-check
Browse files Browse the repository at this point in the history
Deprecate "unique" and "check" column properties
  • Loading branch information
morozov authored Sep 18, 2022
2 parents 7727e46 + e33dd6a commit a4a784a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions docs/en/reference/schema-representation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^

Expand Down Expand Up @@ -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``.
25 changes: 22 additions & 3 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 22 additions & 4 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 22 additions & 4 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a4a784a

Please sign in to comment.