mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42803 from gregschmit/gns/fix-migrate-status-order
db:migrate:status: Sort migration ID as integer for consistency.
This commit is contained in:
commit
fad8d8a0f3
6 changed files with 59 additions and 1 deletions
|
@ -1177,7 +1177,7 @@ module ActiveRecord
|
|||
["up", version, "********** NO FILE **********"]
|
||||
end
|
||||
|
||||
(db_list + file_list).sort_by { |_, version, _| version }
|
||||
(db_list + file_list).sort_by { |_, version, _| version.to_i }
|
||||
end
|
||||
|
||||
def current_environment # :nodoc:
|
||||
|
|
|
@ -167,6 +167,44 @@ class MigratorTest < ActiveRecord::TestCase
|
|||
], ActiveRecord::MigrationContext.new(path, schema_migration).migrations_status
|
||||
end
|
||||
|
||||
def test_migrations_status_order_new_and_old_version
|
||||
path = MIGRATIONS_ROOT + "/old_and_new_versions"
|
||||
schema_migration = ActiveRecord::Base.connection.schema_migration
|
||||
|
||||
@schema_migration.create(version: 230)
|
||||
@schema_migration.create(version: 231)
|
||||
@schema_migration.create(version: 20210716122844)
|
||||
@schema_migration.create(version: 20210716123013)
|
||||
|
||||
assert_equal [
|
||||
["up", "230", "Add people hobby"],
|
||||
["up", "231", "Add people last name"],
|
||||
["up", "20210716122844", "Add people description"],
|
||||
["up", "20210716123013", "Add people number of legs"],
|
||||
], ActiveRecord::MigrationContext.new(path, schema_migration).migrations_status
|
||||
end
|
||||
|
||||
def test_migrations_status_order_new_and_old_version_applied_out_of_order
|
||||
path = MIGRATIONS_ROOT + "/old_and_new_versions"
|
||||
schema_migration = ActiveRecord::Base.connection.schema_migration
|
||||
|
||||
@schema_migration.create(version: 230)
|
||||
@schema_migration.create(version: 231)
|
||||
|
||||
# "Apply" a newer migration and not an older to simulate out-of-order
|
||||
# migration application which should not affect ordering in status and is
|
||||
# possible if a branch is merged which contains a migration which has an
|
||||
# earlier version but is judged to be compatible with existing migrations.
|
||||
@schema_migration.create(version: 20210716123013)
|
||||
|
||||
assert_equal [
|
||||
["up", "230", "Add people hobby"],
|
||||
["up", "231", "Add people last name"],
|
||||
["down", "20210716122844", "Add people description"],
|
||||
["up", "20210716123013", "Add people number of legs"],
|
||||
], ActiveRecord::MigrationContext.new(path, schema_migration).migrations_status
|
||||
end
|
||||
|
||||
def test_migrations_status_in_subdirectories
|
||||
path = MIGRATIONS_ROOT + "/valid_with_subdirectories"
|
||||
schema_migration = ActiveRecord::Base.connection.schema_migration
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPeopleDescription < ActiveRecord::Migration::Current
|
||||
add_column :people, :description, :string
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPeopleNumberOfLegs < ActiveRecord::Migration::Current
|
||||
add_column :people, :number_of_legs, :integer
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPeopleHobby < ActiveRecord::Migration::Current
|
||||
add_column :people, :hobby, :string
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPeopleLastName < ActiveRecord::Migration::Current
|
||||
add_column :people, :last_name, :string
|
||||
end
|
Loading…
Reference in a new issue