Commit 95e6cb93 authored by Marius Bobin's avatar Marius Bobin

Remove JenkinsDeprecatedService records from DB

This migration is executed twice to make sure that no new records
are created before the code is promoted to prod from canary.
parent d48c5fe2
# frozen_string_literal: true
class RemoveDeprecatedJenkinsServiceRecords < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
execute <<~SQL.strip
DELETE FROM services WHERE type = 'JenkinsDeprecatedService';
SQL
end
def down
# no-op
# The records were removed by `up`
end
end
# frozen_string_literal: true
class EnsureDeprecatedJenkinsServiceRecordsRemoval < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
execute <<~SQL.strip
DELETE FROM services WHERE type = 'JenkinsDeprecatedService';
SQL
end
def down
# no-op
# The records were removed by `up`
end
end
......@@ -13791,6 +13791,8 @@ COPY "schema_migrations" (version) FROM STDIN;
20200511121549
20200511121610
20200511121620
20200511130129
20200511130130
20200511145545
20200511162057
20200511162115
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20200511130129_remove_deprecated_jenkins_service_records.rb')
require Rails.root.join('db', 'post_migrate', '20200511130130_ensure_deprecated_jenkins_service_records_removal.rb')
shared_examples 'remove DeprecatedJenkinsService records' do
let(:services) { table(:services) }
before do
services.create!(type: 'JenkinsDeprecatedService')
services.create!(type: 'JenkinsService')
end
it 'deletes services when template and attached to a project' do
expect { migrate! }
.to change { services.where(type: 'JenkinsDeprecatedService').count }.from(1).to(0)
.and not_change { services.where(type: 'JenkinsService').count }
end
end
describe RemoveDeprecatedJenkinsServiceRecords, :migration do
it_behaves_like 'remove DeprecatedJenkinsService records'
end
describe EnsureDeprecatedJenkinsServiceRecordsRemoval, :migration do
it_behaves_like 'remove DeprecatedJenkinsService records'
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