Skip to content

Commit 4c15083

Browse files
authored
Merge pull request #6853 from morozov/remove-invalid-sqlite-auto-increment
Remove support for invalid auto-increment column definitions on SQLite
2 parents 45f3b5a + 318651a commit 4c15083

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

UPGRADE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ awareness about deprecated code.
88

99
# Upgrade to 5.0
1010

11+
## BC BREAK: removed support for invalid auto-increment column definitions on SQLite
12+
13+
The following auto-increment column definitions are no longer supported on SQLite:
14+
15+
1. An auto-increment column that is not a primary key.
16+
2. An auto-increment column that is part of a composite primary key.
17+
1118
## BC BREAK: removed `TableDiff` methods
1219

1320
The `TableDiff::getModifiedForeignKeys()` and `TableDiff::getModifiedIndexes()` methods have been removed.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Platforms\Exception;
6+
7+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
8+
use InvalidArgumentException;
9+
10+
use function sprintf;
11+
12+
final class UnsupportedTableDefinition extends InvalidArgumentException implements PlatformException
13+
{
14+
public static function autoIncrementColumnNotPartOfPrimaryKey(UnqualifiedName $columnName): self
15+
{
16+
return new self(sprintf(
17+
'Auto-increment column %s must be a primary key column.',
18+
$columnName->toString(),
19+
));
20+
}
21+
22+
public static function autoIncrementColumnPartOfCompositePrimaryKey(UnqualifiedName $columnName): self
23+
{
24+
return new self(sprintf(
25+
'Auto-increment column %s cannot be part of a composite primary key.',
26+
$columnName->toString(),
27+
));
28+
}
29+
}

src/Platforms/SQLitePlatform.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Connection;
88
use Doctrine\DBAL\Platforms\Exception\NotSupported;
9+
use Doctrine\DBAL\Platforms\Exception\UnsupportedTableDefinition;
910
use Doctrine\DBAL\Schema\Column;
1011
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
1112
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
@@ -22,7 +23,6 @@
2223
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
2324
use Doctrine\DBAL\TransactionIsolationLevel;
2425
use Doctrine\DBAL\Types;
25-
use Doctrine\Deprecations\Deprecation;
2626
use InvalidArgumentException;
2727

2828
use function array_combine;
@@ -345,17 +345,11 @@ private function hasAutoIncrementColumn(array $columns, array $parameters): bool
345345
->toNormalizedValue($folding);
346346

347347
if (! isset($primaryKeyColumnNames[$columnName])) {
348-
Deprecation::trigger(
349-
'doctrine/dbal',
350-
'https://github.com/doctrine/dbal/pull/6849',
351-
'Declaring a column that is not part of the primary key as auto-increment is deprecated.',
352-
);
353-
} elseif (count($primaryKeyColumnNames) > 1) {
354-
Deprecation::trigger(
355-
'doctrine/dbal',
356-
'https://github.com/doctrine/dbal/pull/6849',
357-
'Declaring a column that is part of a composite primary key as auto-increment is deprecated.',
358-
);
348+
throw UnsupportedTableDefinition::autoIncrementColumnNotPartOfPrimaryKey($column['name']);
349+
}
350+
351+
if (count($primaryKeyColumnNames) > 1) {
352+
throw UnsupportedTableDefinition::autoIncrementColumnPartOfCompositePrimaryKey($column['name']);
359353
}
360354

361355
return true;

tests/Platforms/SQLitePlatformTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Exception;
88
use Doctrine\DBAL\Platforms\AbstractPlatform;
9+
use Doctrine\DBAL\Platforms\Exception\UnsupportedTableDefinition;
910
use Doctrine\DBAL\Platforms\SQLite;
1011
use Doctrine\DBAL\Platforms\SQLitePlatform;
1112
use Doctrine\DBAL\Schema\Column;
@@ -18,15 +19,12 @@
1819
use Doctrine\DBAL\TransactionIsolationLevel;
1920
use Doctrine\DBAL\Types\Type;
2021
use Doctrine\DBAL\Types\Types;
21-
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
2222

2323
use function implode;
2424

2525
/** @extends AbstractPlatformTestCase<SQLitePlatform> */
2626
class SQLitePlatformTest extends AbstractPlatformTestCase
2727
{
28-
use VerifyDeprecations;
29-
3028
public function createPlatform(): AbstractPlatform
3129
{
3230
return new SQLitePlatform();
@@ -646,7 +644,7 @@ public function testCreateTableWithNonPrimaryKeyAutoIncrementColumn(): void
646644
$table = new Table('test_autoincrement');
647645
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
648646

649-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/6849');
647+
$this->expectException(UnsupportedTableDefinition::class);
650648
$this->platform->getCreateTableSQL($table);
651649
}
652650

@@ -657,7 +655,7 @@ public function testCreateTableWithCompositePrimaryKeyAutoIncrementColumn(): voi
657655
$table->addColumn('id2', Types::INTEGER);
658656
$table->setPrimaryKey(['id1', 'id2']);
659657

660-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/6849');
658+
$this->expectException(UnsupportedTableDefinition::class);
661659
$this->platform->getCreateTableSQL($table);
662660
}
663661
}

0 commit comments

Comments
 (0)