Skip to content

Commit c1ca3c2

Browse files
committed
Try being smart about what migrations to execute
If it's 6.1, let's just run all pending migrations We're losing multi-db setups in the process, most likely, though
1 parent c7127d9 commit c1ca3c2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/data_migrate/database_tasks.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,12 @@ def self.migrate_with_data
186186

187187
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
188188

189-
# 7.2 removes the param for db_configs_with_versions in https://github.com/rails/rails/commit/9572fcb4a0bd5396436689a6a42613886871cd81
190-
# 7.1 stable backported the change in https://github.com/rails/rails/commit/c53ec4b60980036b43528829d4b0b7457f759224
191-
schema_mapped_versions = if Gem::Dependency.new("railties", ">= 7.1.4").match?("railties", Gem.loaded_specs["railties"].version, true)
192-
ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions
193-
else
194-
db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
195-
196-
ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions(db_configs)
189+
unless ActiveRecord::Tasks::DatabaseTasks.respond_to?(:db_configs_with_versions)
190+
pending_migrations.each { |migration| run_migration(migration, :up) }
191+
return
197192
end
198193

194+
schema_mapped_versions = schema_db_configs_with_versions
199195
data_mapped_versions = DataMigrate::DatabaseTasks.db_configs_with_versions
200196

201197
mapped_versions = schema_mapped_versions.merge(data_mapped_versions) do |_key, schema_db_configs, data_db_configs|
@@ -279,6 +275,17 @@ def dump_schema_after_migration?
279275
end
280276
end
281277

278+
def self.schema_db_configs_with_versions
279+
method = ActiveRecord::Tasks::DatabaseTasks.method(:db_configs_with_versions)
280+
if method.arity == 1
281+
db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
282+
ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions(db_configs)
283+
else
284+
ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions
285+
end
286+
end
287+
private_class_method :schema_db_configs_with_versions
288+
282289
def schema_format
283290
if ActiveRecord.respond_to?(:schema_format)
284291
ActiveRecord.schema_format

0 commit comments

Comments
 (0)