Skip to content
Snippets Groups Projects
Commit c0d2f535 authored by Andy Schoenen's avatar Andy Schoenen :two:
Browse files

Merge branch '408881-remove-index' into 'master'

Remove tmp_index_issues_on_issue_type_and_id_only_incidents index

See merge request !121466



Merged-by: default avatarAndy Soiron <asoiron@gitlab.com>
Approved-by: default avatarAndy Soiron <asoiron@gitlab.com>
Approved-by: Terri Chu's avatarTerri Chu <tchu@gitlab.com>
Reviewed-by: default avatarAndy Soiron <asoiron@gitlab.com>
Reviewed-by: Terri Chu's avatarTerri Chu <tchu@gitlab.com>
Reviewed-by: default avatarMario Celi <mcelicalderon@gitlab.com>
Co-authored-by: default avatarMario Celi <mcelicalderon@gitlab.com>
parents 6e5983f6 0c6f0537
No related branches found
No related tags found
1 merge request!121466Remove tmp_index_issues_on_issue_type_and_id_only_incidents index
Pipeline #879391308 failed
# frozen_string_literal: true
class EnsureIncidentWorkItemTypeBackfillIsFinished < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
restrict_gitlab_migration gitlab_schema: :gitlab_main
MIGRATION = 'BackfillWorkItemTypeIdForIssues'
INCIDENT_ENUM_TYPE = 1
class MigrationWorkItemType < MigrationRecord
self.table_name = 'work_item_types'
end
def up
incident_work_item_type = MigrationWorkItemType.find_by(namespace_id: nil, base_type: INCIDENT_ENUM_TYPE)
if incident_work_item_type.blank?
say(
'Incident work item type not found. Make sure the work_item_types table is populated' \
'before running this migration'
)
return
end
ensure_batched_background_migration_is_finished(
job_class_name: MIGRATION,
table_name: :issues,
column_name: :id,
job_arguments: [INCIDENT_ENUM_TYPE, incident_work_item_type.id]
)
end
def down
# no-op
end
end
# frozen_string_literal: true
class RemoveTmpIndexIssuesOnIssueTypeAndIdOnlyIncidents < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
INDEX_NAME = 'tmp_index_issues_on_issue_type_and_id_only_incidents'
INCIDENT_ENUM_VALUE = 1
def up
remove_concurrent_index_by_name :issues, INDEX_NAME
end
def down
add_concurrent_index :issues, [:issue_type, :id], name: INDEX_NAME, where: "issue_type = #{INCIDENT_ENUM_VALUE}"
end
end
ef28d42bc0e59c42c6764f0859d36307bf4c6594d109fcfaabbb8ae5392ed563
\ No newline at end of file
efa846e74dcc14732fe78f8458e1d44bb12f3b97282c14e4a33c87eac561e032
\ No newline at end of file
......@@ -33183,8 +33183,6 @@ CREATE INDEX tmp_index_for_null_member_namespace_id ON members USING btree (memb
 
CREATE INDEX tmp_index_for_project_namespace_id_migration_on_routes ON routes USING btree (id) WHERE ((namespace_id IS NULL) AND ((source_type)::text = 'Project'::text));
 
CREATE INDEX tmp_index_issues_on_issue_type_and_id_only_incidents ON issues USING btree (issue_type, id) WHERE (issue_type = 1);
CREATE INDEX tmp_index_members_on_state ON members USING btree (state) WHERE (state = 2);
 
CREATE INDEX tmp_index_migrated_container_registries ON container_repositories USING btree (project_id) WHERE ((migration_state = 'import_done'::text) OR (created_at >= '2022-01-23 00:00:00'::timestamp without time zone));
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe EnsureIncidentWorkItemTypeBackfillIsFinished, :migration, feature_category: :team_planning do
include MigrationHelpers::WorkItemTypesHelper
let(:batched_migrations) { table(:batched_background_migrations) }
let(:work_item_types) { table(:work_item_types) }
let(:batch_failed_status) { 2 }
let!(:migration_class) { described_class::MIGRATION }
describe '#up', :redis do
it "doesn't fail if work item types don't exist on the DB" do
table(:work_item_types).delete_all
migrate!
# Since migration specs run outside of a transaction, we need to make
# sure we recreate default types since this spec deletes them all
reset_work_item_types
end
context 'when migration is missing' do
before do
batched_migrations.where(job_class_name: migration_class).delete_all
end
it 'warns migration not found' do
expect(Gitlab::AppLogger)
.to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
.once
migrate!
end
end
context 'with migration present' do
let!(:backfill_migration) do
type_id = work_item_types.find_by!(namespace_id: nil, base_type: described_class::INCIDENT_ENUM_TYPE).id
create_migration_with(status, described_class::INCIDENT_ENUM_TYPE, type_id)
end
context 'when migrations have finished' do
let(:status) { 3 } # finished enum value
it 'does not raise an error' do
expect { migrate! }.not_to raise_error
end
end
context 'with different migration statuses' do
using RSpec::Parameterized::TableSyntax
where(:status, :description) do
0 | 'paused'
1 | 'active'
4 | 'failed'
5 | 'finalizing'
end
with_them do
it 'finalizes the migration' do
expect do
migrate!
backfill_migration.reload
end.to change { backfill_migration.status }.from(status).to(3)
end
end
end
end
end
def create_migration_with(status, base_type, type_id)
migration = batched_migrations.create!(
job_class_name: migration_class,
table_name: :issues,
column_name: :id,
job_arguments: [base_type, type_id],
interval: 2.minutes,
min_value: 1,
max_value: 2,
batch_size: 1000,
sub_batch_size: 200,
gitlab_schema: :gitlab_main,
status: status
)
table(:batched_background_migration_jobs).create!(
batched_background_migration_id: migration.id,
status: batch_failed_status,
min_value: 1,
max_value: 10,
attempts: 2,
batch_size: 100,
sub_batch_size: 10
)
migration
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment