Commit c789075c authored by dfrazao-gitlab's avatar dfrazao-gitlab

Address the PK Overflow risk for the ci_build_needs - Step 3

- Remove build_id_convert_to_bigint column
- Remove trigger_21e7a2602957 trigger

Related to https://gitlab.com/gitlab-org/gitlab/-/issues/338060

Changelog: added
parent c4553d30
# frozen_string_literal: true
class DropTemporaryColumnsAndTriggersForCiBuildNeeds < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
TABLE = 'ci_build_needs'
TEMPORARY_COLUMN = 'build_id_convert_to_bigint'
MAIN_COLUMN = 'build_id'
# rubocop:disable Migration/WithLockRetriesDisallowedMethod
def up
with_lock_retries do
cleanup_conversion_of_integer_to_bigint(TABLE, MAIN_COLUMN)
end
end
def down
check_trigger_permissions!(TABLE)
with_lock_retries do
add_column(TABLE, TEMPORARY_COLUMN, :int, default: 0, null: false)
install_rename_triggers(TABLE, MAIN_COLUMN, TEMPORARY_COLUMN)
end
end
# rubocop:enable Migration/WithLockRetriesDisallowedMethod
end
c99df310082dd6f5faff3cfd90dfca88af26d840889910ebac0e73ba483a09b2
\ No newline at end of file
......@@ -52,15 +52,6 @@ RETURN NULL;
END
$$;
CREATE FUNCTION trigger_21e7a2602957() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW."build_id_convert_to_bigint" := NEW."build_id";
RETURN NEW;
END;
$$;
CREATE FUNCTION trigger_3f6129be01d2() RETURNS trigger
LANGUAGE plpgsql
AS $$
......@@ -11224,7 +11215,6 @@ ALTER SEQUENCE chat_teams_id_seq OWNED BY chat_teams.id;
CREATE TABLE ci_build_needs (
id integer NOT NULL,
build_id_convert_to_bigint integer DEFAULT 0 NOT NULL,
name text NOT NULL,
artifacts boolean DEFAULT true NOT NULL,
optional boolean DEFAULT false NOT NULL,
......@@ -27285,8 +27275,6 @@ ALTER INDEX product_analytics_events_experimental_pkey ATTACH PARTITION gitlab_p
ALTER INDEX product_analytics_events_experimental_pkey ATTACH PARTITION gitlab_partitions_static.product_analytics_events_experimental_63_pkey;
CREATE TRIGGER trigger_21e7a2602957 BEFORE INSERT OR UPDATE ON ci_build_needs FOR EACH ROW EXECUTE FUNCTION trigger_21e7a2602957();
CREATE TRIGGER trigger_3f6129be01d2 BEFORE INSERT OR UPDATE ON ci_builds FOR EACH ROW EXECUTE FUNCTION trigger_3f6129be01d2();
CREATE TRIGGER trigger_542d6c2ad72e BEFORE INSERT OR UPDATE ON ci_builds_metadata FOR EACH ROW EXECUTE FUNCTION trigger_542d6c2ad72e();
# frozen_string_literal: true
require 'spec_helper'
require_migration!('drop_temporary_columns_and_triggers_for_ci_build_needs')
RSpec.describe DropTemporaryColumnsAndTriggersForCiBuildNeeds do
let(:ci_build_needs_table) { table(:ci_build_needs) }
it 'correctly migrates up and down' do
reversible_migration do |migration|
migration.before -> {
expect(ci_build_needs_table.column_names).to include('build_id_convert_to_bigint')
}
migration.after -> {
ci_build_needs_table.reset_column_information
expect(ci_build_needs_table.column_names).not_to include('build_id_convert_to_bigint')
}
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