diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2019-06-11 08:17:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-11 08:17:50 -0400 |
commit | 96f142ae76b04f5ffe6e4c33550f5b04739f4f56 (patch) | |
tree | df49ece35b5ffb350a728c22fc194fc9a7137e4b /activerecord | |
parent | 4dcb46182a4aaa57f44f3eb722c1db54fa0ff843 (diff) | |
parent | cb8b57d07e132a6528bce47c93ee392c6cc64c10 (diff) | |
download | rails-96f142ae76b04f5ffe6e4c33550f5b04739f4f56.tar.gz rails-96f142ae76b04f5ffe6e4c33550f5b04739f4f56.tar.bz2 rails-96f142ae76b04f5ffe6e4c33550f5b04739f4f56.zip |
Merge pull request #36440 from malept/multi-db-abort_if_pending_migrations-task
Add support for multiple databases to `rails db:abort_if_pending_migrations`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 26 |
2 files changed, 29 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 09fdc66788..a4def5b270 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add support for multiple databases to `rails db:abort_if_pending_migrations`. + + *Mark Lee* + * Fix sqlite3 collation parsing when using decimal columns. *Martin R. Schuster* diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index befcbc8984..d17acc408c 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -250,7 +250,11 @@ db_namespace = namespace :db do # desc "Raises an error if there are pending migrations" task abort_if_pending_migrations: :load_config do - pending_migrations = ActiveRecord::Base.connection.migration_context.open.pending_migrations + pending_migrations = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).flat_map do |db_config| + ActiveRecord::Base.establish_connection(db_config.config) + + ActiveRecord::Base.connection.migration_context.open.pending_migrations + end if pending_migrations.any? puts "You have #{pending_migrations.size} pending #{pending_migrations.size > 1 ? 'migrations:' : 'migration:'}" @@ -261,6 +265,26 @@ db_namespace = namespace :db do end end + namespace :abort_if_pending_migrations do + ActiveRecord::Tasks::DatabaseTasks.for_each do |spec_name| + # desc "Raises an error if there are pending migrations for #{spec_name} database" + task spec_name => :load_config do + db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name) + ActiveRecord::Base.establish_connection(db_config.config) + + pending_migrations = ActiveRecord::Base.connection.migration_context.open.pending_migrations + + if pending_migrations.any? + puts "You have #{pending_migrations.size} pending #{pending_migrations.size > 1 ? 'migrations:' : 'migration:'}" + pending_migrations.each do |pending_migration| + puts " %4d %s" % [pending_migration.version, pending_migration.name] + end + abort %{Run `rails db:migrate:#{spec_name}` to update your database then try again.} + end + end + end + end + desc "Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)" task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed] |