The timestamp that’s passed to version
in db/schema.rb
is very important to get right, especially in merges.
by John Norris
It says “this is what the database looked like after all the migrations up to the file with the same timestamp as this”
ActiveRecord::Schema.define(version: 2023_07_02_163352) do
When I did some squashing of commits, I put an index into schema, but didn’t change the version number to match the migration file that did that.
Heroku CI runs rails db:schema:load
and then any migrations that haven’t been run, but it only knows what ‘hasn’t been run’ by that timestamp, so it tried to index a column that had already been indexed.
Changing it to the above, which matched the timestamp on the index migration file (20230702163352_add_index_to_estimate_item_total.rb
), fixed the problems.
Just worth remembering that most of our environments start with db:schema:load
, not migrate (and you should too when checking out a new project!).