Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6b2be718
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,发现更多精彩内容 >>
提交
6b2be718
编写于
1月 20, 2015
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18597 from kamipo/add-if-exists-to-drop-table
Add an `:if_exists` option to `drop_table`
上级
04d1c371
48e99a45
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
29 addition
and
3 deletion
+29
-3
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+15
-0
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
..._record/connection_adapters/abstract/schema_statements.rb
+1
-1
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+1
-1
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
...ecord/connection_adapters/postgresql/schema_statements.rb
+1
-1
activerecord/test/cases/migration/change_schema_test.rb
activerecord/test/cases/migration/change_schema_test.rb
+11
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
6b2be718
*
Introduce the
`:if_exists`
option for
`drop_table`
.
Example:
drop_table(:posts, if_exists: true)
That would execute:
DROP TABLE IF EXISTS posts
If the table doesn't exist, `if_exists: false` (the default) raises an
exception whereas `if_exists: true` does nothing.
*Cody Cutrer*, *Stefan Kanev*, *Ryuta Kamizono*
*
Don't run SQL if attribute value is not changed for update_attribute method.
*Prathamesh Sonpatki*
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
浏览文件 @
6b2be718
...
...
@@ -380,7 +380,7 @@ def rename_table(table_name, new_name)
# it can be helpful to provide these in a migration's +change+ method so it can be reverted.
# In that case, +options+ and the block will be used by create_table.
def
drop_table
(
table_name
,
options
=
{})
execute
"DROP TABLE
#{
quote_table_name
(
table_name
)
}
"
execute
"DROP TABLE
#{
' IF EXISTS'
if
options
[
:if_exists
]
}
#{
quote_table_name
(
table_name
)
}
"
end
# Adds a new column to the named table.
...
...
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
6b2be718
...
...
@@ -502,7 +502,7 @@ def rename_table(table_name, new_name)
end
def
drop_table
(
table_name
,
options
=
{})
execute
"DROP
#{
' TEMPORARY'
if
options
[
:temporary
]
}
TABLE
#{
quote_table_name
(
table_name
)
}#{
' CASCADE'
if
options
[
:force
]
==
:cascade
}
"
execute
"DROP
#{
' TEMPORARY'
if
options
[
:temporary
]
}
TABLE
#{
' IF EXISTS'
if
options
[
:if_exists
]
}
#{
quote_table_name
(
table_name
)
}#{
' CASCADE'
if
options
[
:force
]
==
:cascade
}
"
end
def
rename_index
(
table_name
,
old_name
,
new_name
)
...
...
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
浏览文件 @
6b2be718
...
...
@@ -112,7 +112,7 @@ def table_exists?(name)
end
def
drop_table
(
table_name
,
options
=
{})
execute
"DROP TABLE
#{
quote_table_name
(
table_name
)
}#{
' CASCADE'
if
options
[
:force
]
==
:cascade
}
"
execute
"DROP TABLE
#{
' IF EXISTS'
if
options
[
:if_exists
]
}
#{
quote_table_name
(
table_name
)
}#{
' CASCADE'
if
options
[
:force
]
==
:cascade
}
"
end
# Returns true if schema exists.
...
...
activerecord/test/cases/migration/change_schema_test.rb
浏览文件 @
6b2be718
...
...
@@ -403,6 +403,17 @@ def test_column_exists_on_table_with_no_options_parameter_supplied
end
end
def
test_drop_table_if_exists
connection
.
create_table
(
:testings
)
assert
connection
.
table_exists?
(
:testings
)
connection
.
drop_table
(
:testings
,
if_exists:
true
)
assert_not
connection
.
table_exists?
(
:testings
)
end
def
test_drop_table_if_exists_nothing_raised
assert_nothing_raised
{
connection
.
drop_table
(
:nonexistent
,
if_exists:
true
)
}
end
private
def
testing_table_with_only_foo_attribute
connection
.
create_table
:testings
,
:id
=>
false
do
|
t
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录