Update database_migrator.rb (#182)

Make database migrator run migrations in order
This commit is contained in:
Justin Edmund 2025-02-18 01:12:15 -08:00 committed by GitHub
parent 3cdd925162
commit bb96593798
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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