Skip to content

Deprecate dropping columns referenced by constraints #6559

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

Merged

Conversation

morozov
Copy link
Member

@morozov morozov commented Oct 20, 2024

Q A
Type deprecation

Summary

Currently, it is impossible to reference a non-existing column in a constraint being added but it's possible to drop the column afterwards, which will leave the table in an invalid state.

The order of operations in the following test will have to be changed once this deprecation is promoted to exception:

$table->dropColumn($assetName);
$table->dropIndex($assetName);
$table->removeForeignKey($assetName);

The following is out of scope of this PR:

  1. Renaming the column being renamed in referencing indexes and constraints (Rename column in indexes and constraints #6578).
  2. Dropping the column being dropped from referencing indexes and dropping the eventually empty indexes.

greg0ire
greg0ire previously approved these changes Oct 20, 2024
@derrabus
Copy link
Member

To what extend do we want schema objects to perform self-validation? Looking at the test code you've referenced, I'd say having an invalid table object is acceptable temporarily because the object might not only represent a deployed or deployable table, but also one that is being changed.

@morozov
Copy link
Member Author

morozov commented Oct 21, 2024

To what extend do we want schema objects to perform self-validation?

Eventually, I want the object to have to be always valid (see "make invalid states unrepresentable"). Otherwise, these objects are unusable in an invalid state, and there's no guarantee that this state will become valid at a later point.

What I also have in mind (as a DX improvement) is to separate the APIs for building and using tables (as well as other schema objects) by introducing builders and making objects immutable. This way, an object will be always guaranteed to be in a valid state, while the builder can be in an arbitrary state and allow arbitrary order of operations (win-win). The validation will happen once at the object construction time.

For example:

$table = getExistingTable();
$table->edit() // creates a builder
  ->makeSomeChange() // if this state is invalid, this is fine
  ->makeSomeOtherChange()
  ->build(); // a new table is created and validated

SenseException
SenseException previously approved these changes Oct 21, 2024
derrabus
derrabus previously approved these changes Oct 21, 2024
@morozov morozov dismissed stale reviews from derrabus, SenseException, and greg0ire via b72f7d6 October 21, 2024 20:37
@morozov morozov force-pushed the deprecate-drop-column-with-constraints branch from 0a2d097 to b72f7d6 Compare October 21, 2024 20:37
@morozov morozov requested a review from greg0ire October 21, 2024 20:45
@greg0ire greg0ire added this to the 4.3.0 milestone Oct 22, 2024
@greg0ire greg0ire merged commit 1103c4f into doctrine:4.3.x Oct 22, 2024
91 checks passed
@greg0ire
Copy link
Member

Thanks @morozov !

@morozov morozov deleted the deprecate-drop-column-with-constraints branch October 22, 2024 18:30
@morozov morozov mentioned this pull request Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants