Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9413ef56
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
9413ef56
编写于
10月 10, 2018
作者:
E
Eileen M. Uchitelle
提交者:
GitHub
10月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34137 from gmcgibbon/db_migrate_status_multi_db
Add multi-db support to rails db:migrate:status
上级
8a1cc51e
287c0de8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
20 deletion
+71
-20
activerecord/lib/active_record/railties/databases.rake
activerecord/lib/active_record/railties/databases.rake
+15
-1
railties/CHANGELOG.md
railties/CHANGELOG.md
+5
-0
railties/test/application/rake/multi_dbs_test.rb
railties/test/application/rake/multi_dbs_test.rb
+51
-19
未找到文件。
activerecord/lib/active_record/railties/databases.rake
浏览文件 @
9413ef56
...
...
@@ -149,7 +149,21 @@ db_namespace = namespace :db do
desc
"Display status of migrations"
task
status: :load_config
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate_status
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
).
each
do
|
db_config
|
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate_status
end
end
namespace
:status
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
for_each
do
|
spec_name
|
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
.
config
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
migrate_status
end
end
end
end
...
...
railties/CHANGELOG.md
浏览文件 @
9413ef56
*
Adds support for multiple databases to
`rails db:migrate:status`
.
Subtasks are also added to get the status of individual databases (eg.
`rails db:migrate:status:animals`
).
*Gannon McGibbon*
*
Use Webpacker by default to manage app-level JavaScript through the new app/javascript directory.
Sprockets is now solely in charge, by default, of compiling CSS and other static assets.
Action Cable channel generators will create ES6 stubs rather than use CoffeeScript.
...
...
railties/test/application/rake/multi_dbs_test.rb
浏览文件 @
9413ef56
...
...
@@ -55,11 +55,19 @@ def assert_match_namespace(namespace, output)
end
end
def
db_migrate_and_
schema_dump_and_load
(
namespace
,
expected_database
,
format
)
def
db_migrate_and_
migrate_status
Dir
.
chdir
(
app_path
)
do
rails
"generate"
,
"model"
,
"book"
,
"title:string"
rails
"generate"
,
"model"
,
"dog"
,
"name:string"
write_models_for_animals
generate_models_for_animals
rails
"db:migrate"
output
=
rails
"db:migrate:status"
assert_match
(
/up \d+ Create books/
,
output
)
assert_match
(
/up \d+ Create dogs/
,
output
)
end
end
def
db_migrate_and_schema_dump_and_load
(
format
)
Dir
.
chdir
(
app_path
)
do
generate_models_for_animals
rails
"db:migrate"
,
"db:
#{
format
}
:dump"
if
format
==
"schema"
...
...
@@ -86,9 +94,7 @@ def db_migrate_and_schema_dump_and_load(namespace, expected_database, format)
def
db_migrate_namespaced
(
namespace
,
expected_database
)
Dir
.
chdir
(
app_path
)
do
rails
"generate"
,
"model"
,
"book"
,
"title:string"
rails
"generate"
,
"model"
,
"dog"
,
"name:string"
write_models_for_animals
generate_models_for_animals
output
=
rails
(
"db:migrate:
#{
namespace
}
"
)
if
namespace
==
"primary"
assert_match
(
/CreateBooks: migrated/
,
output
)
...
...
@@ -98,6 +104,18 @@ def db_migrate_namespaced(namespace, expected_database)
end
end
def
db_migrate_status_namespaced
(
namespace
,
expected_database
)
Dir
.
chdir
(
app_path
)
do
generate_models_for_animals
output
=
rails
(
"db:migrate:status:
#{
namespace
}
"
)
if
namespace
==
"primary"
assert_match
(
/up \d+ Create books/
,
output
)
else
assert_match
(
/up \d+ Create dogs/
,
output
)
end
end
end
def
write_models_for_animals
# make a directory for the animals migration
FileUtils
.
mkdir_p
(
"
#{
app_path
}
/db/animals_migrate"
)
...
...
@@ -117,17 +135,22 @@ def write_models_for_animals
# create the base model for dog to inherit from
File
.
open
(
"
#{
app_path
}
/app/models/animals_base.rb"
,
"w"
)
do
|
file
|
file
.
write
(
<<
-
EOS
class AnimalsBase < ActiveRecord::Base
self.abstract_class = true
file
.
write
(
<<
~
EOS
)
class AnimalsBase < ActiveRecord::Base
self.abstract_class = true
establish_connection :animals
end
EOS
)
establish_connection :animals
end
EOS
end
end
def
generate_models_for_animals
rails
"generate"
,
"model"
,
"book"
,
"title:string"
rails
"generate"
,
"model"
,
"dog"
,
"name:string"
write_models_for_animals
end
test
"db:create and db:drop works on all databases for env"
do
require
"
#{
app_path
}
/config/environment"
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
).
each
do
|
db_config
|
...
...
@@ -144,22 +167,31 @@ class AnimalsBase < ActiveRecord::Base
test
"db:migrate and db:schema:dump and db:schema:load works on all databases"
do
require
"
#{
app_path
}
/config/environment"
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
).
each
do
|
db_config
|
db_migrate_and_schema_dump_and_load
db_config
.
spec_name
,
db_config
.
config
[
"database"
],
"schema"
end
db_migrate_and_schema_dump_and_load
"schema"
end
test
"db:migrate and db:structure:dump and db:structure:load works on all databases"
do
require
"
#{
app_path
}
/config/environment"
db_migrate_and_schema_dump_and_load
"structure"
end
test
"db:migrate:namespace works"
do
require
"
#{
app_path
}
/config/environment"
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
).
each
do
|
db_config
|
db_migrate_
and_schema_dump_and_load
db_config
.
spec_name
,
db_config
.
config
[
"database"
],
"structure"
db_migrate_
namespaced
db_config
.
spec_name
,
db_config
.
config
[
"database"
]
end
end
test
"db:migrate:namespace works"
do
test
"db:migrate:status works on all databases"
do
require
"
#{
app_path
}
/config/environment"
db_migrate_and_migrate_status
end
test
"db:migrate:status:namespace works"
do
require
"
#{
app_path
}
/config/environment"
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
).
each
do
|
db_config
|
db_migrate_namespaced
db_config
.
spec_name
,
db_config
.
config
[
"database"
]
db_migrate_status_namespaced
db_config
.
spec_name
,
db_config
.
config
[
"database"
]
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录