Commit ddcbaece authored by Mikolaj Wawrzyniak's avatar Mikolaj Wawrzyniak Committed by Stan Hu

Remove temporary index at services on project_id

parent 2edc16b9
---
title: Remove temporary index at services on project_id
merge_request: 24263
author:
type: removed
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class ServicesRemoveTemporaryIndexOnProjectId < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'tmp_index_on_project_id_partial_with_prometheus_services'
PARTIAL_FILTER = "type = 'PrometheusService'"
disable_ddl_transaction!
def up
remove_concurrent_index :services, :project_id, where: PARTIAL_FILTER, name: INDEX_NAME
end
def down
add_concurrent_index :services, :project_id, where: PARTIAL_FILTER, name: INDEX_NAME
end
end
...@@ -3846,7 +3846,6 @@ ActiveRecord::Schema.define(version: 2020_02_06_111847) do ...@@ -3846,7 +3846,6 @@ ActiveRecord::Schema.define(version: 2020_02_06_111847) do
t.boolean "instance", default: false t.boolean "instance", default: false
t.index ["instance"], name: "index_services_on_instance" t.index ["instance"], name: "index_services_on_instance"
t.index ["project_id"], name: "index_services_on_project_id" t.index ["project_id"], name: "index_services_on_project_id"
t.index ["project_id"], name: "tmp_index_on_project_id_partial_with_prometheus_services", where: "((type)::text = 'PrometheusService'::text)"
t.index ["type"], name: "index_services_on_type" t.index ["type"], name: "index_services_on_type"
end end
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200203104214_services_remove_temporary_index_on_project_id.rb')
describe ServicesRemoveTemporaryIndexOnProjectId, :migration do
let(:migration_instance) { described_class.new }
it 'adds and removes temporary partial index in up and down methods' do
reversible_migration do |migration|
migration.before -> {
expect(migration_instance.index_exists?(:services, :project_id, name: described_class::INDEX_NAME)).to be true
}
migration.after -> {
expect(migration_instance.index_exists?(:services, :project_id, name: described_class::INDEX_NAME)).to be false
}
end
end
describe '#up' do
context 'index does not exist' do
it 'skips removal action' do
migrate!
expect { migrate! }.not_to change { migration_instance.index_exists?(:services, :project_id, name: described_class::INDEX_NAME) }
end
end
end
describe '#down' do
context 'index already exists' do
it 'skips creation of duplicated temporary partial index on project_id' do
schema_migrate_down!
expect { schema_migrate_down! }.not_to change { migration_instance.index_exists?(:services, :project_id, name: described_class::INDEX_NAME) }
end
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