Commit b08838c6 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '214983-remove_additional_rows_in_application_settings' into 'master'

Add migration that deletes additional application_settings rows

Closes #214983

See merge request gitlab-org/gitlab!29981
parents 9f69b063 079d0c3d
---
title: Delete orphaned rows in application_settings table
merge_request: 29981
author:
type: performance
# frozen_string_literal: true
class RemoveAdditionalApplicationSettingsRows < ActiveRecord::Migration[6.0]
class ApplicationSetting < ActiveRecord::Base
self.table_name = 'application_settings'
end
def up
return if ApplicationSetting.count == 1
execute "DELETE from application_settings WHERE id NOT IN (SELECT MAX(id) FROM application_settings);"
end
def down
# no changes
end
end
...@@ -13421,6 +13421,7 @@ COPY "schema_migrations" (version) FROM STDIN; ...@@ -13421,6 +13421,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200416120128 20200416120128
20200416120354 20200416120354
20200417044453 20200417044453
20200420162730
20200420172113 20200420172113
20200420172752 20200420172752
20200420172927 20200420172927
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200420162730_remove_additional_application_settings_rows.rb')
describe RemoveAdditionalApplicationSettingsRows do
let(:application_settings) { table(:application_settings) }
it 'removes additional rows from application settings' do
3.times { application_settings.create! }
latest_settings = application_settings.create!
disable_migrations_output { migrate! }
expect(application_settings.count).to eq(1)
expect(application_settings.first).to eq(latest_settings)
end
it 'leaves only row in application_settings' do
latest_settings = application_settings.create!
disable_migrations_output { migrate! }
expect(application_settings.first).to eq(latest_settings)
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