Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
36c3da0f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
36c3da0f
编写于
9月 18, 2019
作者:
E
Eileen M. Uchitelle
提交者:
GitHub
9月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #37242 from seejohnrun/use-database-configs-instead-of-configuration_hash
Make DatabaseTasks use DatabaseConfig objects
上级
3a77fca5
aa3e92fd
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
228 addition
and
157 deletion
+228
-157
activerecord/lib/active_record/migration.rb
activerecord/lib/active_record/migration.rb
+1
-1
activerecord/lib/active_record/railties/databases.rake
activerecord/lib/active_record/railties/databases.rake
+22
-24
activerecord/lib/active_record/tasks/database_tasks.rb
activerecord/lib/active_record/tasks/database_tasks.rb
+87
-80
activerecord/lib/active_record/tasks/mysql_database_tasks.rb
activerecord/lib/active_record/tasks/mysql_database_tasks.rb
+1
-1
activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
...cord/lib/active_record/tasks/postgresql_database_tasks.rb
+1
-1
activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
...verecord/lib/active_record/tasks/sqlite_database_tasks.rb
+1
-1
activerecord/lib/active_record/test_databases.rb
activerecord/lib/active_record/test_databases.rb
+1
-1
activerecord/test/cases/tasks/database_tasks_test.rb
activerecord/test/cases/tasks/database_tasks_test.rb
+114
-48
未找到文件。
activerecord/lib/active_record/migration.rb
浏览文件 @
36c3da0f
...
...
@@ -591,7 +591,7 @@ def load_schema_if_pending!
all_configs
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
)
needs_update
=
!
all_configs
.
all?
do
|
db_config
|
Tasks
::
DatabaseTasks
.
schema_up_to_date?
(
db_config
.
configuration_hash
,
ActiveRecord
::
Base
.
schema_format
,
nil
,
Rails
.
env
,
db_config
.
spec_name
)
Tasks
::
DatabaseTasks
.
schema_up_to_date?
(
db_config
,
ActiveRecord
::
Base
.
schema_format
)
end
if
needs_update
...
...
activerecord/lib/active_record/railties/databases.rake
浏览文件 @
36c3da0f
...
...
@@ -29,7 +29,7 @@ db_namespace = namespace :db do
desc
"Create
#{
spec_name
}
database for current environment"
task
spec_name
=>
:load_config
do
db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
,
spec_name:
spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
(
db_config
.
configuration_hash
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
(
db_config
)
end
end
end
...
...
@@ -48,7 +48,7 @@ db_namespace = namespace :db do
desc
"Drop
#{
spec_name
}
database for current environment"
task
spec_name
=>
[
:load_config
,
:check_protected_environments
]
do
db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
,
spec_name:
spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop
(
db_config
.
configuration_hash
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop
(
db_config
)
end
end
end
...
...
@@ -81,7 +81,7 @@ db_namespace = namespace :db do
desc
"Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
task
migrate: :load_config
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate
end
db_namespace
[
"_dump"
].
invoke
...
...
@@ -107,7 +107,7 @@ db_namespace = namespace :db do
desc
"Migrate
#{
spec_name
}
database for current environment"
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
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate
end
end
...
...
@@ -150,7 +150,7 @@ db_namespace = namespace :db do
db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
,
spec_name:
spec_name
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
check_target_version
ActiveRecord
::
Base
.
connection
.
migration_context
.
run
(
:up
,
...
...
@@ -184,7 +184,7 @@ db_namespace = namespace :db do
db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
,
spec_name:
spec_name
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
check_target_version
ActiveRecord
::
Base
.
connection
.
migration_context
.
run
(
:down
,
...
...
@@ -199,7 +199,7 @@ db_namespace = namespace :db do
desc
"Display status of migrations"
task
status: :load_config
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate_status
end
end
...
...
@@ -209,7 +209,7 @@ db_namespace = namespace :db do
desc
"Display status of 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
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate_status
end
end
...
...
@@ -253,7 +253,7 @@ 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
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
flat_map
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Base
.
connection
.
migration_context
.
open
.
pending_migrations
end
...
...
@@ -274,7 +274,7 @@ db_namespace = namespace :db do
# 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
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
pending_migrations
=
ActiveRecord
::
Base
.
connection
.
migration_context
.
open
.
pending_migrations
...
...
@@ -297,22 +297,20 @@ db_namespace = namespace :db do
seed
=
false
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
# Skipped when no database
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate
if
ActiveRecord
::
Base
.
dump_schema_after_migration
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema
(
db_config
.
configuration_hash
,
ActiveRecord
::
Base
.
schema_format
,
db_config
.
spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema
(
db_config
,
ActiveRecord
::
Base
.
schema_format
)
end
rescue
ActiveRecord
::
NoDatabaseError
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
db_config
.
env_name
,
db_config
.
spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
load_schema
(
db_config
.
configuration_hash
,
db_config
,
ActiveRecord
::
Base
.
schema_format
,
nil
,
db_config
.
env_name
,
db_config
.
spec_name
nil
)
seed
=
true
...
...
@@ -385,8 +383,8 @@ db_namespace = namespace :db do
desc
"Creates a db/schema.rb file that is portable against any DB supported by Active Record"
task
dump: :load_config
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema
(
db_config
.
configuration_hash
,
:ruby
,
db_config
.
spec_name
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema
(
db_config
,
:ruby
)
end
db_namespace
[
"schema:dump"
].
reenable
...
...
@@ -405,7 +403,7 @@ db_namespace = namespace :db do
desc
"Creates a db/schema_cache.yml file."
task
dump: :load_config
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
filename
=
ActiveRecord
::
Tasks
::
DatabaseTasks
.
cache_dump_filename
(
db_config
.
spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema_cache
(
ActiveRecord
::
Base
.
connection
,
...
...
@@ -428,8 +426,8 @@ db_namespace = namespace :db do
desc
"Dumps the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
task
dump: :load_config
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
configuration_hash
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema
(
db_config
.
configuration_hash
,
:sql
,
db_config
.
spec_name
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_schema
(
db_config
,
:sql
)
end
db_namespace
[
"structure:dump"
].
reenable
...
...
@@ -462,7 +460,7 @@ db_namespace = namespace :db do
ActiveRecord
::
Schema
.
verbose
=
false
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"test"
).
each
do
|
db_config
|
filename
=
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_filename
(
db_config
.
spec_name
,
:ruby
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
load_schema
(
db_config
.
configuration_hash
,
:ruby
,
filename
,
"test"
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
load_schema
(
db_config
,
:ruby
,
filename
)
end
ensure
if
should_reconnect
...
...
@@ -474,14 +472,14 @@ db_namespace = namespace :db do
task
load_structure:
%w(db:test:purge)
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"test"
).
each
do
|
db_config
|
filename
=
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_filename
(
db_config
.
spec_name
,
:sql
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
load_schema
(
db_config
.
configuration_hash
,
:sql
,
filename
,
"test"
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
load_schema
(
db_config
,
:sql
,
filename
)
end
end
# desc "Empty the test database"
task
purge:
%w(load_config check_protected_environments)
do
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"test"
).
each
do
|
db_config
|
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge
(
db_config
.
configuration_hash
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge
(
db_config
)
end
end
...
...
activerecord/lib/active_record/tasks/database_tasks.rb
浏览文件 @
36c3da0f
...
...
@@ -123,23 +123,23 @@ def current_config(options = {})
end
deprecate
:current_config
def
create
(
*
arguments
)
configuration
=
arguments
.
first
.
symbolize_keys
class_for_adapter
(
configuration
[
:adapter
]).
new
(
*
arguments
).
create
$stdout
.
puts
"Created database '
#{
configuration
[
:database
]
}
'"
if
verbose?
def
create
(
configuration
,
*
arguments
)
db_config
=
resolve_configuration
(
configuration
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
,
*
arguments
).
create
$stdout
.
puts
"Created database '
#{
db_config
.
configuration_hash
[
:database
]
}
'"
if
verbose?
rescue
DatabaseAlreadyExists
$stderr
.
puts
"Database '
#{
configuration
[
:database
]
}
' already exists"
if
verbose?
$stderr
.
puts
"Database '
#{
db_config
.
configuration_hash
[
:database
]
}
' already exists"
if
verbose?
rescue
Exception
=>
error
$stderr
.
puts
error
$stderr
.
puts
"Couldn't create '
#{
configuration
[
:database
]
}
' database. Please check your configuration."
$stderr
.
puts
"Couldn't create '
#{
db_config
.
configuration_hash
[
:database
]
}
' database. Please check your configuration."
raise
end
def
create_all
old_pool
=
ActiveRecord
::
Base
.
connection_handler
.
retrieve_connection_pool
(
ActiveRecord
::
Base
.
connection_specification_name
)
each_local_configuration
{
|
configuration
|
create
configuration
}
each_local_configuration
{
|
db_config
|
create
(
db_config
)
}
if
old_pool
ActiveRecord
::
Base
.
connection_handler
.
establish_connection
(
old_pool
.
spec
.
db_config
.
configuration_hash
)
ActiveRecord
::
Base
.
connection_handler
.
establish_connection
(
old_pool
.
spec
.
db_config
)
end
end
...
...
@@ -183,36 +183,32 @@ def raise_for_multi_db(environment = env, command:)
end
def
create_current
(
environment
=
env
,
spec_name
=
nil
)
each_current_configuration
(
environment
,
spec_name
)
{
|
configuration
|
create
configuration
}
each_current_configuration
(
environment
,
spec_name
)
{
|
db_config
|
create
(
db_config
)
}
ActiveRecord
::
Base
.
establish_connection
(
environment
.
to_sym
)
end
def
drop
(
*
arguments
)
configuration
=
arguments
.
first
.
symbolize_keys
class_for_adapter
(
configuration
[
:adapter
]).
new
(
*
arguments
).
drop
$stdout
.
puts
"Dropped database '
#{
configuration
[
:database
]
}
'"
if
verbose?
def
drop
(
configuration
,
*
arguments
)
db_config
=
resolve_configuration
(
configuration
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
,
*
arguments
).
drop
$stdout
.
puts
"Dropped database '
#{
db_config
.
configuration_hash
[
:database
]
}
'"
if
verbose?
rescue
ActiveRecord
::
NoDatabaseError
$stderr
.
puts
"Database '
#{
configuration
[
:database
]
}
' does not exist"
$stderr
.
puts
"Database '
#{
db_config
.
configuration_hash
[
:database
]
}
' does not exist"
rescue
Exception
=>
error
$stderr
.
puts
error
$stderr
.
puts
"Couldn't drop database '
#{
configuration
[
:database
]
}
'"
$stderr
.
puts
"Couldn't drop database '
#{
db_config
.
configuration_hash
[
:database
]
}
'"
raise
end
def
drop_all
each_local_configuration
{
|
configuration
|
drop
configuration
}
each_local_configuration
{
|
db_config
|
drop
(
db_config
)
}
end
def
drop_current
(
environment
=
env
)
each_current_configuration
(
environment
)
{
|
configuration
|
drop
configuration
}
each_current_configuration
(
environment
)
{
|
db_config
|
drop
(
db_config
)
}
end
def
truncate_tables
(
configuration
)
ActiveRecord
::
Base
.
connected_to
(
database:
{
truncation:
configuration
})
do
def
truncate_tables
(
db_config
)
ActiveRecord
::
Base
.
connected_to
(
database:
{
truncation:
db_config
.
configuration_hash
})
do
conn
=
ActiveRecord
::
Base
.
connection
table_names
=
conn
.
tables
table_names
-=
[
...
...
@@ -227,7 +223,7 @@ def truncate_tables(configuration)
def
truncate_all
(
environment
=
env
)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
environment
).
each
do
|
db_config
|
truncate_tables
db_config
.
configuration_hash
truncate_tables
(
db_config
)
end
end
...
...
@@ -271,107 +267,113 @@ def target_version
ENV
[
"VERSION"
].
to_i
if
ENV
[
"VERSION"
]
&&
!
ENV
[
"VERSION"
].
empty?
end
def
charset_current
(
environment
=
env
,
specification_name
=
spec
)
charset
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
environment
,
spec_name:
specification_name
).
configuration_hash
def
charset_current
(
env_name
=
env
,
spec_name
=
spec
)
db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
charset
(
db_config
)
end
def
charset
(
*
arguments
)
configuration
=
arguments
.
first
.
symbolize_keys
class_for_adapter
(
configuration
[
:adapter
]).
new
(
*
arguments
).
charset
def
charset
(
configuration
,
*
arguments
)
db_config
=
resolve_configuration
(
configuration
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
,
*
arguments
).
charset
end
def
collation_current
(
environment
=
env
,
specification_name
=
spec
)
collation
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
environment
,
spec_name:
specification_name
).
configuration_hash
def
collation_current
(
env_name
=
env
,
spec_name
=
spec
)
db_config
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
collation
(
db_config
)
end
def
collation
(
*
arguments
)
configuration
=
arguments
.
first
.
symbolize_keys
class_for_adapter
(
configuration
[
:adapter
]).
new
(
*
arguments
).
collation
def
collation
(
configuration
,
*
arguments
)
db_config
=
resolve_configuration
(
configuration
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
,
*
arguments
).
collation
end
def
purge
(
configuration
)
configuration
=
configuration
.
symbolize_keys
class_for_adapter
(
configuration
[
:adapter
]).
new
(
configuration
).
purge
db_config
=
resolve_configuration
(
configuration
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
).
purge
end
def
purge_all
each_local_configuration
{
|
configuration
|
purge
configuration
}
each_local_configuration
{
|
db_config
|
purge
(
db_config
)
}
end
def
purge_current
(
environment
=
env
)
each_current_configuration
(
environment
)
{
|
configuration
|
purge
configuration
}
each_current_configuration
(
environment
)
{
|
db_config
|
purge
(
db_config
)
}
ActiveRecord
::
Base
.
establish_connection
(
environment
.
to_sym
)
end
def
structure_dump
(
*
arguments
)
configuration
=
arguments
.
first
.
symbolize_keys
filename
=
arguments
.
delete_at
1
class_for_adapter
(
configuration
[
:adapter
]).
new
(
*
arguments
).
structure_dump
(
filename
,
structure_dump_flags
)
def
structure_dump
(
configuration
,
*
arguments
)
db_config
=
resolve_configuration
(
configuration
)
filename
=
arguments
.
delete_at
(
0
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
,
*
arguments
).
structure_dump
(
filename
,
structure_dump_flags
)
end
def
structure_load
(
*
arguments
)
configuration
=
arguments
.
first
.
symbolize_keys
filename
=
arguments
.
delete_at
1
class_for_adapter
(
configuration
[
:adapter
]).
new
(
*
arguments
).
structure_load
(
filename
,
structure_load_flags
)
def
structure_load
(
configuration
,
*
arguments
)
db_config
=
resolve_configuration
(
configuration
)
filename
=
arguments
.
delete_at
(
0
)
class_for_adapter
(
db_config
.
configuration_hash
[
:adapter
]).
new
(
db_config
.
configuration_hash
,
*
arguments
).
structure_load
(
filename
,
structure_load_flags
)
end
def
load_schema
(
configuration
,
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
,
environment
=
env
,
spec_name
=
"primary"
)
# :nodoc:
file
||=
dump_filename
(
spec_name
,
format
)
def
load_schema
(
db_config
,
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
)
# :nodoc:
file
||=
dump_filename
(
db_config
.
spec_name
,
format
)
verbose_was
,
Migration
.
verbose
=
Migration
.
verbose
,
verbose?
&&
ENV
[
"VERBOSE"
]
check_schema_file
(
file
)
ActiveRecord
::
Base
.
establish_connection
(
configuration
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
case
format
when
:ruby
load
(
file
)
when
:sql
structure_load
(
configuration
,
file
)
structure_load
(
db_config
,
file
)
else
raise
ArgumentError
,
"unknown format
#{
format
.
inspect
}
"
end
ActiveRecord
::
InternalMetadata
.
create_table
ActiveRecord
::
InternalMetadata
[
:environment
]
=
environment
ActiveRecord
::
InternalMetadata
[
:environment
]
=
db_config
.
env_name
ActiveRecord
::
InternalMetadata
[
:schema_sha1
]
=
schema_sha1
(
file
)
ensure
Migration
.
verbose
=
verbose_was
end
def
schema_up_to_date?
(
configuration
,
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
,
environment
=
env
,
spec_name
=
"primary"
)
def
schema_up_to_date?
(
configuration
,
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
,
environment
=
nil
,
spec_name
=
nil
)
db_config
=
resolve_configuration
(
configuration
)
if
environment
||
spec_name
ActiveSupport
::
Deprecation
.
warn
(
"`environment` and `spec_name` will be removed as parameters in 6.2.0, you may now pass an ActiveRecord::DatabaseConfigurations::DatabaseConfig as `configuration` instead."
)
end
spec_name
||=
db_config
.
spec_name
file
||=
dump_filename
(
spec_name
,
format
)
return
true
unless
File
.
exist?
(
file
)
ActiveRecord
::
Base
.
establish_connection
(
configuration
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
return
false
unless
ActiveRecord
::
InternalMetadata
.
table_exists?
ActiveRecord
::
InternalMetadata
[
:schema_sha1
]
==
schema_sha1
(
file
)
end
def
reconstruct_from_schema
(
configuration
,
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
,
environment
=
env
,
spec_name
=
"primary"
)
# :nodoc:
file
||=
dump_filename
(
spec_name
,
format
)
def
reconstruct_from_schema
(
db_config
,
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
)
# :nodoc:
file
||=
dump_filename
(
db_config
.
spec_name
,
format
)
check_schema_file
(
file
)
ActiveRecord
::
Base
.
establish_connection
(
configuration
)
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
if
schema_up_to_date?
(
configuration
,
format
,
file
,
environment
,
spec_nam
e
)
truncate_tables
(
configuration
)
if
schema_up_to_date?
(
db_config
,
format
,
fil
e
)
truncate_tables
(
db_config
)
else
purge
(
configuration
)
load_schema
(
configuration
,
format
,
file
,
environment
,
spec_nam
e
)
purge
(
db_config
)
load_schema
(
db_config
,
format
,
fil
e
)
end
rescue
ActiveRecord
::
NoDatabaseError
create
(
configuration
)
load_schema
(
configuration
,
format
,
file
,
environment
,
spec_nam
e
)
create
(
db_config
)
load_schema
(
db_config
,
format
,
fil
e
)
end
def
dump_schema
(
configuration
,
format
=
ActiveRecord
::
Base
.
schema_format
,
spec_name
=
"primary"
)
# :nodoc:
def
dump_schema
(
db_config
,
format
=
ActiveRecord
::
Base
.
schema_format
)
# :nodoc:
require
"active_record/schema_dumper"
filename
=
dump_filename
(
spec_name
,
format
)
filename
=
dump_filename
(
db_config
.
spec_name
,
format
)
connection
=
ActiveRecord
::
Base
.
connection
case
format
...
...
@@ -380,7 +382,7 @@ def dump_schema(configuration, format = ActiveRecord::Base.schema_format, spec_n
ActiveRecord
::
SchemaDumper
.
dump
(
ActiveRecord
::
Base
.
connection
,
file
)
end
when
:sql
structure_dump
(
configuration
,
filename
)
structure_dump
(
db_config
,
filename
)
if
connection
.
schema_migration
.
table_exists?
File
.
open
(
filename
,
"a"
)
do
|
f
|
f
.
puts
connection
.
dump_schema_information
...
...
@@ -424,9 +426,9 @@ def cache_dump_filename(namespace)
end
def
load_schema_current
(
format
=
ActiveRecord
::
Base
.
schema_format
,
file
=
nil
,
environment
=
env
)
each_current_configuration
(
environment
)
{
|
configuration
,
spec_name
,
env
|
load_schema
(
configuration
,
format
,
file
,
env
,
spec_nam
e
)
}
each_current_configuration
(
environment
)
do
|
db_config
|
load_schema
(
db_config
,
format
,
fil
e
)
end
ActiveRecord
::
Base
.
establish_connection
(
environment
.
to_sym
)
end
...
...
@@ -459,6 +461,11 @@ def dump_schema_cache(conn, filename)
end
private
def
resolve_configuration
(
configuration
)
resolver
=
ConnectionAdapters
::
Resolver
.
new
(
ActiveRecord
::
Base
.
configurations
)
resolver
.
resolve
(
configuration
)
end
def
verbose?
ENV
[
"VERBOSE"
]
?
ENV
[
"VERBOSE"
]
!=
"false"
:
true
end
...
...
@@ -479,26 +486,26 @@ def each_current_configuration(environment, spec_name = nil)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env
).
each
do
|
db_config
|
next
if
spec_name
&&
spec_name
!=
db_config
.
spec_name
yield
db_config
.
configuration_hash
,
db_config
.
spec_name
,
env
yield
db_config
end
end
end
def
each_local_configuration
ActiveRecord
::
Base
.
configurations
.
configs_for
.
each
do
|
db_config
|
configuration
=
db_config
.
configuration_hash
next
unless
configuration
[
:database
]
next
unless
db_config
.
configuration_hash
[
:database
]
if
local_database?
(
configuration
)
yield
configuration
if
local_database?
(
db_config
)
yield
db_config
else
$stderr
.
puts
"This task only modifies local databases.
#{
configuration
[
:database
]
}
is on a remote host."
$stderr
.
puts
"This task only modifies local databases.
#{
db_config
.
configuration_hash
[
:database
]
}
is on a remote host."
end
end
end
def
local_database?
(
configuration
)
configuration
[
:host
].
blank?
||
LOCAL_HOSTS
.
include?
(
configuration
[
:host
])
def
local_database?
(
db_config
)
host
=
db_config
.
configuration_hash
[
:host
]
host
.
blank?
||
LOCAL_HOSTS
.
include?
(
host
)
end
def
schema_sha1
(
file
)
...
...
activerecord/lib/active_record/tasks/mysql_database_tasks.rb
浏览文件 @
36c3da0f
...
...
@@ -8,7 +8,7 @@ class MySQLDatabaseTasks # :nodoc:
delegate
:connection
,
:establish_connection
,
to:
ActiveRecord
::
Base
def
initialize
(
configuration
)
@configuration
=
configuration
.
symbolize_keys
@configuration
=
configuration
end
def
create
...
...
activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
浏览文件 @
36c3da0f
...
...
@@ -13,7 +13,7 @@ class PostgreSQLDatabaseTasks # :nodoc:
to:
ActiveRecord
::
Base
def
initialize
(
configuration
)
@configuration
=
configuration
.
symbolize_keys
@configuration
=
configuration
end
def
create
(
master_established
=
false
)
...
...
activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
浏览文件 @
36c3da0f
...
...
@@ -6,7 +6,7 @@ class SQLiteDatabaseTasks # :nodoc:
delegate
:connection
,
:establish_connection
,
to:
ActiveRecord
::
Base
def
initialize
(
configuration
,
root
=
ActiveRecord
::
Tasks
::
DatabaseTasks
.
root
)
@configuration
,
@root
=
configuration
.
symbolize_keys
,
root
@configuration
,
@root
=
configuration
,
root
end
def
create
...
...
activerecord/lib/active_record/test_databases.rb
浏览文件 @
36c3da0f
...
...
@@ -13,7 +13,7 @@ def self.create_and_load_schema(i, env_name:)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
).
each
do
|
db_config
|
db_config
.
configuration_hash
[
:database
]
+=
"-
#{
i
}
"
ActiveRecord
::
Tasks
::
DatabaseTasks
.
reconstruct_from_schema
(
db_config
.
configuration_hash
,
ActiveRecord
::
Base
.
schema_format
,
nil
,
env_name
,
db_config
.
spec_name
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
reconstruct_from_schema
(
db_config
,
ActiveRecord
::
Base
.
schema_format
,
nil
)
end
ensure
ActiveRecord
::
Base
.
establish_connection
(
Rails
.
env
.
to_sym
)
...
...
activerecord/test/cases/tasks/database_tasks_test.rb
浏览文件 @
36c3da0f
...
...
@@ -14,7 +14,9 @@ def create; end
def
drop
;
end
def
purge
;
end
def
charset
;
end
def
charset_current
;
end
def
collation
;
end
def
collation_current
;
end
def
structure_dump
(
*
);
end
def
structure_load
(
*
);
end
end
.
new
...
...
@@ -317,7 +319,7 @@ def test_creates_current_environment_database
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
database:
"test-db"
],
[
config_for
(
"test"
,
"primary"
)]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
ActiveSupport
::
StringInquirer
.
new
(
"test"
)
...
...
@@ -331,7 +333,7 @@ def test_creates_current_environment_database_with_url
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
adapter:
"abstract"
,
database:
"prod-db"
,
host:
"prod-db-host"
],
[
config_for
(
"production"
,
"primary"
)]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
ActiveSupport
::
StringInquirer
.
new
(
"production"
)
...
...
@@ -346,8 +348,8 @@ def test_creates_test_and_development_databases_when_env_was_not_specified
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
[
database:
"dev-db"
],
[
database:
"test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"test"
,
"primary"
)
]
],
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
...
...
@@ -366,8 +368,8 @@ def test_creates_test_and_development_databases_when_rails_env_is_development
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
[
database:
"dev-db"
],
[
database:
"test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"test"
,
"primary"
)
]
],
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
...
...
@@ -390,6 +392,10 @@ def test_establishes_connection_for_the_given_environments
end
private
def
config_for
(
env_name
,
spec_name
)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
end
def
with_stubbed_configurations_establish_connection
old_configurations
=
ActiveRecord
::
Base
.
configurations
ActiveRecord
::
Base
.
configurations
=
@configurations
...
...
@@ -417,8 +423,8 @@ def test_creates_current_environment_database
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
...
...
@@ -434,8 +440,8 @@ def test_creates_current_environment_database_with_url
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
[
adapter:
"abstract"
,
database:
"prod-db"
,
host:
"prod-db-host"
],
[
adapter:
"abstract"
,
database:
"secondary-prod-db"
,
host:
"secondary-prod-db-host"
]
[
config_for
(
"production"
,
"primary"
)
],
[
config_for
(
"production"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
...
...
@@ -451,10 +457,10 @@ def test_creates_test_and_development_databases_when_env_was_not_specified
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
[
database:
"dev-db"
],
[
database:
"secondary-dev-db"
],
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"development"
,
"secondary"
)
],
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
...
...
@@ -473,10 +479,10 @@ def test_creates_test_and_development_databases_when_rails_env_is_development
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:create
,
[
[
database:
"dev-db"
],
[
database:
"secondary-dev-db"
],
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"development"
,
"secondary"
)
],
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_current
(
...
...
@@ -503,6 +509,10 @@ def test_establishes_connection_for_the_given_environments_config
end
private
def
config_for
(
env_name
,
spec_name
)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
end
def
with_stubbed_configurations_establish_connection
old_configurations
=
ActiveRecord
::
Base
.
configurations
ActiveRecord
::
Base
.
configurations
=
@configurations
...
...
@@ -624,8 +634,11 @@ def setup
def
test_drops_current_environment_database
with_stubbed_configurations
do
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
database:
"test-db"
])
do
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
config_for
(
"test"
,
"primary"
)]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
ActiveSupport
::
StringInquirer
.
new
(
"test"
)
)
...
...
@@ -635,8 +648,11 @@ def test_drops_current_environment_database
def
test_drops_current_environment_database_with_url
with_stubbed_configurations
do
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
adapter:
"abstract"
,
database:
"prod-db"
,
host:
"prod-db-host"
])
do
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
config_for
(
"production"
,
"primary"
)]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
ActiveSupport
::
StringInquirer
.
new
(
"production"
)
)
...
...
@@ -650,8 +666,8 @@ def test_drops_test_and_development_databases_when_env_was_not_specified
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
[
database:
"dev-db"
],
[
database:
"test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"test"
,
"primary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
...
...
@@ -670,8 +686,8 @@ def test_drops_testand_development_databases_when_rails_env_is_development
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
[
database:
"dev-db"
],
[
database:
"test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"test"
,
"primary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
...
...
@@ -684,6 +700,10 @@ def test_drops_testand_development_databases_when_rails_env_is_development
end
private
def
config_for
(
env_name
,
spec_name
)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
end
def
with_stubbed_configurations
old_configurations
=
ActiveRecord
::
Base
.
configurations
ActiveRecord
::
Base
.
configurations
=
@configurations
...
...
@@ -709,8 +729,8 @@ def test_drops_current_environment_database
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
...
...
@@ -726,8 +746,8 @@ def test_drops_current_environment_database_with_url
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
[
adapter:
"abstract"
,
database:
"prod-db"
,
host:
"prod-db-host"
],
[
adapter:
"abstract"
,
database:
"secondary-prod-db"
,
host:
"secondary-prod-db-host"
]
[
config_for
(
"production"
,
"primary"
)
],
[
config_for
(
"production"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
...
...
@@ -743,10 +763,10 @@ def test_drops_test_and_development_databases_when_env_was_not_specified
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
[
database:
"dev-db"
],
[
database:
"secondary-dev-db"
],
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"development"
,
"secondary"
)
],
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
...
...
@@ -765,10 +785,10 @@ def test_drops_testand_development_databases_when_rails_env_is_development
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:drop
,
[
[
database:
"dev-db"
],
[
database:
"secondary-dev-db"
],
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"development"
,
"secondary"
)
],
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_current
(
...
...
@@ -781,6 +801,10 @@ def test_drops_testand_development_databases_when_rails_env_is_development
end
private
def
config_for
(
env_name
,
spec_name
)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
end
def
with_stubbed_configurations
old_configurations
=
ActiveRecord
::
Base
.
configurations
ActiveRecord
::
Base
.
configurations
=
@configurations
...
...
@@ -977,7 +1001,7 @@ def test_purges_current_environment_database
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:purge
,
[
database:
"prod-db"
]
[
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"production"
,
spec_name:
"primary"
)
]
)
do
assert_called_with
(
ActiveRecord
::
Base
,
:establish_connection
,
[
:production
])
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge_current
(
"production"
)
...
...
@@ -997,7 +1021,7 @@ def test_purge_all_local_configurations
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:purge
,
[
database:
"my-db"
]
[
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"development"
,
spec_name:
"primary"
)
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge_all
end
...
...
@@ -1098,8 +1122,8 @@ def test_truncate_all_databases_for_environment
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:truncate_tables
,
[
[
database:
"test-db"
],
[
database:
"secondary-test-db"
]
[
config_for
(
"test"
,
"primary"
)
],
[
config_for
(
"test"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
truncate_all
(
...
...
@@ -1115,8 +1139,8 @@ def test_truncate_all_databases_with_url_for_environment
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:truncate_tables
,
[
[
adapter:
"abstract"
,
database:
"prod-db"
,
host:
"prod-db-host"
],
[
adapter:
"abstract"
,
database:
"secondary-prod-db"
,
host:
"secondary-prod-db-host"
]
[
config_for
(
"production"
,
"primary"
)
],
[
config_for
(
"production"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
truncate_all
(
...
...
@@ -1132,8 +1156,8 @@ def test_truncate_all_development_databases_when_env_is_not_specified
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:truncate_tables
,
[
[
database:
"dev-db"
],
[
database:
"secondary-dev-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"development"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
truncate_all
(
...
...
@@ -1152,8 +1176,8 @@ def test_truncate_all_development_databases_when_env_is_development
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:truncate_tables
,
[
[
database:
"dev-db"
],
[
database:
"secondary-dev-db"
]
[
config_for
(
"development"
,
"primary"
)
],
[
config_for
(
"development"
,
"secondary"
)
]
]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
truncate_all
(
...
...
@@ -1166,6 +1190,10 @@ def test_truncate_all_development_databases_when_env_is_development
end
private
def
config_for
(
env_name
,
spec_name
)
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
env_name
,
spec_name:
spec_name
)
end
def
with_stubbed_configurations
old_configurations
=
ActiveRecord
::
Base
.
configurations
ActiveRecord
::
Base
.
configurations
=
@configurations
...
...
@@ -1188,6 +1216,25 @@ class DatabaseTasksCharsetTest < ActiveRecord::TestCase
end
end
end
def
test_charset_current
old_configurations
=
ActiveRecord
::
Base
.
configurations
configurations
=
{
"production"
=>
{
"database"
=>
"prod-db"
}
}
ActiveRecord
::
Base
.
configurations
=
configurations
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:charset
,
[
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"production"
,
spec_name:
"primary"
)]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
charset_current
(
"production"
,
"primary"
)
end
ensure
ActiveRecord
::
Base
.
configurations
=
old_configurations
end
end
class
DatabaseTasksCollationTest
<
ActiveRecord
::
TestCase
...
...
@@ -1202,6 +1249,25 @@ class DatabaseTasksCollationTest < ActiveRecord::TestCase
end
end
end
def
test_collation_current
old_configurations
=
ActiveRecord
::
Base
.
configurations
configurations
=
{
"production"
=>
{
"database"
=>
"prod-db"
}
}
ActiveRecord
::
Base
.
configurations
=
configurations
assert_called_with
(
ActiveRecord
::
Tasks
::
DatabaseTasks
,
:collation
,
[
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
"production"
,
spec_name:
"primary"
)]
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
collation_current
(
"production"
,
"primary"
)
end
ensure
ActiveRecord
::
Base
.
configurations
=
old_configurations
end
end
class
DatabaseTaskTargetVersionTest
<
ActiveRecord
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录