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
5af3eb5f
Commit
5af3eb5f
authored
Jul 04, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check foreign keys in migration in separate conditional
parent
6a615285
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
20170703102400_add_stage_id_foreign_key_to_builds.rb
...rate/20170703102400_add_stage_id_foreign_key_to_builds.rb
+15
-1
No files found.
db/migrate/20170703102400_add_stage_id_foreign_key_to_builds.rb
View file @
5af3eb5f
...
...
@@ -8,14 +8,28 @@ class AddStageIdForeignKeyToBuilds < ActiveRecord::Migration
def
up
unless
index_exists?
(
:ci_builds
,
:stage_id
)
add_concurrent_index
(
:ci_builds
,
:stage_id
)
end
unless
foreign_key_exists?
(
:ci_builds
,
:stage_id
)
add_concurrent_foreign_key
(
:ci_builds
,
:ci_stages
,
column: :stage_id
,
on_delete: :cascade
)
end
end
def
down
if
index
_exists?
(
:ci_builds
,
:stage_id
)
if
foreign_key
_exists?
(
:ci_builds
,
:stage_id
)
remove_foreign_key
(
:ci_builds
,
column: :stage_id
)
end
if
index_exists?
(
:ci_builds
,
:stage_id
)
remove_concurrent_index
(
:ci_builds
,
:stage_id
)
end
end
private
def
foreign_key_exists?
(
table
,
column
)
foreign_keys
(
:ci_builds
).
any?
do
|
key
|
key
.
options
[
:column
]
==
column
.
to_s
end
end
end
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