Commit 21b2afdd authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ab/pk-conversion-cibuilds-satellites' into 'master'

Prepare to convert primary type for ci_build_needs table

See merge request gitlab-org/gitlab!59467
parents 1e9ea8b7 f89dbba3
......@@ -5,6 +5,9 @@ module Ci
extend Gitlab::Ci::Model
include BulkInsertSafe
include IgnorableColumns
ignore_columns :build_id_convert_to_bigint, remove_with: '14.1', remove_after: '2021-07-22'
belongs_to :build, class_name: "Ci::Processable", foreign_key: :build_id, inverse_of: :needs
......@@ -14,5 +17,12 @@ module Ci
scope :scoped_build, -> { where('ci_builds.id=ci_build_needs.build_id') }
scope :artifacts, -> { where(artifacts: true) }
# TODO: Remove once build_id_convert_to_bigint is not an "ignored" column anymore (see .ignore_columns above)
# There is a database-side trigger to populate this column. This is unexpected in the context
# of cloning an instance, e.g. when retrying the job. Hence we exclude the ignored column explicitly here.
def attributes
super.except('build_id_convert_to_bigint')
end
end
end
---
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