Commit 7152f24c authored by Alper Akgun's avatar Alper Akgun Committed by Mayra Cabrera

Remove creations in gitlab_subscription_histories

In gitlab_subscription_histories table we don't track
gitlab_subscription creations anymore. This MR removes the existing
redundant rows in the gitlab.com database
parent c5ae48ac
# frozen_string_literal: true
class RemoveCreationsInGitlabSubscriptionHistories < ActiveRecord::Migration[5.2]
DOWNTIME = false
GITLAB_SUBSCRIPTION_CREATED = 0
def up
return unless Gitlab.com?
delete_sql = "DELETE FROM gitlab_subscription_histories WHERE change_type=#{GITLAB_SUBSCRIPTION_CREATED} RETURNING *"
records = execute(delete_sql)
logger = Gitlab::BackgroundMigration::Logger.build
records.to_a.each do |record|
logger.info record.as_json.merge(message: "gitlab_subscription_histories with change_type=0 was deleted")
end
end
def down
# There's no way to restore, and the data is useless
# all the data to be deleted in case needed https://gitlab.com/gitlab-org/gitlab/uploads/7409379b0ed658624f5d33202b5668a1/gitlab_subscription_histories_change_type_0.sql.txt
end
end
---
title: Remove "creations" in gitlab_subscription_histories on gitlab.com
merge_request: 22278
author:
type: other
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200113151354_remove_creations_in_gitlab_subscription_histories.rb')
describe RemoveCreationsInGitlabSubscriptionHistories, :migration do
GITLAB_SUBSCRIPTION_CREATED = 0
GITLAB_SUBSCRIPTION_UPDATED = 1
GITLAB_SUBSCRIPTION_DESTROYED = 2
let(:gitlab_subscriptions) { table(:gitlab_subscriptions) }
let(:gitlab_subscription_histories) { table(:gitlab_subscription_histories) }
it 'removes creations in gitlab_subscription_histories on gitlab.com' do
allow(Gitlab).to receive(:com?).and_return(true)
gitlab_subscription = gitlab_subscriptions.create!
gitlab_subscription_histories.create! change_type: GITLAB_SUBSCRIPTION_CREATED,
gitlab_subscription_id: gitlab_subscription.id
gitlab_subscription_histories.create! change_type: GITLAB_SUBSCRIPTION_UPDATED,
seats: 13,
gitlab_subscription_id: gitlab_subscription.id
gitlab_subscription_histories.create! change_type: GITLAB_SUBSCRIPTION_DESTROYED,
seats: 13,
gitlab_subscription_id: gitlab_subscription.id
expect { migrate! }.to change { gitlab_subscription_histories.count }.from(3).to(2)
expect(gitlab_subscription_histories.where(change_type: [GITLAB_SUBSCRIPTION_UPDATED,
GITLAB_SUBSCRIPTION_DESTROYED]).count) .to eq(2)
expect(gitlab_subscription_histories.where(change_type: GITLAB_SUBSCRIPTION_CREATED).count) .to eq(0)
end
it 'does not run if not on gitlab.com' do
allow(Gitlab).to receive(:com?).and_return(false)
gitlab_subscription = gitlab_subscriptions.create!
gitlab_subscription_histories.create! change_type: GITLAB_SUBSCRIPTION_CREATED,
gitlab_subscription_id: gitlab_subscription.id
expect { migrate! }.not_to change { gitlab_subscription_histories.count }
expect(gitlab_subscription_histories.count) .to eq(1)
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