|
14 | 14 | use Doctrine\DBAL\Schema\ComparatorConfig; |
15 | 15 | use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
16 | 16 | use Doctrine\DBAL\Schema\Index; |
| 17 | +use Doctrine\DBAL\Schema\Name\UnqualifiedName; |
17 | 18 | use Doctrine\DBAL\Schema\Table; |
18 | 19 | use Doctrine\DBAL\Schema\TableDiff; |
19 | 20 | use Doctrine\DBAL\Schema\UniqueConstraint; |
@@ -422,47 +423,58 @@ public function testQuotedNameInIndexSQL(): void |
422 | 423 |
|
423 | 424 | public function testQuotedColumnInForeignKeyPropagation(): void |
424 | 425 | { |
425 | | - $table = new Table('`quoted`', [ |
426 | | - Column::editor() |
427 | | - ->setUnquotedName('create') |
428 | | - ->setTypeName(Types::STRING) |
429 | | - ->setLength(255) |
430 | | - ->create(), |
431 | | - Column::editor() |
432 | | - ->setUnquotedName('foo') |
433 | | - ->setTypeName(Types::STRING) |
434 | | - ->setLength(255) |
435 | | - ->create(), |
436 | | - Column::editor() |
437 | | - ->setQuotedName('bar') |
438 | | - ->setTypeName(Types::STRING) |
439 | | - ->setLength(255) |
440 | | - ->create(), |
441 | | - ]); |
442 | | - |
443 | | - $table->addForeignKeyConstraint( |
444 | | - 'foreign', |
445 | | - ['create', 'foo', '`bar`'], |
446 | | - ['create', 'bar', '`foo-bar`'], |
447 | | - [], |
448 | | - 'FK_WITH_RESERVED_KEYWORD', |
449 | | - ); |
| 426 | + $referencingColumnNames = [ |
| 427 | + UnqualifiedName::unquoted('create'), |
| 428 | + UnqualifiedName::unquoted('foo'), |
| 429 | + UnqualifiedName::quoted('bar'), |
| 430 | + ]; |
450 | 431 |
|
451 | | - $table->addForeignKeyConstraint( |
452 | | - 'foo', |
453 | | - ['create', 'foo', '`bar`'], |
454 | | - ['create', 'bar', '`foo-bar`'], |
455 | | - [], |
456 | | - 'FK_WITH_NON_RESERVED_KEYWORD', |
457 | | - ); |
| 432 | + $referencedColumnNames = [ |
| 433 | + UnqualifiedName::unquoted('create'), |
| 434 | + UnqualifiedName::unquoted('bar'), |
| 435 | + UnqualifiedName::quoted('foo-bar'), |
| 436 | + ]; |
458 | 437 |
|
459 | | - $table->addForeignKeyConstraint( |
460 | | - '`foo-bar`', |
461 | | - ['create', 'foo', '`bar`'], |
462 | | - ['create', 'bar', '`foo-bar`'], |
463 | | - [], |
464 | | - 'FK_WITH_INTENDED_QUOTATION', |
465 | | - ); |
| 438 | + $table = Table::editor() |
| 439 | + ->setQuotedName('quoted') |
| 440 | + ->setColumns( |
| 441 | + Column::editor() |
| 442 | + ->setUnquotedName('create') |
| 443 | + ->setTypeName(Types::STRING) |
| 444 | + ->setLength(255) |
| 445 | + ->create(), |
| 446 | + Column::editor() |
| 447 | + ->setUnquotedName('foo') |
| 448 | + ->setTypeName(Types::STRING) |
| 449 | + ->setLength(255) |
| 450 | + ->create(), |
| 451 | + Column::editor() |
| 452 | + ->setQuotedName('bar') |
| 453 | + ->setTypeName(Types::STRING) |
| 454 | + ->setLength(255) |
| 455 | + ->create(), |
| 456 | + ) |
| 457 | + ->setForeignKeyConstraints( |
| 458 | + ForeignKeyConstraint::editor() |
| 459 | + ->setUnquotedName('FK_WITH_RESERVED_KEYWORD') |
| 460 | + ->setReferencingColumnNames(...$referencingColumnNames) |
| 461 | + ->setUnquotedReferencedTableName('foreign') |
| 462 | + ->setReferencedColumnNames(...$referencedColumnNames) |
| 463 | + ->create(), |
| 464 | + ForeignKeyConstraint::editor() |
| 465 | + ->setUnquotedName('FK_WITH_NON_RESERVED_KEYWORD') |
| 466 | + ->setReferencingColumnNames(...$referencingColumnNames) |
| 467 | + ->setUnquotedReferencedTableName('foo') |
| 468 | + ->setReferencedColumnNames(...$referencedColumnNames) |
| 469 | + ->create(), |
| 470 | + ForeignKeyConstraint::editor() |
| 471 | + ->setUnquotedName('FK_WITH_INTENDED_QUOTATION') |
| 472 | + ->setReferencingColumnNames(...$referencingColumnNames) |
| 473 | + ->setQuotedReferencedTableName('foo-bar') |
| 474 | + ->setReferencedColumnNames(...$referencedColumnNames) |
| 475 | + ->create(), |
| 476 | + ) |
| 477 | + ->create(); |
466 | 478 |
|
467 | 479 | $sql = $this->platform->getCreateTableSQL($table); |
468 | 480 | self::assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); |
@@ -974,32 +986,47 @@ abstract protected function getAlterStringToFixedStringSQL(): array; |
974 | 986 |
|
975 | 987 | public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL(): void |
976 | 988 | { |
977 | | - $foreignTable = new Table('foreign_table', [ |
978 | | - Column::editor() |
979 | | - ->setUnquotedName('id') |
980 | | - ->setTypeName(Types::INTEGER) |
981 | | - ->create(), |
982 | | - ]); |
983 | | - $foreignTable->setPrimaryKey(['id']); |
984 | | - |
985 | | - $primaryTable = new Table('mytable', [ |
986 | | - Column::editor() |
987 | | - ->setUnquotedName('foo') |
988 | | - ->setTypeName(Types::INTEGER) |
989 | | - ->create(), |
990 | | - Column::editor() |
991 | | - ->setUnquotedName('bar') |
992 | | - ->setTypeName(Types::INTEGER) |
993 | | - ->create(), |
994 | | - Column::editor() |
995 | | - ->setUnquotedName('baz') |
996 | | - ->setTypeName(Types::INTEGER) |
997 | | - ->create(), |
998 | | - ]); |
999 | | - $primaryTable->addIndex(['foo'], 'idx_foo'); |
1000 | | - $primaryTable->addIndex(['bar'], 'idx_bar'); |
1001 | | - $primaryTable->addForeignKeyConstraint($foreignTable->getName(), ['foo'], ['id'], [], 'fk_foo'); |
1002 | | - $primaryTable->addForeignKeyConstraint($foreignTable->getName(), ['bar'], ['id'], [], 'fk_bar'); |
| 989 | + $primaryTable = Table::editor() |
| 990 | + ->setUnquotedName('mytable') |
| 991 | + ->setColumns( |
| 992 | + Column::editor() |
| 993 | + ->setUnquotedName('foo') |
| 994 | + ->setTypeName(Types::INTEGER) |
| 995 | + ->create(), |
| 996 | + Column::editor() |
| 997 | + ->setUnquotedName('bar') |
| 998 | + ->setTypeName(Types::INTEGER) |
| 999 | + ->create(), |
| 1000 | + Column::editor() |
| 1001 | + ->setUnquotedName('baz') |
| 1002 | + ->setTypeName(Types::INTEGER) |
| 1003 | + ->create(), |
| 1004 | + ) |
| 1005 | + ->setIndexes( |
| 1006 | + Index::editor() |
| 1007 | + ->setUnquotedName('idx_foo') |
| 1008 | + ->setUnquotedColumnNames('foo') |
| 1009 | + ->create(), |
| 1010 | + Index::editor() |
| 1011 | + ->setUnquotedName('idx_bar') |
| 1012 | + ->setUnquotedColumnNames('bar') |
| 1013 | + ->create(), |
| 1014 | + ) |
| 1015 | + ->setForeignKeyConstraints( |
| 1016 | + ForeignKeyConstraint::editor() |
| 1017 | + ->setUnquotedName('fk_foo') |
| 1018 | + ->setUnquotedReferencingColumnNames('foo') |
| 1019 | + ->setUnquotedReferencedTableName('foreign_table') |
| 1020 | + ->setUnquotedReferencedColumnNames('id') |
| 1021 | + ->create(), |
| 1022 | + ForeignKeyConstraint::editor() |
| 1023 | + ->setUnquotedName('fk_bar') |
| 1024 | + ->setUnquotedReferencingColumnNames('bar') |
| 1025 | + ->setUnquotedReferencedTableName('foreign_table') |
| 1026 | + ->setUnquotedReferencedColumnNames('id') |
| 1027 | + ->create(), |
| 1028 | + ) |
| 1029 | + ->create(); |
1003 | 1030 |
|
1004 | 1031 | $tableDiff = new TableDiff($primaryTable, renamedIndexes: [ |
1005 | 1032 | 'idx_foo' => new Index('idx_foo_renamed', ['foo']), |
|
0 commit comments