BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
2a345b07
Commit
2a345b07
authored
Aug 03, 2017
by
Stan Hu
Committed by
James Edwards-Jones
Aug 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'project-foreign-keys-without-errors' into 'master'
Change project FK migration to skip existing FKs Closes #35243 See merge request !13235
parent
251b2a8c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
+30
-8
project-foreign-keys-without-errors.yml
...gelogs/unreleased/project-foreign-keys-without-errors.yml
+4
-0
20170530130129_project_foreign_keys_with_cascading_deletes.rb
...0530130129_project_foreign_keys_with_cascading_deletes.rb
+26
-8
No files found.
changelogs/unreleased/project-foreign-keys-without-errors.yml
0 → 100644
View file @
2a345b07
---
title
:
Change project FK migration to skip existing FKs
merge_request
:
author
:
db/migrate/20170530130129_project_foreign_keys_with_cascading_deletes.rb
View file @
2a345b07
...
...
@@ -62,8 +62,8 @@ class ProjectForeignKeysWithCascadingDeletes < ActiveRecord::Migration
# These columns are not indexed yet, meaning a cascading delete would take
# forever.
add_
concurrent_index
(
:project_group_links
,
:project_id
)
add_
concurrent_index
(
:pages_domains
,
:project_id
)
add_
index_if_not_exists
(
:project_group_links
,
:project_id
)
add_
index_if_not_exists
(
:pages_domains
,
:project_id
)
end
def
down
...
...
@@ -71,15 +71,15 @@ class ProjectForeignKeysWithCascadingDeletes < ActiveRecord::Migration
remove_foreign_key_without_error
(
source
,
column
)
end
add_
concurrent_foreign_key
(
:boards
,
:projects
,
column: :project_id
)
add_
concurrent_foreign_key
(
:lists
,
:labels
,
column: :label_id
)
add_
concurrent_foreign_key
(
:lists
,
:boards
,
column: :board_id
)
add_
foreign_key_if_not_exists
(
:boards
,
:projects
,
column: :project_id
)
add_
foreign_key_if_not_exists
(
:lists
,
:labels
,
column: :label_id
)
add_
foreign_key_if_not_exists
(
:lists
,
:boards
,
column: :board_id
)
add_
concurrent_foreign_key
(
:protected_branch_merge_access_levels
,
add_
foreign_key_if_not_exists
(
:protected_branch_merge_access_levels
,
:protected_branches
,
column: :protected_branch_id
)
add_
concurrent_foreign_key
(
:protected_branch_push_access_levels
,
add_
foreign_key_if_not_exists
(
:protected_branch_push_access_levels
,
:protected_branches
,
column: :protected_branch_id
)
...
...
@@ -89,7 +89,7 @@ class ProjectForeignKeysWithCascadingDeletes < ActiveRecord::Migration
def
add_foreign_keys
TABLES
.
each
do
|
(
source
,
target
,
column
)
|
add_
concurrent_foreign_key
(
source
,
target
,
column:
column
)
add_
foreign_key_if_not_exists
(
source
,
target
,
column:
column
)
end
end
...
...
@@ -153,6 +153,18 @@ class ProjectForeignKeysWithCascadingDeletes < ActiveRecord::Migration
EOF
end
def
add_foreign_key_if_not_exists
(
source
,
target
,
column
:)
return
if
foreign_key_exists?
(
source
,
column
)
add_concurrent_foreign_key
(
source
,
target
,
column:
column
)
end
def
add_index_if_not_exists
(
table
,
column
)
return
if
index_exists?
(
table
,
column
)
add_concurrent_index
(
table
,
column
)
end
def
remove_foreign_key_without_error
(
table
,
column
)
remove_foreign_key
(
table
,
column:
column
)
rescue
ArgumentError
...
...
@@ -163,6 +175,12 @@ class ProjectForeignKeysWithCascadingDeletes < ActiveRecord::Migration
rescue
ArgumentError
end
def
foreign_key_exists?
(
table
,
column
)
foreign_keys
(
table
).
any?
do
|
key
|
key
.
options
[
:column
]
==
column
.
to_s
end
end
def
connection
# Rails memoizes connection objects, but this causes them to be shared
# amongst threads; we don't want that.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment