Commit e8d78b6f authored by Simon Tomlinson's avatar Simon Tomlinson

Finalize converting deployments to bigint

Ensure the `deployable_id` to `deployable_id_convert_to_bigint`
conversion is completed

Copy the index on (deployable_type, deployable_id)

Swap the columns

See https://gitlab.com/gitlab-org/gitlab/-/issues/334824

Changelog: other
parent 81410641
# frozen_string_literal: true
class FinalizeConvertDeploymentsBigint < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
TABLE_NAME = 'deployments'
COLUMN_NAME = 'deployable_id'
COLUMN_NAME_BIGINT = "#{COLUMN_NAME}_convert_to_bigint"
def up
ensure_batched_background_migration_is_finished(
job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
table_name: TABLE_NAME,
column_name: 'id',
job_arguments: [[COLUMN_NAME], [COLUMN_NAME_BIGINT]]
)
swap
end
def down
swap
end
def swap
old_index_name = 'index_deployments_on_deployable_type_and_deployable_id'
bigint_index_name = 'index_deployments_on_deployable_type_and_deployable_id_bigint'
add_concurrent_index TABLE_NAME, ['deployable_type', COLUMN_NAME_BIGINT], name: bigint_index_name
with_lock_retries(raise_on_exhaustion: true) do
# Swap columns
temp_name = "#{COLUMN_NAME}_tmp"
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(COLUMN_NAME)} TO #{quote_column_name(temp_name)}"
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(COLUMN_NAME_BIGINT)} TO #{quote_column_name(COLUMN_NAME)}"
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(COLUMN_NAME_BIGINT)}"
function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(COLUMN_NAME, COLUMN_NAME_BIGINT)
execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
execute "DROP INDEX #{old_index_name}"
rename_index TABLE_NAME, bigint_index_name, old_index_name
end
end
end
a686e5df8b1528fa4d8d1c7b65b234837443d0cc249d08a38694f83263bb0532
\ No newline at end of file
...@@ -12414,7 +12414,7 @@ CREATE TABLE deployments ( ...@@ -12414,7 +12414,7 @@ CREATE TABLE deployments (
tag boolean NOT NULL, tag boolean NOT NULL,
sha character varying NOT NULL, sha character varying NOT NULL,
user_id integer, user_id integer,
deployable_id integer, deployable_id_convert_to_bigint integer,
deployable_type character varying, deployable_type character varying,
created_at timestamp without time zone, created_at timestamp without time zone,
updated_at timestamp without time zone, updated_at timestamp without time zone,
...@@ -12422,7 +12422,7 @@ CREATE TABLE deployments ( ...@@ -12422,7 +12422,7 @@ CREATE TABLE deployments (
status smallint NOT NULL, status smallint NOT NULL,
finished_at timestamp with time zone, finished_at timestamp with time zone,
cluster_id integer, cluster_id integer,
deployable_id_convert_to_bigint bigint deployable_id bigint
); );
CREATE SEQUENCE deployments_id_seq CREATE SEQUENCE deployments_id_seq
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