@@ -192,9 +192,17 @@ def prepare_all
192
192
193
193
seed = true
194
194
end
195
+ end
196
+ end
195
197
196
- migrate
197
- dump_schema ( db_config ) if ActiveRecord . dump_schema_after_migration
198
+ each_current_environment ( env ) do |environment |
199
+ db_configs_with_versions ( environment ) . sort . each do |version , db_configs |
200
+ db_configs . each do |db_config |
201
+ with_temporary_pool ( db_config ) do
202
+ migrate ( version )
203
+ dump_schema ( db_config ) if ActiveRecord . dump_schema_after_migration
204
+ end
205
+ end
198
206
end
199
207
end
200
208
@@ -255,10 +263,10 @@ def migrate(version = nil)
255
263
Migration . verbose = verbose_was
256
264
end
257
265
258
- def db_configs_with_versions # :nodoc:
266
+ def db_configs_with_versions ( environment = env ) # :nodoc:
259
267
db_configs_with_versions = Hash . new { |h , k | h [ k ] = [ ] }
260
268
261
- with_temporary_pool_for_each do |pool |
269
+ with_temporary_pool_for_each ( env : environment ) do |pool |
262
270
db_config = pool . db_config
263
271
versions_to_run = pool . migration_context . pending_migration_versions
264
272
target_version = ActiveRecord ::Tasks ::DatabaseTasks . target_version
@@ -580,10 +588,7 @@ def class_for_adapter(adapter)
580
588
end
581
589
582
590
def each_current_configuration ( environment , name = nil )
583
- environments = [ environment ]
584
- environments << "test" if environment == "development" && !ENV [ "SKIP_TEST_DATABASE" ] && !ENV [ "DATABASE_URL" ]
585
-
586
- environments . each do |env |
591
+ each_current_environment ( environment ) do |env |
587
592
configs_for ( env_name : env ) . each do |db_config |
588
593
next if name && name != db_config . name
589
594
@@ -592,6 +597,12 @@ def each_current_configuration(environment, name = nil)
592
597
end
593
598
end
594
599
600
+ def each_current_environment ( environment , &block )
601
+ environments = [ environment ]
602
+ environments << "test" if environment == "development" && !ENV [ "SKIP_TEST_DATABASE" ] && !ENV [ "DATABASE_URL" ]
603
+ environments . each ( &block )
604
+ end
605
+
595
606
def each_local_configuration
596
607
configs_for . each do |db_config |
597
608
next unless db_config . database
0 commit comments