diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index 4f9a2e4456272c3039ea63ddfef494083ab1219f..5cd85fcf5eead224612943aafc5c90e78a09c007 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -8,9 +8,12 @@ class Stage < Ci::ApplicationRecord include Gitlab::OptimisticLocking include Presentable include SafelyChangeColumnDefault + include IgnorableColumns columns_changing_default :partition_id + ignore_column :pipeline_id_convert_to_bigint, remove_with: '16.6', remove_after: '2023-10-22' + partitionable scope: :pipeline enum status: Ci::HasStatus::STATUSES_ENUM diff --git a/db/migrate/20230717062425_initialize_conversion_of_ci_stages_pipeline_id.rb b/db/migrate/20230717062425_initialize_conversion_of_ci_stages_pipeline_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..70d6406bb675360ca6109b8272717353cdf3a65e --- /dev/null +++ b/db/migrate/20230717062425_initialize_conversion_of_ci_stages_pipeline_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiStagesPipelineId < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE = :ci_stages + COLUMNS = %i[pipeline_id] + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/post_migrate/20230717062445_backfill_ci_stages_pipeline_id_conversion.rb b/db/post_migrate/20230717062445_backfill_ci_stages_pipeline_id_conversion.rb new file mode 100644 index 0000000000000000000000000000000000000000..d93517fb49b01144d612e04d6a17e8e937f80531 --- /dev/null +++ b/db/post_migrate/20230717062445_backfill_ci_stages_pipeline_id_conversion.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class BackfillCiStagesPipelineIdConversion < Gitlab::Database::Migration[2.1] + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + TABLE = :ci_stages + COLUMNS = %i[pipeline_id] + SUB_BATCH_SIZE = 250 + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS, sub_batch_size: SUB_BATCH_SIZE) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/schema_migrations/20230717062425 b/db/schema_migrations/20230717062425 new file mode 100644 index 0000000000000000000000000000000000000000..735c10874e0a7d575976135f65207f8b1e21d907 --- /dev/null +++ b/db/schema_migrations/20230717062425 @@ -0,0 +1 @@ +5303be6b0da16a7b1fa64c1c99ef3809ee2f5c131daaf25e6073ffc4122fe8ec \ No newline at end of file diff --git a/db/schema_migrations/20230717062445 b/db/schema_migrations/20230717062445 new file mode 100644 index 0000000000000000000000000000000000000000..20b05fded65288dedc9dd79853a5626f1d3e786f --- /dev/null +++ b/db/schema_migrations/20230717062445 @@ -0,0 +1 @@ +cb600935d177a342f082bf896ffbc23f638fae2d124a89f7604b84c1e0ca9a2a \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 408d9d851aac7cfeccd7b4334a2d89f2c64a2baf..d6689c5669cb93fd63d3700f4bb2f21487c05a05 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -249,6 +249,15 @@ RETURN NULL; END $$; +CREATE FUNCTION trigger_07bc3c48f407() RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN + NEW."pipeline_id_convert_to_bigint" := NEW."pipeline_id"; + RETURN NEW; +END; +$$; + CREATE FUNCTION trigger_1a857e8db6cd() RETURNS trigger LANGUAGE plpgsql AS $$ @@ -14078,6 +14087,7 @@ CREATE TABLE ci_stages ( "position" integer, id bigint NOT NULL, partition_id bigint NOT NULL, + pipeline_id_convert_to_bigint bigint, CONSTRAINT check_81b431e49b CHECK ((lock_version IS NOT NULL)) ); @@ -35312,6 +35322,8 @@ CREATE TRIGGER push_rules_loose_fk_trigger AFTER DELETE ON push_rules REFERENCIN CREATE TRIGGER tags_loose_fk_trigger AFTER DELETE ON tags REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records(); +CREATE TRIGGER trigger_07bc3c48f407 BEFORE INSERT OR UPDATE ON ci_stages FOR EACH ROW EXECUTE FUNCTION trigger_07bc3c48f407(); + CREATE TRIGGER trigger_1a857e8db6cd BEFORE INSERT OR UPDATE ON vulnerability_occurrences FOR EACH ROW EXECUTE FUNCTION trigger_1a857e8db6cd(); CREATE TRIGGER trigger_7f3d66a7d7f5 BEFORE INSERT OR UPDATE ON ci_pipeline_variables FOR EACH ROW EXECUTE FUNCTION trigger_7f3d66a7d7f5();