这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/railties/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ db_namespace = namespace :db do
conn.migration_context.run(:up, ActiveRecord::Tasks::DatabaseTasks.target_version)
end

db_namespace["_dump"].invoke
db_namespace["_dump:#{name}"].invoke
end
end
end
Expand Down Expand Up @@ -235,7 +235,7 @@ db_namespace = namespace :db do
conn.migration_context.run(:down, ActiveRecord::Tasks::DatabaseTasks.target_version)
end

db_namespace["_dump"].invoke
db_namespace["_dump:#{name}"].invoke
end
end
end
Expand Down Expand Up @@ -269,7 +269,7 @@ db_namespace = namespace :db do
conn.migration_context.rollback(step)
end

db_namespace["_dump"].invoke
db_namespace["_dump:#{name}"].invoke
end
end
end
Expand Down
36 changes: 36 additions & 0 deletions railties/test/application/rake/multi_dbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,28 @@ class TwoMigration < ActiveRecord::Migration::Current
db_up_and_down "02", "animals"
end

test "db:migrate:down:namespace and db:migrate:up:namespace dumps schema only for specific database" do
require "#{app_path}/config/environment"

app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
class OneMigration < ActiveRecord::Migration::Current
end
MIGRATION

app_file "db/animals_migrate/02_two_migration.rb", <<-MIGRATION
class TwoMigration < ActiveRecord::Migration::Current
end
MIGRATION

Dir.chdir(app_path) do
rails("db:migrate:up:primary", "VERSION=01")
rails("db:migrate:down:primary", "VERSION=01")

assert File.exist?("db/schema.rb"), "should dump schema for primary database"
assert_not File.exist?("db/animals_schema.rb"), "should not dump schema for animals database"
end
end

test "db:migrate:redo raises in a multi-db application" do
require "#{app_path}/config/environment"
db_migrate_redo
Expand Down Expand Up @@ -742,6 +764,20 @@ class TwoMigration < ActiveRecord::Migration::Current
db_migrate_and_rollback "animals"
end

test "db:rollback:namespace dumps schema only for specific database" do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "generate", "model", "dog", "name:string", "--database animals"
rails "db:migrate"
File.delete("db/animals_schema.rb")

rails "db:rollback:primary"

assert File.exist?("db/schema.rb"), "should dump schema for primary database"
assert_not File.exist?("db/animals_schema.rb"), "should not dump schema for animals database"
end
end

test "db:migrate:status works on all databases" do
require "#{app_path}/config/environment"
db_migrate_and_migrate_status
Expand Down