Commit 46a91af8 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '218526_backstage_remove_gitlab_issue_tracker_service_records' into 'master'

Remove GitlabIssueTrackerService records

See merge request gitlab-org/gitlab!35221
parents c3ea51fb 82bc7b93
---
title: Clean up GitlabIssueTrackerService database records
merge_request: 35221
author:
type: other
# frozen_string_literal: true
class RemoveGitlabIssueTrackerServiceRecords < ActiveRecord::Migration[6.0]
DOWNTIME = false
BATCH_SIZE = 5000
disable_ddl_transaction!
class Service < ActiveRecord::Base
include EachBatch
self.table_name = 'services'
def self.gitlab_issue_tracker_service
where(type: 'GitlabIssueTrackerService')
end
end
def up
Service.each_batch(of: BATCH_SIZE) do |services|
services.gitlab_issue_tracker_service.delete_all
end
end
def down
# no-op
end
end
......@@ -23812,6 +23812,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200623121135
20200623141217
20200623141544
20200623142159
20200623170000
20200623185440
20200624075411
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200623142159_remove_gitlab_issue_tracker_service_records.rb')
RSpec.describe RemoveGitlabIssueTrackerServiceRecords do
let(:services) { table(:services) }
before do
5.times { services.create!(type: 'GitlabIssueTrackerService') }
services.create!(type: 'SomeOtherType')
end
it 'removes services records of type GitlabIssueTrackerService', :aggregate_failures do
expect { migrate! }.to change { services.count }.from(6).to(1)
expect(services.first.type).to eq('SomeOtherType')
expect(services.where(type: 'GitlabIssueTrackerService')).to be_empty
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