Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
35a3e918
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
35a3e918
编写于
12月 14, 2016
作者:
N
Nick Thomas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make the index on environment name and project id unique, fixing up any duplicates
上级
2d1dfae9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
3 deletion
+74
-3
db/migrate/20161207231620_fixup_environment_name_uniqueness.rb
...grate/20161207231620_fixup_environment_name_uniqueness.rb
+53
-0
db/migrate/20161207231621_create_environment_name_unique_index.rb
...te/20161207231621_create_environment_name_unique_index.rb
+18
-0
db/schema.rb
db/schema.rb
+3
-3
未找到文件。
db/migrate/20161207231620_fixup_environment_name_uniqueness.rb
0 → 100644
浏览文件 @
35a3e918
class
FixupEnvironmentNameUniqueness
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
true
DOWNTIME_REASON
=
'Renaming non-unique environments'
def
up
environments
=
Arel
::
Table
.
new
(
:environments
)
# Get all [project_id, name] pairs that occur more than once
finder_sql
=
environments
.
group
(
environments
[
:project_id
],
environments
[
:name
]).
having
(
Arel
.
sql
(
"COUNT(1)"
).
gt
(
1
)).
project
(
environments
[
:project_id
],
environments
[
:name
]).
to_sql
conflicting
=
connection
.
exec_query
(
finder_sql
)
conflicting
.
rows
.
each
do
|
project_id
,
name
|
fix_duplicates
(
project_id
,
name
)
end
end
def
down
# Nothing to do
end
# Rename conflicting environments by appending "-#{id}" to all but the first
def
fix_duplicates
(
project_id
,
name
)
environments
=
Arel
::
Table
.
new
(
:environments
)
finder_sql
=
environments
.
where
(
environments
[
:project_id
].
eq
(
project_id
)).
where
(
environments
[
:name
].
eq
(
name
)).
order
(
environments
[
:id
].
asc
).
project
(
environments
[
:id
],
environments
[
:name
]).
to_sql
# Now we have the data for all the conflicting rows
conflicts
=
connection
.
exec_query
(
finder_sql
).
rows
conflicts
.
shift
# Leave the first row alone
conflicts
.
each
do
|
id
,
name
|
update_sql
=
Arel
::
UpdateManager
.
new
(
ActiveRecord
::
Base
).
table
(
environments
).
set
(
environments
[
:name
]
=>
name
+
"-"
+
id
.
to_s
).
where
(
environments
[
:id
].
eq
(
id
)).
to_sql
connection
.
exec_update
(
update_sql
,
self
.
class
.
name
,
[])
end
end
end
db/migrate/20161207231621_create_environment_name_unique_index.rb
0 → 100644
浏览文件 @
35a3e918
class
CreateEnvironmentNameUniqueIndex
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
DOWNTIME
=
true
DOWNTIME_REASON
=
'Making a non-unique index into a unique index'
def
up
remove_index
:environments
,
[
:project_id
,
:name
]
add_concurrent_index
:environments
,
[
:project_id
,
:name
],
unique:
true
end
def
down
remove_index
:environments
,
[
:project_id
,
:name
],
unique:
true
add_concurrent_index
:environments
,
[
:project_id
,
:name
]
end
end
db/schema.rb
浏览文件 @
35a3e918
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201612
12142807
)
do
ActiveRecord
::
Schema
.
define
(
version:
201612
07231621
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -430,7 +430,7 @@ ActiveRecord::Schema.define(version: 20161212142807) do
t
.
string
"state"
,
default:
"available"
,
null:
false
end
add_index
"environments"
,
[
"project_id"
,
"name"
],
name:
"index_environments_on_project_id_and_name"
,
using: :btree
add_index
"environments"
,
[
"project_id"
,
"name"
],
name:
"index_environments_on_project_id_and_name"
,
u
nique:
true
,
u
sing: :btree
create_table
"events"
,
force: :cascade
do
|
t
|
t
.
string
"target_type"
...
...
@@ -1290,4 +1290,4 @@ ActiveRecord::Schema.define(version: 20161212142807) do
add_foreign_key
"subscriptions"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"trending_projects"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"u2f_registrations"
,
"users"
end
\ No newline at end of file
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录