emulate schema_migrations after rake db:schema:load
Closed this issue · 4 comments
When you run rake db:schema:load
an entry for each db migration is added to the schema_migrations table.
I think it would be useful to have the same behavior wrt the data_migrations table. After all, there should be no need to migrate data right after a schema:load.
Without this behavior the data migrations will need a bunch of conditionals.
Example:
My db has students and enrollments tables.
Initially #call_sign was a column on students, but it was later moved to enrollments and dropped from students. At that point I added a data migration to move the data from students to enrollments.
But if I deploy to a new server that data_migration will fail with no column call_sign on table students
Is it possible for rails-data-migrations to modify the behavior of db:schema:load
? Or to listen for it and respond to it?
Maybe a better idea is to add a new task that adds each pending data migration to the data_migrations table, without actually attempting to execute them.
something like this (which I added as a custom rake task in my app):
task :mark_data_migrations_complete => :environment do
migrations_path = RailsDataMigrations::Migrator.migrations_path
source_versions = RailsDataMigrations::Migrator.migrations(migrations_path).collect(&:version)
applied_versions = RailsDataMigrations::Migrator.get_all_versions
(source_versions - applied_versions).sort.each do |version|
RailsDataMigrations::LogEntry.create!(version: version.to_s)
end
end
@jdowd would you mind wrapping this into a PR? I think reset
is a good name for this task
yup, will do. Apologies in advance cuz it might take me a bit. I assume you'll want specs to match, right?