Commit d1d6eae4 authored by Stan Hu's avatar Stan Hu

Merge branch '196858-cleanup-temporary-index-at-services-table-on-project_id' into 'master'

Cleanup temporary index at services table on project_id

Closes #196858

See merge request gitlab-org/gitlab!24263
parents 29f4d3f2 ddcbaece
---
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
t.boolean "instance", default: false
t.index ["instance"], name: "index_services_on_instance"
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"
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