shlogg · Early preview
Augusts Bautra @augustsbautra

Adding Indexes In Production With Strong Migrations And PGHero

Adding an index in production is relatively safe with `strong_migrations` and `pghero`. Use `ActiveRecord::Migration.add_index` to add concurrently, then remove if it fails. Commit a corresponding migration for all envs.

Sometimes you may need to add an index or two in production outside of normal deployment. This is a relatively safe operation, especially if you are the only one tinkering and gem "strong_migrations" is being used. I also recommend only doing this after having gem "pghero" configured, so you can easily inspect things if something goes wrong.
As part of my de-NULL-ification struggle, I need to backfill a column, but to efficiently query for records missing a value, I need the index, so I've decided to add the index manually in production console and add a corresponding migration later to have o...