aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/railties
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2015-10-02 01:21:37 +0900
committeryui-knk <spiketeika@gmail.com>2015-11-02 23:06:57 +0900
commita7beeb7faac405de0f78c39dbfb7240a584d0d10 (patch)
treec7b58555604d401eeabe1ea3cbf05e44c6dc31a0 /activerecord/lib/active_record/railties
parentab3510367bd4622f836374e5a37e54381ea72fc6 (diff)
downloadrails-a7beeb7faac405de0f78c39dbfb7240a584d0d10.tar.gz
rails-a7beeb7faac405de0f78c39dbfb7240a584d0d10.tar.bz2
rails-a7beeb7faac405de0f78c39dbfb7240a584d0d10.zip
Make `db:migrate:status` to render `1_some.rb` format migrate files.
`1_valid_people_have_last_names.rb` and `20150823202140_create_users.rb` are valid migration file name. But `1_valid_people_have_last_names.rb` is rendered as `********** NO FILE **********` when `rake db:migrate:status`. Fix to this bug, this commit includes * define some API private methdos and a Constant `match_to_migration_filename?`, `parse_migration_filename`, and `MigrationFilenameRegexp` * use these methods in `db:migrate:status` task Example: These files are in `db/migrate` * 1_valid_people_have_last_names.rb * 20150819202140_irreversible_migration.rb * 20150823202140_add_admin_flag_to_users.rb * 20150823202141_migration_tests.rb * 2_we_need_reminders.rb * 3_innocent_jointable.rb we can migrate all of them. Before ```shell $ bundle exec rake db:migrate:status ... Status Migration ID Migration Name -------------------------------------------------- up 001 ********** NO FILE ********** up 002 ********** NO FILE ********** up 003 ********** NO FILE ********** up 20150819202140 Irreversible migration up 20150823202140 Add admin flag to users up 20150823202141 Migration tests ``` After ```shell $ bundle exec rake db:migrate:status ... Status Migration ID Migration Name -------------------------------------------------- up 001 Valid people have last names up 002 We need reminders up 003 Innocent jointable up 20150819202140 Irreversible migration up 20150823202140 Add admin flag to users up 20150823202141 Migration tests ```
Diffstat (limited to 'activerecord/lib/active_record/railties')
-rw-r--r--activerecord/lib/active_record/railties/databases.rake12
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index b6f3695856..5b1ea16f0b 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -100,12 +100,14 @@ db_namespace = namespace :db do
file_list =
ActiveRecord::Tasks::DatabaseTasks.migrations_paths.flat_map do |path|
- # match "20091231235959_some_name.rb" and "001_some_name.rb" pattern
- Dir.foreach(path).grep(/^(\d{3,})_(.+)\.rb$/) do
- version = ActiveRecord::SchemaMigration.normalize_migration_number($1)
+ Dir.foreach(path).map do |file|
+ next unless ActiveRecord::Migrator.match_to_migration_filename?(file)
+
+ version, name, scope = ActiveRecord::Migrator.parse_migration_filename(file)
+ version = ActiveRecord::SchemaMigration.normalize_migration_number(version)
status = db_list.delete(version) ? 'up' : 'down'
- [status, version, $2.humanize]
- end
+ [status, version, (name + scope).humanize]
+ end.compact
end
db_list.map! do |version|