Commit 1a21f2c6 authored by Sean Arnold's avatar Sean Arnold

Add down method for migration

- Add specs
- update! -> update
parent 0dba4721
......@@ -30,7 +30,7 @@ module AlertManagement
end
def update_integration_data(http_integration)
http_integration.update!(
http_integration.update(
active: alert_service.active,
encrypted_token: alert_service.data.encrypted_token,
encrypted_token_iv: alert_service.data.encrypted_token_iv
......
......@@ -42,6 +42,15 @@ class MigrateServicesToHttpIntegrations < ActiveRecord::Migration[6.0]
end
def down
# NO-OP
sql = <<~SQL
SELECT project_id FROM services
WHERE type = '#{ALERT_SERVICE_TYPE}'
SQL
select_values(sql).each do |project_id|
HttpIntegration
.where(project_id: project_id, endpoint_identifier: SERVICE_NAMES_IDENTIFIER[:identifier])
.delete_all
end
end
end
......@@ -4,11 +4,10 @@ require 'spec_helper'
require Rails.root.join('db', 'migrate', '20201027002551_migrate_services_to_http_integrations.rb')
RSpec.describe MigrateServicesToHttpIntegrations do
let_it_be(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') }
let_it_be(:project) { table(:projects).create!(id: 1, namespace_id: namespace.id) }
let_it_be(:alert_service) { table(:services).create(type: 'AlertsService', project_id: project.id)}
let_it_be(:alert_service_data) { table(:alerts_service_data).create(service_id: alert_service.id, encrypted_token: 'test', encrypted_token_iv: 'test')}
let!(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') }
let!(:project) { table(:projects).create!(id: 1, namespace_id: namespace.id) }
let!(:alert_service) { table(:services).create!(type: 'AlertsService', project_id: project.id) }
let!(:alert_service_data) { table(:alerts_service_data).create!(service_id: alert_service.id, encrypted_token: 'test', encrypted_token_iv: 'test')}
let(:http_integrations) { table(:alert_management_http_integrations) }
describe '#up' do
......@@ -24,4 +23,20 @@ RSpec.describe MigrateServicesToHttpIntegrations do
expect(http_integration.endpoint_identifier).to eq(described_class::SERVICE_NAMES_IDENTIFIER[:identifier])
end
end
describe '#down' do
before do
http_integrations.create!(
project_id: project.id,
name: described_class::SERVICE_NAMES_IDENTIFIER[:name],
endpoint_identifier: described_class::SERVICE_NAMES_IDENTIFIER[:identifier],
encrypted_token: 'test',
encrypted_token_iv: 'test'
)
end
it 'removes the existing http integrations' do
expect { described_class.new.down }.to change { http_integrations.count }.from(1).to(0)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment