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

Fix migration that drops unique index #384

Merged
merged 2 commits into from Apr 17, 2023
Merged

Conversation

adamiak
Copy link
Member

@adamiak adamiak commented Apr 15, 2023

Resolves L2B-1051

Rolling back this migration would cause a uniqe index to be re-added but we can't do it since there is potentially already data in DB that has correct duplicates (adding unique index was a mistake in the first place). This PR changes the migration so that id never re-adds the unique index, just keeps the one without unique contraint.

@adamiak adamiak requested a review from torztomasz April 15, 2023 17:58
@linear
Copy link

linear bot commented Apr 15, 2023

L2B-1051 Fix migration 032_drop_uniqueness_from_preprocessed

There was a unique index that had to be dropped (due to Perpetuals on Gammax supporting use case where a single user has multiple positions).

Migration 32 drops the unique key, but it turns out that when this migration is rolled back (I'm not sure exactly when, Mateusz had this happen when starting backend with FRESH_START), it tries to re-add the unique index (see down()), which fails because there are obviously violations in the table.

Don't be tempted to use a simple solution of just not moving back to unique index. If you do that, then migrating again to 32 will fail, because it tries to drop a unique index that wouldn't exist.

I guess the only solution here is to delete * from the table when rolling back. Consult with piotr.szlachciak if this is a good idea.

@adamiak adamiak enabled auto-merge April 17, 2023 13:52
@adamiak adamiak added this pull request to the merge queue Apr 17, 2023
Merged via the queue into master with commit c040b4f Apr 17, 2023
4 checks passed
@adamiak adamiak deleted the fix-unique-key-db-migration branch April 17, 2023 13:59
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