1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

bin/rake db:migrate:status works with legacy migration numbers.

The migration numbers were normalized different ways. This left
the task output in an inconsistent state.

Closes #15538.
This commit is contained in:
Yves Senn 2014-06-06 12:16:48 +02:00
parent 92f9ada352
commit e3cd80b4cf
5 changed files with 22 additions and 4 deletions

View file

@ -1,3 +1,9 @@
* `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
Fixes #15538.
*Yves Senn*
* Baseclass becomes! subclass.
Before this change, a record which changed its STI type, could not be

View file

@ -711,7 +711,7 @@ module ActiveRecord
if ActiveRecord::Base.timestamped_migrations
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max
else
"%.3d" % number
SchemaMigration.normalize_migration_number(number)
end
end

View file

@ -86,14 +86,15 @@ db_namespace = namespace :db do
abort 'Schema migrations table does not exist yet.'
end
db_list = ActiveRecord::Base.connection.select_values("SELECT version FROM #{ActiveRecord::Migrator.schema_migrations_table_name}")
db_list.map! { |version| "%.3d" % version }
db_list.map! { |version| ActiveRecord::SchemaMigration.normalize_migration_number(version) }
file_list = []
ActiveRecord::Migrator.migrations_paths.each do |path|
Dir.foreach(path) do |file|
# match "20091231235959_some_name.rb" and "001_some_name.rb" pattern
if match_data = /^(\d{3,})_(.+)\.rb$/.match(file)
status = db_list.delete(match_data[1]) ? 'up' : 'down'
file_list << [status, match_data[1], match_data[2].humanize]
version = ActiveRecord::SchemaMigration.normalize_migration_number(match_data[1])
status = db_list.delete(version) ? 'up' : 'down'
file_list << [status, version, match_data[2].humanize]
end
end
end

View file

@ -36,6 +36,10 @@ module ActiveRecord
connection.drop_table(table_name)
end
end
def normalize_migration_number(number)
"%.3d" % number.to_i
end
end
def version

View file

@ -66,5 +66,12 @@ if ActiveRecord::Base.connection.supports_migrations?
end
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
end
def test_normalize_version
assert_equal "118", ActiveRecord::SchemaMigration.normalize_migration_number("0000118")
assert_equal "002", ActiveRecord::SchemaMigration.normalize_migration_number("2")
assert_equal "017", ActiveRecord::SchemaMigration.normalize_migration_number("0017")
assert_equal "20131219224947", ActiveRecord::SchemaMigration.normalize_migration_number("20131219224947")
end
end
end