Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c4a7c315
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,发现更多精彩内容 >>
提交
c4a7c315
编写于
3月 17, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9762 from senny/8079_do_not_grant_on_root_user
`rake db:create` does not change permissions of root user.
上级
8744632f
274e966a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
3 deletion
+26
-3
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/tasks/mysql_database_tasks.rb
activerecord/lib/active_record/tasks/mysql_database_tasks.rb
+3
-1
activerecord/test/cases/tasks/mysql_rake_test.rb
activerecord/test/cases/tasks/mysql_rake_test.rb
+18
-2
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
c4a7c315
## Rails 4.0.0 (unreleased) ##
*
`rake db:create`
does not change permissions of the MySQL root user.
Fixes #8079.
*Yves Senn*
*
The length of the
`version`
column in the
`schema_migrations`
table
created by the
`mysql2`
adapter is 191 if the encoding is "utf8mb4".
...
...
activerecord/lib/active_record/tasks/mysql_database_tasks.rb
浏览文件 @
c4a7c315
...
...
@@ -26,7 +26,9 @@ def create
$stdout
.
print
error
.
error
establish_connection
root_configuration_without_database
connection
.
create_database
configuration
[
'database'
],
creation_options
connection
.
execute
grant_statement
.
gsub
(
/\s+/
,
' '
).
strip
if
configuration
[
'username'
]
!=
'root'
connection
.
execute
grant_statement
.
gsub
(
/\s+/
,
' '
).
strip
end
establish_connection
configuration
else
$stderr
.
puts
"Couldn't create database for
#{
configuration
.
inspect
}
,
#{
creation_options
.
inspect
}
"
...
...
activerecord/test/cases/tasks/mysql_rake_test.rb
浏览文件 @
c4a7c315
...
...
@@ -71,7 +71,7 @@ def setup
return
skip
(
"only tested on mysql"
)
end
@connection
=
stub
(
:create_database
=>
true
,
:execute
=>
true
)
@connection
=
stub
(
"Connection"
,
create_database:
true
)
@error
=
Mysql
::
Error
.
new
"Invalid permissions"
@configuration
=
{
'adapter'
=>
'mysql'
,
...
...
@@ -90,6 +90,7 @@ def setup
end
def
test_root_password_is_requested
assert_permissions_granted_for
"pat"
skip
"only if mysql is available"
unless
defined?
(
::
Mysql
)
$stdin
.
expects
(
:gets
).
returns
(
"secret
\n
"
)
...
...
@@ -97,6 +98,7 @@ def test_root_password_is_requested
end
def
test_connection_established_as_root
assert_permissions_granted_for
"pat"
ActiveRecord
::
Base
.
expects
(
:establish_connection
).
with
(
'adapter'
=>
'mysql'
,
'database'
=>
nil
,
...
...
@@ -108,6 +110,7 @@ def test_connection_established_as_root
end
def
test_database_created_by_root
assert_permissions_granted_for
"pat"
@connection
.
expects
(
:create_database
).
with
(
'my-app-db'
,
:charset
=>
'utf8'
,
:collation
=>
'utf8_unicode_ci'
)
...
...
@@ -115,12 +118,18 @@ def test_database_created_by_root
end
def
test_grant_privileges_for_normal_user
@connection
.
expects
(
:execute
).
with
(
"GRANT ALL PRIVILEGES ON my-app-db.* TO 'pat'@'localhost' IDENTIFIED BY 'wossname' WITH GRANT OPTION;"
)
assert_permissions_granted_for
"pat"
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
end
def
test_do_not_grant_privileges_for_root_user
@configuration
[
'username'
]
=
'root'
@configuration
[
'password'
]
=
''
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
end
def
test_connection_established_as_normal_user
assert_permissions_granted_for
"pat"
ActiveRecord
::
Base
.
expects
(
:establish_connection
).
returns
do
ActiveRecord
::
Base
.
expects
(
:establish_connection
).
with
(
'adapter'
=>
'mysql'
,
...
...
@@ -142,6 +151,13 @@ def test_sends_output_to_stderr_when_other_errors
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
end
private
def
assert_permissions_granted_for
(
db_user
)
db_name
=
@configuration
[
'database'
]
db_password
=
@configuration
[
'password'
]
@connection
.
expects
(
:execute
).
with
(
"GRANT ALL PRIVILEGES ON
#{
db_name
}
.* TO '
#{
db_user
}
'@'localhost' IDENTIFIED BY '
#{
db_password
}
' WITH GRANT OPTION;"
)
end
end
class
MySQLDBDropTest
<
ActiveRecord
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录