I am using the Heroku Postgres addon for my DB (basic version). Ruby Sequel is my ORM for schema management.
Recently, some migrations have not updated the DB schema.
I run migration 19, 019_add_last_unique_story_to_user.rb:
Sequel.migration do
up do
alter_table(:state_tables) do
add_column :last_unique_story, Integer, default: 0
add_column :last_unique_story_read?, TrueClass, default: true
end
end
down do
alter_table(:state_tables) do
drop_column :last_unique_story
drop_column :last_unique_story_read?
end
end
end
This updates the DB[:schema_info] from version 18 to 19, but no columns are added to the :state_table table. This problem exists for both production and local databases. I have tried migrating multiple times and checked that the db url was correct.
My quick fix:
I copy and pasted the above code into a 20th migration, 020_test.rb, and ran my rake migration task rake db:migrate:up
. This successfully updated the database.
Does anyone know what could be going on here? Why do some migrations run successfully, update the migration version, yet not update any columns? Could this be a naming issue, a caching issue, or a Heroku issue? Thanks for you help!
It depends how your rake task is written. Sequel does not ship rake tasks, so you'll have to check where you got the rake task from.
In general, the only reason that the migration wouldn't add the column is if the migration wasn't run. For example, if the schema version in the database was already 19, then it wouldn't run migration 19 when you migrate up. This would explain why it did run the migration when you copied it to migration 20 and then migrated up. If you run the migrator with a database logger, Sequel will log migration activity (in addition to SQL).