Fregata icon indicating copy to clipboard operation
Fregata copied to clipboard

[v2] Refactor the ForeignKey constructor

Open AymDev opened this issue 4 years ago • 0 comments

$tableName parameter

Why was it useful in v1

The $tableName parameter of the constructor is required because of https://github.com/doctrine/dbal/issues/4506 which prevents getting the local table from a ForeignKeyConstraint. This issue is now closed and the circular reference has been removed, deprecating the use of ForeignKeyConstraint::getLocalTableName() among other methods.

Actually the internal and user code have to use the SchemaManager to get the table.

How to replace it in v2

Replacing the string $tableName parameter with a Table $table one would only require the user to provide the object. The parameter count would be the same but it would enforce a better type for the ForeignKey class and remove most of the SchemaManager usage in ForeignKeyBeforeTask and ForeignKeyAfterTask.

$allowNull parameter

Why was it useful in v1

This parameter is required to reset a column of a foreign key constraint back to NOT NULL after a migration, during an after task. This is necessary because some of the columns of a foreign key constraint may accept NULL. This parameter helps keeping track of the columns that were NOT NULL before the migration.

How to replace it in v2

Storing the columns that should be set back to NOT NULL using a cache system. The $allowNull parameter could simply be removed.

AymDev avatar Sep 14 '21 20:09 AymDev