Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
043920bb
Commit
043920bb
authored
Mar 01, 2019
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rebuild foreign keys for MySQL to fix broken master
MySQL requires to drop FK for time of re-adding index
parent
3f02e805
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
17 deletions
+38
-17
ee/db/migrate/20180912113336_allow_prometheus_alerts_per_environment.rb
...20180912113336_allow_prometheus_alerts_per_environment.rb
+38
-17
No files found.
ee/db/migrate/20180912113336_allow_prometheus_alerts_per_environment.rb
View file @
043920bb
# frozen_string_literal: true
# frozen_string_literal: true
class
AllowPrometheusAlertsPerEnvironment
<
ActiveRecord
::
Migration
class
AllowPrometheusAlertsPerEnvironment
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
...
@@ -9,6 +9,7 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
...
@@ -9,6 +9,7 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
rebuild_foreign_key
do
# Before we create the new index we need to remove it to deal with possible
# Before we create the new index we need to remove it to deal with possible
# failures from previous migration.
# failures from previous migration.
#
#
...
@@ -20,10 +21,12 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
...
@@ -20,10 +21,12 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
remove_concurrent_index
:prometheus_alerts
,
old_columns
remove_concurrent_index
:prometheus_alerts
,
old_columns
end
end
end
def
down
def
down
delete_duplicate_alerts!
delete_duplicate_alerts!
rebuild_foreign_key
do
# Before we create the new index we need to remove it to deal with possible
# Before we create the new index we need to remove it to deal with possible
# failures from previous migration.
# failures from previous migration.
#
#
...
@@ -35,6 +38,7 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
...
@@ -35,6 +38,7 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
remove_concurrent_index
:prometheus_alerts
,
new_columns
,
remove_concurrent_index
:prometheus_alerts
,
new_columns
,
name:
INDEX_METRIC_ENVIRONMENT_NAME
name:
INDEX_METRIC_ENVIRONMENT_NAME
end
end
end
private
private
...
@@ -58,6 +62,23 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
...
@@ -58,6 +62,23 @@ class AllowPrometheusAlertsPerEnvironment < ActiveRecord::Migration
end
end
end
end
# MySQL requires to drop FK for time of re-adding index
def
rebuild_foreign_key
if
Gitlab
::
Database
.
mysql?
remove_foreign_key_without_error
:prometheus_alerts
,
:prometheus_metrics
remove_foreign_key_without_error
:prometheus_alerts
,
:projects
end
yield
if
Gitlab
::
Database
.
mysql?
add_concurrent_foreign_key
:prometheus_alerts
,
:prometheus_metrics
,
column: :prometheus_metric_id
,
on_delete: :cascade
add_concurrent_foreign_key
:prometheus_alerts
,
:projects
,
column: :project_id
,
on_delete: :cascade
end
end
def
new_columns
def
new_columns
[
:project_id
,
:prometheus_metric_id
,
:environment_id
]
[
:project_id
,
:prometheus_metric_id
,
:environment_id
]
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