Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
22ba159e
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 搜索 >>
提交
22ba159e
编写于
11月 10, 2014
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correctly dump `:options` on `create_table` for MySQL
上级
76836ef7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
106 addition
and
0 deletion
+106
-0
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
..._record/connection_adapters/abstract/schema_statements.rb
+4
-0
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+10
-0
activerecord/lib/active_record/schema_dumper.rb
activerecord/lib/active_record/schema_dumper.rb
+4
-0
activerecord/test/cases/adapters/mysql/table_options_test.rb
activerecord/test/cases/adapters/mysql/table_options_test.rb
+42
-0
activerecord/test/cases/adapters/mysql2/table_options_test.rb
...verecord/test/cases/adapters/mysql2/table_options_test.rb
+42
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
22ba159e
*
Correctly dump
`:options`
on
`create_table`
for MySQL.
*Ryuta Kamizono*
*
Make
`unscope`
aware of "less than" and "greater than" conditions.
*TAKAHASHI Kazuaki*
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
浏览文件 @
22ba159e
...
...
@@ -14,6 +14,10 @@ def native_database_types
{}
end
def
table_options
(
table_name
)
nil
end
# Truncates a table alias according to the limits of the current adapter.
def
table_alias_for
(
table_name
)
table_name
[
0
...
table_alias_length
].
tr
(
'.'
,
'_'
)
...
...
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
22ba159e
...
...
@@ -686,6 +686,16 @@ def foreign_keys(table_name)
end
end
def
table_options
(
table_name
)
create_table_info
=
select_one
(
"SHOW CREATE TABLE
#{
quote_table_name
(
table_name
)
}
"
)[
"Create Table"
]
# strip create_definitions and partition_options
raw_table_options
=
create_table_info
.
sub
(
/\A.*\n\) /m
,
''
).
sub
(
/\n\/\*!.*\*\/\n\z/m
,
''
).
strip
# strip AUTO_INCREMENT
raw_table_options
.
sub
(
/(ENGINE=\w+)(?: AUTO_INCREMENT=\d+)/
,
'\1'
)
end
# Maps logical Rails types to MySQL-specific data types.
def
type_to_sql
(
type
,
limit
=
nil
,
precision
=
nil
,
scale
=
nil
)
case
type
.
to_s
...
...
activerecord/lib/active_record/schema_dumper.rb
浏览文件 @
22ba159e
...
...
@@ -131,6 +131,10 @@ def table(table, stream)
tbl
.
print
", id: false"
end
tbl
.
print
", force: :cascade"
table_options
=
@connection
.
table_options
(
table
)
tbl
.
print
", options:
#{
table_options
.
inspect
}
"
unless
table_options
.
blank?
tbl
.
puts
" do |t|"
# then dump all non-primary key columns
...
...
activerecord/test/cases/adapters/mysql/table_options_test.rb
0 → 100644
浏览文件 @
22ba159e
require
"cases/helper"
require
'support/schema_dumping_helper'
class
MysqlTableOptionsTest
<
ActiveRecord
::
TestCase
include
SchemaDumpingHelper
def
setup
@connection
=
ActiveRecord
::
Base
.
connection
end
def
teardown
@connection
.
drop_table
"mysql_table_options"
,
if_exists:
true
end
test
"table options with ENGINE"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"ENGINE=MyISAM"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{ENGINE=MyISAM}
,
options
end
test
"table options with ROW_FORMAT"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"ROW_FORMAT=REDUNDANT"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{ROW_FORMAT=REDUNDANT}
,
options
end
test
"table options with CHARSET"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"CHARSET=utf8mb4"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{CHARSET=utf8mb4}
,
options
end
test
"table options with COLLATE"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"COLLATE=utf8mb4_bin"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{COLLATE=utf8mb4_bin}
,
options
end
end
activerecord/test/cases/adapters/mysql2/table_options_test.rb
0 → 100644
浏览文件 @
22ba159e
require
"cases/helper"
require
'support/schema_dumping_helper'
class
MysqlTableOptionsTest
<
ActiveRecord
::
TestCase
include
SchemaDumpingHelper
def
setup
@connection
=
ActiveRecord
::
Base
.
connection
end
def
teardown
@connection
.
drop_table
"mysql_table_options"
,
if_exists:
true
end
test
"table options with ENGINE"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"ENGINE=MyISAM"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{ENGINE=MyISAM}
,
options
end
test
"table options with ROW_FORMAT"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"ROW_FORMAT=REDUNDANT"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{ROW_FORMAT=REDUNDANT}
,
options
end
test
"table options with CHARSET"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"CHARSET=utf8mb4"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{CHARSET=utf8mb4}
,
options
end
test
"table options with COLLATE"
do
@connection
.
create_table
"mysql_table_options"
,
force:
true
,
options:
"COLLATE=utf8mb4_bin"
output
=
dump_table_schema
(
"mysql_table_options"
)
options
=
%r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}
.
match
(
output
)[
:options
]
assert_match
%r{COLLATE=utf8mb4_bin}
,
options
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录