Skip to content
代码片段 群组 项目
未验证 提交 465e1f24 编辑于 作者: Aakriti Gupta's avatar Aakriti Gupta
浏览文件

Finalize conversion of geo_event_id to bigint

上级 1c0e82d4
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
class FinalizeBigintConversionOfGeoEventId < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::ConvertToBigint
disable_ddl_transaction!
milestone '16.9'
restrict_gitlab_migration gitlab_schema: :gitlab_main
TABLE_NAME = 'geo_event_log'
COLUMN_NAME = 'geo_event_id'
BIGINT_COLUMN_NAME = 'geo_event_id_convert_to_bigint'
def up
ensure_batched_background_migration_is_finished(
job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
table_name: TABLE_NAME,
column_name: COLUMN_NAME,
job_arguments: [[COLUMN_NAME], [BIGINT_COLUMN_NAME]]
)
end
def down
# no-op
end
end
# frozen_string_literal: true
class SwapBigintGeoEventId < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::ConvertToBigint
milestone '16.9'
disable_ddl_transaction!
TABLE_NAME = 'geo_event_log'
COLUMN_NAME = 'geo_event_id'
INDEX_NAME = 'index_geo_event_log_on_geo_event_id'
BIGINT_COLUMN_NAME = 'geo_event_id_convert_to_bigint'
# For the FK from 'geo_event_log' table referencing 'geo_events'
FK_SOURCE_TABLE_NAME = 'geo_events'
FK_NAME = 'fk_geo_event_log_on_geo_event_id'
TEMP_FK_NAME = 'fk_geo_event_id_convert_to_bigint'
def up
swap
end
def down
swap
end
def swap
add_bigint_column_indexes TABLE_NAME, COLUMN_NAME
unless foreign_key_exists?(TABLE_NAME, name: TEMP_FK_NAME)
add_concurrent_foreign_key TABLE_NAME, FK_SOURCE_TABLE_NAME,
name: TEMP_FK_NAME,
on_delete: :cascade,
column: BIGINT_COLUMN_NAME
end
with_lock_retries(raise_on_exhaustion: true) do
# Lock the table to avoid deadlocks
execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
# Swap the column names
temp_name = quote_column_name('id_tmp')
id_name = quote_column_name(COLUMN_NAME)
id_convert_to_bigint_name = quote_column_name(BIGINT_COLUMN_NAME)
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_name} TO #{temp_name}"
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_convert_to_bigint_name} TO #{id_name}"
execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{id_convert_to_bigint_name}"
# Reset the trigger function
function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(
TABLE_NAME, connection: connection).name(
COLUMN_NAME,
BIGINT_COLUMN_NAME
)
execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
end
# Rename the temporary FK
execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT #{FK_NAME} CASCADE"
rename_constraint TABLE_NAME, TEMP_FK_NAME, FK_NAME
# Rename index
execute "DROP INDEX CONCURRENTLY #{INDEX_NAME}"
rename_index TABLE_NAME, bigint_index_name(INDEX_NAME), INDEX_NAME
end
end
16c4e020edd4300dc246ccb8b2f101de8e9c8767dfae918659940e461776d598
\ No newline at end of file
b2d951df7d6f27ef267984f233e30e9263b3db5de0107f914e5999738b81cb87
\ No newline at end of file
...@@ -17347,8 +17347,8 @@ CREATE TABLE geo_event_log ( ...@@ -17347,8 +17347,8 @@ CREATE TABLE geo_event_log (
hashed_storage_attachments_event_id bigint, hashed_storage_attachments_event_id bigint,
reset_checksum_event_id bigint, reset_checksum_event_id bigint,
cache_invalidation_event_id bigint, cache_invalidation_event_id bigint,
geo_event_id integer, geo_event_id_convert_to_bigint integer,
geo_event_id_convert_to_bigint bigint geo_event_id bigint
); );
   
CREATE SEQUENCE geo_event_log_id_seq CREATE SEQUENCE geo_event_log_id_seq
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册