Commit 51390ff9 authored by Andreas Brandl's avatar Andreas Brandl Committed by Heinrich Lee Yu

Prepare to convert PK type for ci_build_needs

parent a4650301
---
title: Prepare to convert PK type for ci_build_needs
merge_request: 59467
author:
type: other
# frozen_string_literal: true
class InitializeConversionOfCiBuildNeedsToBigint < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
def up
initialize_conversion_of_integer_to_bigint :ci_build_needs, :build_id
end
def down
trigger_name = rename_trigger_name(:ci_build_needs, :build_id, :build_id_convert_to_bigint)
remove_rename_triggers_for_postgresql :ci_build_needs, trigger_name
remove_column :ci_build_needs, :build_id_convert_to_bigint
end
end
# frozen_string_literal: true
class BackfillCiBuildNeedsForBigintConversion < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
return unless should_run?
backfill_conversion_of_integer_to_bigint :ci_build_needs, :build_id,
batch_size: 15000, sub_batch_size: 100
end
def down
return unless should_run?
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_build_needs', column_name: 'build_id')
.where('job_arguments = ?', %w[build_id build_id_convert_to_bigint].to_json)
.delete_all
end
private
def should_run?
Gitlab.dev_or_test_env? || Gitlab.com?
end
end
dd6474593b6f4dd82f7f4776f558a82fa34307c45e20f13f77807f7dc96db368
\ No newline at end of file
2ba1f8832a6ba4300796ff9f74dfa2d0ff7a648a9231db369274ad002d0e4ec8
\ No newline at end of file
......@@ -106,6 +106,15 @@ BEGIN
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_69523443cc10() RETURNS trigger
LANGUAGE plpgsql
AS $$
......@@ -10283,7 +10292,8 @@ CREATE TABLE ci_build_needs (
build_id integer NOT NULL,
name text NOT NULL,
artifacts boolean DEFAULT true NOT NULL,
optional boolean DEFAULT false NOT NULL
optional boolean DEFAULT false NOT NULL,
build_id_convert_to_bigint bigint DEFAULT 0 NOT NULL
);
CREATE SEQUENCE ci_build_needs_id_seq
......@@ -24713,6 +24723,8 @@ CREATE TRIGGER table_sync_trigger_b99eb6998c AFTER INSERT OR DELETE OR UPDATE ON
CREATE TRIGGER trigger_07c94931164e BEFORE INSERT OR UPDATE ON push_event_payloads FOR EACH ROW EXECUTE PROCEDURE trigger_07c94931164e();
CREATE TRIGGER trigger_21e7a2602957 BEFORE INSERT OR UPDATE ON ci_build_needs FOR EACH ROW EXECUTE PROCEDURE trigger_21e7a2602957();
CREATE TRIGGER trigger_69523443cc10 BEFORE INSERT OR UPDATE ON events FOR EACH ROW EXECUTE PROCEDURE trigger_69523443cc10();
CREATE TRIGGER trigger_8485e97c00e3 BEFORE INSERT OR UPDATE ON ci_sources_pipelines FOR EACH ROW EXECUTE PROCEDURE trigger_8485e97c00e3();
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