diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /db/migrate/20201027002551_migrate_services_to_http_integrations.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'db/migrate/20201027002551_migrate_services_to_http_integrations.rb')
-rw-r--r-- | db/migrate/20201027002551_migrate_services_to_http_integrations.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/db/migrate/20201027002551_migrate_services_to_http_integrations.rb b/db/migrate/20201027002551_migrate_services_to_http_integrations.rb new file mode 100644 index 00000000000..5fe05320862 --- /dev/null +++ b/db/migrate/20201027002551_migrate_services_to_http_integrations.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class MigrateServicesToHttpIntegrations < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + ALERT_SERVICE_TYPE = 'AlertsService' + SERVICE_NAMES_IDENTIFIER = { + name: 'HTTP endpoint', + identifier: 'legacy' + } + + class HttpIntegration < ActiveRecord::Base + self.table_name = 'alert_management_http_integrations' + end + + # For each Alerts service, + # Create the matching HttpIntegration + def up + HttpIntegration.reset_column_information + + sql = <<~SQL + SELECT * FROM services + JOIN alerts_service_data + ON (services.id = alerts_service_data.service_id) + WHERE type = '#{ALERT_SERVICE_TYPE}' + AND active = TRUE + SQL + + current_time = Time.current + + values = select_all(sql).map do |alerts_service| + { + project_id: alerts_service['project_id'], + name: SERVICE_NAMES_IDENTIFIER[:name], + endpoint_identifier: SERVICE_NAMES_IDENTIFIER[:identifier], + encrypted_token: alerts_service['encrypted_token'], + encrypted_token_iv: alerts_service['encrypted_token_iv'], + active: alerts_service['active'], + updated_at: current_time, + created_at: current_time + } + end + + HttpIntegration.insert_all(values) if values.present? + end + + def down + # no-op + end +end |