Update database_migrator.rb (#182)
Make database migrator run migrations in order
This commit is contained in:
parent
3cdd925162
commit
bb96593798
1 changed files with 24 additions and 1 deletions
|
|
@ -18,7 +18,7 @@ module PostDeployment
|
||||||
if @test_mode
|
if @test_mode
|
||||||
simulate_migrations
|
simulate_migrations
|
||||||
else
|
else
|
||||||
perform_migrations
|
perform_migrations_in_order
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -83,5 +83,28 @@ module PostDeployment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def perform_migrations_in_order
|
||||||
|
schema_context = ActiveRecord::Base.connection.migration_context
|
||||||
|
schema_migrations = schema_context.migrations
|
||||||
|
|
||||||
|
data_migrations_path = DataMigrate.config.data_migrations_path
|
||||||
|
data_context = DataMigrate::MigrationContext.new(data_migrations_path)
|
||||||
|
data_migrations = data_context.migrations
|
||||||
|
|
||||||
|
all_migrations = (schema_migrations + data_migrations).sort_by(&:version)
|
||||||
|
|
||||||
|
all_migrations.each do |migration|
|
||||||
|
if migration.filename.start_with?(data_migrations_path)
|
||||||
|
say "Running data migration: #{migration.name}"
|
||||||
|
# Run the data migration (you might need to call `data_context.run(migration)` or similar)
|
||||||
|
data_context.run(migration)
|
||||||
|
else
|
||||||
|
say "Running schema migration: #{migration.name}"
|
||||||
|
# Run the schema migration (Rails will handle this for you)
|
||||||
|
schema_context.run(migration)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue