Commit 0b857c7e authored by Krasimir Angelov's avatar Krasimir Angelov

Update rename trigger when swapping column

to avoid type mismatch error.

See https://gitlab.com/gitlab-org/gitlab/-/issues/288005#note_613672553.
parent ea525f3b
...@@ -38,6 +38,12 @@ class FinalizePushEventPayloadsBigintConversion < ActiveRecord::Migration[6.1] ...@@ -38,6 +38,12 @@ class FinalizePushEventPayloadsBigintConversion < ActiveRecord::Migration[6.1]
execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:event_id_convert_to_bigint)} TO #{quote_column_name(:event_id)}" execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:event_id_convert_to_bigint)} TO #{quote_column_name(:event_id)}"
execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:event_id_convert_to_bigint)}" execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(:event_id_convert_to_bigint)}"
# We need to update the trigger function in order to make PostgreSQL to
# regenerate the execution plan for it. This is to avoid type mismatch errors like
# "type of parameter 15 (bigint) does not match that when preparing the plan (integer)"
function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME).name(:event_id, :event_id_convert_to_bigint)
execute "ALTER FUNCTION #{function_name} RESET ALL"
# Swap defaults # Swap defaults
change_column_default TABLE_NAME, :event_id, nil change_column_default TABLE_NAME, :event_id, nil
change_column_default TABLE_NAME, :event_id_convert_to_bigint, 0 change_column_default TABLE_NAME, :event_id_convert_to_bigint, 0
......
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