Skip to content

Index reapplication - migration rollback #419

@leonelgalan

Description

@leonelgalan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions