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

Preserve foreign key constraints on columns duplicated for backfilling #230

Merged
merged 5 commits into from
Jan 15, 2024

Conversation

andrew-farries
Copy link
Collaborator

When duplicating a column for backfilling to add NOT NULL constraint, ensure that any foreign keys on the duplicated column are preserved.

This fixes the issue where adding NOT NULL to an FK column would drop the FK from the column.

This is part of a larger class of issues where duplicated columns are not faithfully preserving all properties of the original, tracked in #227.

Base automatically changed from change-complete-method-signature to main January 15, 2024 15:47
andrew-farries added a commit that referenced this pull request Jan 15, 2024
Change the signature of the `Complete` method on the `Operation`
interface to take a `*schema.Schema` argument like the `Start` and
`Validate` methods already do.

This allows for implementations of `Complete` to be aware of the entire
database schema, supporting things like renaming of any temporary
constraints created on columns affected the operation being completed.

See #230, which depends on this PR.
This function renames a duplicated column to its original name, along
with with any temporary constraints that were created on the column.
This ensures that any FK constraints on the duplicated column get
renamed back to their original names.
Add a test that checks that setting a column with an FK constraint to
`NOT NULL` does not remove the FK constraint.
@andrew-farries andrew-farries merged commit b81c42c into main Jan 15, 2024
24 checks passed
@andrew-farries andrew-farries deleted the duplication-of-fk-columns branch January 15, 2024 15:56
andrew-farries added a commit that referenced this pull request Jan 15, 2024
Preserve any foreign key constraints defined on columns when changing a
column's type.

Uses the `Duplicator` type added in #230 in the 'change type' operation
to ensure that FK constraints are preserved when the column is
duplicated for backfilling.

#230 did the same thing for
preserving FK constraints when a column has a `NOT NULL` constraint
added.

Part of #227
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.

None yet

2 participants