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

Identify duplicated foreign key constraints by prefix #245

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

andrew-farries
Copy link
Collaborator

When duplicating a column for backfilling, ensure that any FK constraints on the column are duplicated with a special prefix to identify them as duplicated constraints. Naming the duplicated FK constraints in this way allows the rename process to ensure that it only attempts to rename duplicated FK constraints.

When duplicating a column for backfilling, ensure that any FK
constraints on the column are duplicated with a special prefix to
identify them as duplicated constraints. Naming the duplicated FK
constraint makes it easy for such constraints to be renamed on migration
completion.
On migration completion, `RenameDuplicatedColumn` is called to rename
a duplicated column along with any FK constraints that were created on
the column. Ensure that the rename process only attempts to handle
duplicated FK constraints by looking to the special name prefix.
There is no need to create FK constraints with a temporary name prefix -
they only need to be validated on migration completion, not renamed.
Update test expectations now that FK constraints on duplicated columns
have a special prefix.
Copy link
Member

@exekias exekias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, how could a column end up with a fk constraint that doesn't come from duplication? I guess it's in the case you are actually adding it, which requires a duplicate?

@andrew-farries
Copy link
Collaborator Author

I guess it's in the case you are actually adding it, which requires a duplicate?

Yes, that's it. We need to distinguish the case where the FK on a temporary column is a duplicate because an FK was already on the column when we set the column NOT NULL for example, vs the case where the FK is on the temporary column because it's new on the column (ie put there by a 'set FK' operation).

@andrew-farries andrew-farries merged commit 7a38e1f into main Jan 19, 2024
24 checks passed
@andrew-farries andrew-farries deleted the use-prefix-on-duplicated-fks branch January 19, 2024 15:08
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