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

Index reapplication - migration rollback #419

Open
leonelgalan opened this issue Jun 26, 2024 · 0 comments
Open

Index reapplication - migration rollback #419

leonelgalan opened this issue Jun 26, 2024 · 0 comments

Comments

@leonelgalan
Copy link

This is meant to be a cautionary tale for other users, maybe it can be a documentation change once we agree on how this should be presented. The index reapplication worked as expected, keeping only the appropriate indexes after the update. I then noticed a mistake and rolled back the migration before fixing it and migrating again, the "fix" allowed an index that was dropped previously to stay, but it was no longer on the DB because it was dropped earlier. The add_index call was many migrations back, even worse this was the unique index, needed for my periodic refresh_materialized_view with concurrently: true call.

I had to manually run:

ActiveRecord::Migration.add_index :view_name, :id, unique: true

Possible workarounds?

  • Have update_view whitelist which indexes can be dropped (less magic) but less prone for errors.
  • Have update_view scream (maybe it did, but I didn't notice) when dropping an index.
  • Have update_view save the dropped index, to be created when rolling back? This one I have no idea on how it would work
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

No branches or pull requests

1 participant