1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# frozen_string_literal: true
# Migrate Integrations::Prometheus records to 'alert_management_http_integrations',
# corresponding to Metrics Dashboard removal in 16.0.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/338838 for more details.
class BackfillAlertManagementPrometheusIntegrations < Gitlab::Database::Migration[2.1]
restrict_gitlab_migration gitlab_schema: :gitlab_main
disable_ddl_transaction!
BATCH_SIZE = 10
def up
each_batch_range(:project_alerting_settings, of: BATCH_SIZE) do |min, max|
execute <<~SQL
INSERT INTO alert_management_http_integrations (
project_id,
encrypted_token,
encrypted_token_iv,
active,
name,
endpoint_identifier,
type_identifier,
created_at,
updated_at
) SELECT
project_alerting_settings.project_id,
project_alerting_settings.encrypted_token,
project_alerting_settings.encrypted_token_iv,
COALESCE(integrations.active, FALSE),
'Prometheus',
'legacy-prometheus',
1, --type_identifiers { http: 0, prometheus: 1 }
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
FROM project_alerting_settings
LEFT JOIN integrations
ON project_alerting_settings.project_id = integrations.project_id
AND integrations.type_new = 'Integrations::Prometheus'
WHERE project_alerting_settings.project_id BETWEEN #{min} AND #{max}
ON CONFLICT DO NOTHING
SQL
end
end
def down
execute <<~SQL
DELETE FROM alert_management_http_integrations
WHERE type_identifier = 1 --type_identifiers { http: 0, prometheus: 1 }
AND endpoint_identifier = 'legacy-prometheus'
SQL
end
end
|