Commit 5358e822 authored by Patrick Bair's avatar Patrick Bair

Merge branch...

Merge branch '338060-address-the-primary-key-overflow-risk-for-the-ci_build_needs-table-step-3-drop-temporary' into 'master'

Resolve "Address the Primary Key Overflow risk for the ci_build_needs table - Step 3: Drop temporary columns and triggers"

See merge request gitlab-org/gitlab!69473
parents 48edefee c789075c
# 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
...@@ -64,15 +64,6 @@ RETURN NULL; ...@@ -64,15 +64,6 @@ RETURN NULL;
END 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 CREATE FUNCTION trigger_3f6129be01d2() RETURNS trigger
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
...@@ -11227,7 +11218,6 @@ ALTER SEQUENCE chat_teams_id_seq OWNED BY chat_teams.id; ...@@ -11227,7 +11218,6 @@ ALTER SEQUENCE chat_teams_id_seq OWNED BY chat_teams.id;
CREATE TABLE ci_build_needs ( CREATE TABLE ci_build_needs (
id integer NOT NULL, id integer NOT NULL,
build_id_convert_to_bigint integer DEFAULT 0 NOT NULL,
name text NOT NULL, name text NOT NULL,
artifacts boolean DEFAULT true NOT NULL, artifacts boolean DEFAULT true NOT NULL,
optional boolean DEFAULT false NOT NULL, optional boolean DEFAULT false NOT NULL,
...@@ -27321,8 +27311,6 @@ ALTER INDEX product_analytics_events_experimental_pkey ATTACH PARTITION gitlab_p ...@@ -27321,8 +27311,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; 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_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(); 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