Skip to content
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

Deprecate "unique" and "check" column properties #5656

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.',
greg0ire marked this conversation as resolved.
Show resolved Hide resolved
);

$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 @@ -1637,11 +1637,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