Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fe0145c5
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 搜索 >>
提交
fe0145c5
编写于
4月 04, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Respect table name prefix/suffix for `truncate_all`
上级
9bccf460
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
67 addition
and
5 deletion
+67
-5
activerecord/lib/active_record/internal_metadata.rb
activerecord/lib/active_record/internal_metadata.rb
+5
-1
activerecord/lib/active_record/schema_migration.rb
activerecord/lib/active_record/schema_migration.rb
+1
-1
activerecord/lib/active_record/tasks/database_tasks.rb
activerecord/lib/active_record/tasks/database_tasks.rb
+2
-2
activerecord/test/cases/migration/foreign_key_test.rb
activerecord/test/cases/migration/foreign_key_test.rb
+1
-1
activerecord/test/cases/tasks/database_tasks_test.rb
activerecord/test/cases/tasks/database_tasks_test.rb
+58
-0
未找到文件。
activerecord/lib/active_record/internal_metadata.rb
浏览文件 @
fe0145c5
...
...
@@ -17,7 +17,7 @@ def primary_key
end
def
table_name
"
#{
table_name_prefix
}#{
ActiveRecord
::
Base
.
internal_metadata_table_name
}#{
table_name_suffix
}
"
"
#{
table_name_prefix
}#{
internal_metadata_table_name
}#{
table_name_suffix
}
"
end
def
[]=
(
key
,
value
)
...
...
@@ -44,6 +44,10 @@ def create_table
end
end
end
def
drop_table
connection
.
drop_table
table_name
,
if_exists:
true
end
end
end
end
activerecord/lib/active_record/schema_migration.rb
浏览文件 @
fe0145c5
...
...
@@ -19,7 +19,7 @@ def primary_key
end
def
table_name
"
#{
table_name_prefix
}#{
ActiveRecord
::
Base
.
schema_migrations_table_name
}#{
table_name_suffix
}
"
"
#{
table_name_prefix
}#{
schema_migrations_table_name
}#{
table_name_suffix
}
"
end
def
table_exists?
...
...
activerecord/lib/active_record/tasks/database_tasks.rb
浏览文件 @
fe0145c5
...
...
@@ -186,8 +186,8 @@ def truncate_tables(configuration)
ActiveRecord
::
Base
.
connected_to
(
database:
{
truncation:
configuration
})
do
table_names
=
ActiveRecord
::
Base
.
connection
.
tables
table_names
-=
[
ActiveRecord
::
Base
.
schema_migrations_
table_name
,
ActiveRecord
::
Base
.
internal_metadata_
table_name
SchemaMigration
.
table_name
,
InternalMetadata
.
table_name
]
ActiveRecord
::
Base
.
connection
.
truncate_tables
(
*
table_names
)
...
...
activerecord/test/cases/migration/foreign_key_test.rb
浏览文件 @
fe0145c5
...
...
@@ -155,7 +155,7 @@ class ForeignKeyChangeColumnWithPrefixTest < ForeignKeyChangeColumnTest
class
ForeignKeyChangeColumnWithSuffixTest
<
ForeignKeyChangeColumnTest
setup
do
ActiveRecord
::
Base
.
table_name_suffix
=
"_
p
"
ActiveRecord
::
Base
.
table_name_suffix
=
"_
s
"
end
teardown
do
...
...
activerecord/test/cases/tasks/database_tasks_test.rb
浏览文件 @
fe0145c5
...
...
@@ -50,6 +50,8 @@ def test_raises_an_error_when_called_with_protected_environment
protected_environments
=
ActiveRecord
::
Base
.
protected_environments
current_env
=
ActiveRecord
::
Base
.
connection
.
migration_context
.
current_environment
InternalMetadata
[
:environment
]
=
current_env
assert_called_on_instance_of
(
ActiveRecord
::
MigrationContext
,
:current_version
,
...
...
@@ -73,6 +75,9 @@ def test_raises_an_error_when_called_with_protected_environment
def
test_raises_an_error_when_called_with_protected_environment_which_name_is_a_symbol
protected_environments
=
ActiveRecord
::
Base
.
protected_environments
current_env
=
ActiveRecord
::
Base
.
connection
.
migration_context
.
current_environment
InternalMetadata
[
:environment
]
=
current_env
assert_called_on_instance_of
(
ActiveRecord
::
MigrationContext
,
:current_version
,
...
...
@@ -951,11 +956,22 @@ class DatabaseTasksTruncateAllTest < ActiveRecord::TestCase
fixtures
:authors
,
:author_addresses
def
setup
SchemaMigration
.
create_table
SchemaMigration
.
create!
(
version:
"foo"
)
InternalMetadata
.
create_table
InternalMetadata
.
create!
(
key:
"foo"
,
value:
"bar"
)
end
def
teardown
SchemaMigration
.
drop_table
InternalMetadata
.
drop_table
ActiveRecord
::
Base
.
connection_handlers
=
{
writing:
ActiveRecord
::
Base
.
default_connection_handler
}
end
def
test_truncate_tables
assert_operator
SchemaMigration
.
count
,
:
>
,
0
assert_operator
InternalMetadata
.
count
,
:
>
,
0
assert_operator
Author
.
count
,
:
>
,
0
assert_operator
AuthorAddress
.
count
,
:
>
,
0
...
...
@@ -969,12 +985,54 @@ def test_truncate_tables
)
end
assert_operator
SchemaMigration
.
count
,
:
>
,
0
assert_operator
InternalMetadata
.
count
,
:
>
,
0
assert_equal
0
,
Author
.
count
assert_equal
0
,
AuthorAddress
.
count
ensure
ActiveRecord
::
Base
.
configurations
=
old_configurations
end
end
class
DatabaseTasksTruncateAllWithPrefixTest
<
DatabaseTasksTruncateAllTest
setup
do
ActiveRecord
::
Base
.
table_name_prefix
=
"p_"
SchemaMigration
.
reset_table_name
SchemaMigration
.
reset_column_information
InternalMetadata
.
reset_table_name
InternalMetadata
.
reset_column_information
end
teardown
do
ActiveRecord
::
Base
.
table_name_prefix
=
nil
SchemaMigration
.
reset_table_name
SchemaMigration
.
reset_column_information
InternalMetadata
.
reset_table_name
InternalMetadata
.
reset_column_information
end
end
class
DatabaseTasksTruncateAllWithSuffixTest
<
DatabaseTasksTruncateAllTest
setup
do
ActiveRecord
::
Base
.
table_name_suffix
=
"_s"
SchemaMigration
.
reset_table_name
SchemaMigration
.
reset_column_information
InternalMetadata
.
reset_table_name
InternalMetadata
.
reset_column_information
end
teardown
do
ActiveRecord
::
Base
.
table_name_suffix
=
nil
SchemaMigration
.
reset_table_name
SchemaMigration
.
reset_column_information
InternalMetadata
.
reset_table_name
InternalMetadata
.
reset_column_information
end
end
end
class
DatabaseTasksTruncateAllWithMultipleDatabasesTest
<
ActiveRecord
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录