-
Notifications
You must be signed in to change notification settings - Fork 105
Support table and column rename operations preceding create_constraint
operations
#674
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ensure that the triggers created on operation start use the correct name of the table being modified. This ensures that trigger creation is aware of any table renaming that may have been done by operations earlier in the same migration.
When adding a check constraint, the physical table name should be used, not the one specified in the operation, so that table renames are taken into account.
Use the physical table name when rolling back a constraint creation instead of the logical table name. A previous rename table operation in the same migration may have renamed the table, but the physical name of the table remains unchanged until migration completion.
When duplicating columns for a new constraint, duplicate the columns using their final names after migration completion. This ensures that the `Complete` step is able to find the duplicated columns.
ad6af4b
to
caf15c9
Compare
kvch
approved these changes
Feb 11, 2025
andrew-farries
added a commit
that referenced
this pull request
Feb 11, 2025
…nt` `UNIQUE` operations (#676) Follow up to #674 which ensured that `create_constraint` `CHECK` operations could be preceded by rename table and rename column operations. This PR ensures that `create_constraint` `UNIQUE` operations can be preceded by rename table and rename column operations as in the following example: ```json { "name": "19_multiple_ops", "operations": [ { "rename_table": { "from": "items", "to": "products" } }, { "rename_column": { "table": "products", "from": "name", "to": "item_name" } }, { "create_constraint": { "table": "products", "type": "unique", "name": "unique_item_name", "columns": ["item_name"], "up": { "item_name": "item_name || '-from-up'" }, "down": { "item_name": "item_name || '-from-down'" } } } ] } ```
andrew-farries
added a commit
that referenced
this pull request
Feb 14, 2025
…nt` `FOREIGN KEY` operations (#682) Ensure that `create_constraint` `FOREIGN KEY` operations can be preceded by rename table and rename column operations as in the following example: ```json { "name": "22_multiple_ops", "operations": [ { "rename_table": { "from": "items", "to": "products" } }, { "rename_column": { "table": "products", "from": "owner", "to": "owner_id" } }, { "create_constraint": { "table": "products", "type": "foreign_key", "name": "fk_items_users", "columns": ["owner_id"], "references": { "table": "users", "columns": ["id"] }, "up": { "owner_id": "owner_id" }, "down": { "owner_id": "owner_id" } } } ] } ``` Follow up to #674 and #676. Part of #239.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for allowing the table and column on which a
create_constraint
operation acts to be renamed by preceding operations in the same migration. For example, ensure that a migration like this works as expected:Here, a three operation migration first renames the
items
table toproducts
, renames thename
field toitem_name
then adds aCHECK
constraint to theitem_name
field on theproducts
table.This PR covers the case of adding
CHECK
constraints only; further (smaller) PRs may be needed for the other constraint types supported bycreate_constraint
.Part of #239