Skip to content
Snippets Groups Projects

Finalize ci_job_artifacts conversion to bigint

Merged Alex Ives requested to merge 325615/finalize_ci_job_artifacts_bigint into master
1 unresolved thread
Compare and Show latest version
1 file
+ 25
10
Compare changes
  • Side-by-side
  • Inline
@@ -28,6 +28,7 @@ def down
@@ -28,6 +28,7 @@ def down
private
private
def swap
def swap
 
add_concurrent_index TABLE_NAME, :job_id_convert_to_bigint, unique: true, name: 'index_ci_job_artifact_on_job_id_convert_to_bigint'
# This is to replace the existing "ci_job_artifacts_pkey" PRIMARY KEY, btree (id)
# This is to replace the existing "ci_job_artifacts_pkey" PRIMARY KEY, btree (id)
add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_ci_job_artifact_on_id_convert_to_bigint'
add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: 'index_ci_job_artifact_on_id_convert_to_bigint'
# This is to replace the existing "index_ci_job_artifacts_for_terraform_reports" btree (project_id, id) where (file_type = 18)
# This is to replace the existing "index_ci_job_artifacts_for_terraform_reports" btree (project_id, id) where (file_type = 18)
@@ -48,14 +49,26 @@ def swap
@@ -48,14 +49,26 @@ def swap
name: fk_artifacts_archive_id_tmp,
name: fk_artifacts_archive_id_tmp,
on_delete: :nullify
on_delete: :nullify
# Add a FK on `job_id_convert_to_bigint` to `ci_builds(id)`, the old FK (fk_rails_c5137cb2c1)
# # Add a FK on `job_id_convert_to_bigint` to `ci_builds(id)`, the old FK (fk_rails_c5137cb2c1)
# is removed below since it won't be dropped automatically.
# # is removed below since it won't be dropped automatically.
fk_ci_builds_job_id = concurrent_foreign_key_name(TABLE_NAME, :job_id, prefix: 'fk_rails_')
# fk_ci_builds_job_id = concurrent_foreign_key_name(TABLE_NAME, :job_id, prefix: 'fk_rails_')
fk_ci_builds_job_id_tmp = "#{fk_ci_builds_job_id}_tmp"
# fk_ci_builds_job_id_tmp = "#{fk_ci_builds_job_id}_tmp"
add_concurrent_foreign_key TABLE_NAME, :ci_builds,
column: :job_id_convert_to_bigint,
# add_concurrent_foreign_key TABLE_NAME, :ci_builds,
name: fk_ci_builds_job_id_tmp,
# column: :job_id_convert_to_bigint,
on_delete: :cascade
# name: fk_ci_builds_job_id_tmp,
 
# on_delete: :cascade
 
 
# Add a foreign key on `job_id_convert_to_bigint` before we swap the columns and drop the old FK ()
 
add_concurrent_foreign_key TABLE_NAME, :ci_builds, column: :job_id_convert_to_bigint, on_delete: :cascade, name: 'fk_rails_c5137cb2c1_tmp'
 
 
 
 
 
 
 
 
with_lock_retries(raise_on_exhaustion: true) do
with_lock_retries(raise_on_exhaustion: true) do
# We'll need ACCESS EXCLUSIVE lock on the related tables,
# We'll need ACCESS EXCLUSIVE lock on the related tables,
@@ -102,15 +115,17 @@ def swap
@@ -102,15 +115,17 @@ def swap
execute 'DROP INDEX index_ci_job_artifacts_on_job_id_and_file_type'
execute 'DROP INDEX index_ci_job_artifacts_on_job_id_and_file_type'
rename_index TABLE_NAME, 'index_ci_job_artifacts_on_job_id_and_file_type_bigint', 'index_ci_job_artifacts_on_job_id_and_file_type'
rename_index TABLE_NAME, 'index_ci_job_artifacts_on_job_id_and_file_type_bigint', 'index_ci_job_artifacts_on_job_id_and_file_type'
 
rename_index TABLE_NAME, 'index_ci_job_artifact_on_job_id_convert_to_bigint', 'index_ci_job_artifact_on_job_id'
 
# Change the name of the temporary FK for project_pages_metadata(artifacts_archive_id) -> id
# Change the name of the temporary FK for project_pages_metadata(artifacts_archive_id) -> id
rename_constraint(:project_pages_metadata, fk_artifacts_archive_id_tmp, fk_artifacts_archive_id)
rename_constraint(:project_pages_metadata, fk_artifacts_archive_id_tmp, fk_artifacts_archive_id)
# Drop original FK on the old int4 `job_id` (fk_rails_c5137cb2c1)
# Drop original FK on the old int4 `job_id` (fk_rails_c5137cb2c1)
remove_foreign_key TABLE_NAME, name: fk_ci_builds_job_id
remove_foreign_key TABLE_NAME, name: 'fk_rails_c5137cb2c1'
# We swapped the columns but the FK for job_id is still using the temporary name for the job_id_convert_to_bigint column
# We swapped the columns but the FK for job_id is still using the temporary name for the job_id_convert_to_bigint column
# So we have to also swap the FK name now that we dropped the other one with the same
# So we have to also swap the FK name now that we dropped the other one with the same
rename_constraint(TABLE_NAME, fk_ci_builds_job_id_tmp, fk_ci_builds_job_id)
rename_constraint(TABLE_NAME, 'fk_rails_c5137cb2c1_tmp', 'fk_rails_c5137cb2c1')
end
end
end
end
end
end
Loading