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

Add a drop_multicolumn_constraint operation #487

Merged
merged 7 commits into from
Nov 26, 2024

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Nov 26, 2024

Add a new drop_multicolumn_constraint operation type. The new operation is used to drop multi-column (and single-column) CHECK, UNIQUE, and FOREIGN KEY constraints:

The following migration drops a multi-column constraint called check_zip_name, and defines up and down SQL data migrations for each column covered by the constraint:

{
  "name": "48_drop_tickets_check",
  "operations": [
    {
      "drop_multicolumn_constraint": {
        "table": "tickets",
        "name": "check_zip_name",
        "up": {
          "sellers_name": "sellers_name",
          "sellers_zip": "sellers_zip"
        },
        "down": {
          "sellers_name": "sellers_name",
          "sellers_zip": "sellers_zip"
        }
      }
    }
  ]
}
  • On operation Start each column covered by the constraint is duplicated, ignoring the constraint to be dropped. Triggers for data migrations are created for each column covered by the constraint using the SQL for each column from the migration file.
  • On Complete, the duplicated column is renamed to the original name and triggers are removed.
  • Validate ensures that all columns covered by the constraint have data migrations defined, and only columns covered by the constraint have data migrations defined.

The new operation is in addition to the existing drop_constraint operation which only drops single column constraints. This old operation type is preserved for backwards compatibility but will be removed as a breaking change before a v1 release.

#489 tracks the removal of the drop_constraint operation.

@andrew-farries andrew-farries force-pushed the drop-multi-column-constraints branch 2 times, most recently from c47d1e8 to d715a5e Compare November 26, 2024 09:33
`OpCreateConstraint` will not be the only operation that requires
multiple up/down expressions. This commit extracts the multi-column
up/down expressions into their own types, `MultiColumnUpSQL` and
`MultiColumnDownSQL`, respectively.
Drop a multi-column constraint.
@andrew-farries andrew-farries force-pushed the drop-multi-column-constraints branch from d715a5e to ff33276 Compare November 26, 2024 09:39
@andrew-farries andrew-farries marked this pull request as ready for review November 26, 2024 09:46
@andrew-farries andrew-farries merged commit 9c9518b into main Nov 26, 2024
27 checks passed
@andrew-farries andrew-farries deleted the drop-multi-column-constraints branch November 26, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants