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
4fd3314c
Commit
4fd3314c
authored
Sep 05, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix prometheus_metric_id non-unique migration
parent
10593253
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
db/schema.rb
db/schema.rb
+2
-1
ee/db/migrate/20180831134049_allow_many_prometheus_alerts.rb
ee/db/migrate/20180831134049_allow_many_prometheus_alerts.rb
+28
-4
No files found.
db/schema.rb
View file @
4fd3314c
...
...
@@ -2270,7 +2270,8 @@ ActiveRecord::Schema.define(version: 20180831164910) do
end
add_index
"prometheus_alerts"
,
[
"environment_id"
],
name:
"index_prometheus_alerts_on_environment_id"
,
using: :btree
add_index
"prometheus_alerts"
,
[
"prometheus_metric_id"
],
name:
"index_prometheus_alerts_on_prometheus_metric_id"
,
unique:
true
,
using: :btree
add_index
"prometheus_alerts"
,
[
"project_id"
,
"prometheus_metric_id"
],
name:
"index_prometheus_alerts_on_project_id_and_prometheus_metric_id"
,
unique:
true
,
using: :btree
add_index
"prometheus_alerts"
,
[
"prometheus_metric_id"
],
name:
"index_prometheus_alerts_on_prometheus_metric_id_non_unique"
,
using: :btree
create_table
"prometheus_metrics"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
...
...
ee/db/migrate/20180831134049_allow_many_prometheus_alerts.rb
View file @
4fd3314c
...
...
@@ -5,13 +5,37 @@ class AllowManyPrometheusAlerts < ActiveRecord::Migration
disable_ddl_transaction!
# We mutate `:prometheus_metric_id` into non unique one,
# and convert it into project+prometheus_metric unique
def
up
add_concurrent_index
:prometheus_alerts
,
[
:project_id
,
:prometheus_metric_id
],
unique:
true
remove_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
unique:
true
rebuild_foreign_key
do
add_concurrent_index
:prometheus_alerts
,
[
:project_id
,
:prometheus_metric_id
],
unique:
true
add_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
name: :index_prometheus_alerts_on_prometheus_metric_id_non_unique
remove_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
unique:
true
end
end
def
down
add_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
unique:
true
remove_concurrent_index
:prometheus_alerts
,
[
:project_id
,
:prometheus_metric_id
],
unique:
true
rebuild_foreign_key
do
add_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
unique:
true
remove_concurrent_index
:prometheus_alerts
,
[
:project_id
,
:prometheus_metric_id
],
unique:
true
remove_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
name: :index_prometheus_alerts_on_prometheus_metric_id_non_unique
end
end
private
# 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
end
yield
if
Gitlab
::
Database
.
mysql?
add_concurrent_foreign_key
:prometheus_alerts
,
:prometheus_metrics
,
column: :prometheus_metric_id
,
on_delete: :cascade
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