aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-06 12:16:48 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-06 12:16:48 +0200
commite3cd80b4cfda38c9f82342af80dd674236a5d738 (patch)
tree9ed2753179452c4480d7e1a113ace0a8a63c26d5
parent92f9ada352a1ae70253313161a340f96447f6845 (diff)
downloadrails-e3cd80b4cfda38c9f82342af80dd674236a5d738.tar.gz
rails-e3cd80b4cfda38c9f82342af80dd674236a5d738.tar.bz2
rails-e3cd80b4cfda38c9f82342af80dd674236a5d738.zip
`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.
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/migration.rb2
-rw-r--r--activerecord/lib/active_record/railties/databases.rake7
-rw-r--r--activerecord/lib/active_record/schema_migration.rb4
-rw-r--r--activerecord/test/cases/ar_schema_test.rb7
5 files changed, 22 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 7acb92620c..f09b27d01f 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -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
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index fca002873c..481e5c17e4 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -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
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index fa25ceaefa..6dca206f2a 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -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
diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb
index a9d164e366..5e484ded75 100644
--- a/activerecord/lib/active_record/schema_migration.rb
+++ b/activerecord/lib/active_record/schema_migration.rb
@@ -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
diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb
index 811695938e..861b8cbaa7 100644
--- a/activerecord/test/cases/ar_schema_test.rb
+++ b/activerecord/test/cases/ar_schema_test.rb
@@ -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