File tree Expand file tree Collapse file tree 3 files changed +43
-5
lines changed
activerecord/lib/active_record
railties/test/application/rake Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -94,9 +94,11 @@ db_namespace = namespace :db do
94
94
original_db_config = ActiveRecord ::Base . connection_db_config
95
95
mapped_versions = ActiveRecord ::Tasks ::DatabaseTasks . db_configs_with_versions ( db_configs )
96
96
97
- mapped_versions . sort . each do |version , db_config |
98
- ActiveRecord ::Base . establish_connection ( db_config )
99
- ActiveRecord ::Tasks ::DatabaseTasks . migrate ( version )
97
+ mapped_versions . sort . each do |version , db_configs |
98
+ db_configs . each do |db_config |
99
+ ActiveRecord ::Base . establish_connection ( db_config )
100
+ ActiveRecord ::Tasks ::DatabaseTasks . migrate ( version )
101
+ end
100
102
end
101
103
end
102
104
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ def migrate(version = nil)
286
286
end
287
287
288
288
def db_configs_with_versions ( db_configs ) # :nodoc:
289
- db_configs_with_versions = { }
289
+ db_configs_with_versions = Hash . new { | h , k | h [ k ] = [ ] }
290
290
291
291
db_configs . each do |db_config |
292
292
ActiveRecord ::Base . establish_connection ( db_config )
@@ -295,7 +295,7 @@ def db_configs_with_versions(db_configs) # :nodoc:
295
295
296
296
versions_to_run . each do |version |
297
297
next if target_version && target_version != version
298
- db_configs_with_versions [ version ] = db_config
298
+ db_configs_with_versions [ version ] << db_config
299
299
end
300
300
end
301
301
Original file line number Diff line number Diff line change @@ -451,6 +451,42 @@ class ThreeMigration < ActiveRecord::Migration::Current
451
451
end
452
452
end
453
453
454
+ test "migrations in different directories can have the same timestamp" do
455
+ require "#{ app_path } /config/environment"
456
+ app_file "db/migrate/01_one_migration.rb" , <<-MIGRATION
457
+ class OneMigration < ActiveRecord::Migration::Current
458
+ def change
459
+ create_table :posts do |t|
460
+ t.string :title
461
+
462
+ t.timestamps
463
+ end
464
+ end
465
+ end
466
+ MIGRATION
467
+
468
+ app_file "db/animals_migrate/01_one_migration.rb" , <<-MIGRATION
469
+ class OneMigration < ActiveRecord::Migration::Current
470
+ def change
471
+ create_table :dogs do |t|
472
+ t.string :name
473
+
474
+ t.timestamps
475
+ end
476
+ end
477
+ end
478
+ MIGRATION
479
+
480
+ Dir . chdir ( app_path ) do
481
+ output = rails "db:migrate"
482
+ entries = output . scan ( /^== (\d +).+migrated/ ) . map ( &:first ) . map ( &:to_i )
483
+
484
+ assert_match ( /dogs/ , output )
485
+ assert_match ( /posts/ , output )
486
+ assert_equal [ 1 , 1 ] , entries
487
+ end
488
+ end
489
+
454
490
test "db:migrate and db:schema:dump and db:schema:load works on all databases" do
455
491
db_migrate_and_schema_dump_and_load
456
492
end
You can’t perform that action at this time.
0 commit comments