Compare commits

...

1 commit

Author SHA1 Message Date
1d4915890f Update database_migrator.rb
Make database migrator run migrations in order
2025-02-18 01:11:41 -08:00

View file

@ -18,7 +18,7 @@ module PostDeployment
if @test_mode
simulate_migrations
else
perform_migrations
perform_migrations_in_order
end
end
@ -83,5 +83,28 @@ module PostDeployment
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