diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-13 00:10:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-13 00:10:33 +0300 |
commit | 8cdf31a1f97786973eb60564ef667e8416d1b1c8 (patch) | |
tree | da2c8f275dc32269bfadda39b74deb28137366c9 /db | |
parent | bf1990164b801489b4475504701eefb66146e724 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
5 files changed, 106 insertions, 2 deletions
diff --git a/db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb b/db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb new file mode 100644 index 00000000000..34f8ec43a8f --- /dev/null +++ b/db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddPypiPackageRequestsForwardingToApplicationSettings < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column(:application_settings, :pypi_package_requests_forwarding, :boolean, default: true, null: false) + end + end + + def down + with_lock_retries do + remove_column(:application_settings, :pypi_package_requests_forwarding) + end + end +end diff --git a/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb b/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb new file mode 100644 index 00000000000..40977277bd1 --- /dev/null +++ b/db/post_migrate/20210706212710_finalize_ci_job_artifacts_bigint_conversion.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class FinalizeCiJobArtifactsBigintConversion < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + TABLE_NAME = 'ci_job_artifacts' + + def up + ensure_batched_background_migration_is_finished( + job_class_name: 'CopyColumnUsingBackgroundMigrationJob', + table_name: TABLE_NAME, + column_name: 'id', + job_arguments: [%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]] + ) + + swap + end + + def down + swap + end + + private + + def swap + 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) + add_concurrent_index TABLE_NAME, [:project_id, :id_convert_to_bigint], name: 'index_ci_job_artifacts_for_terraform_reports_bigint', where: "file_type = 18" + # This is to replace the existing "index_ci_job_artifacts_id_for_terraform_reports" btree (id) where (file_type = 18) + add_concurrent_index TABLE_NAME, [:id_convert_to_bigint], name: 'index_ci_job_artifacts_id_for_terraform_reports_bigint', where: "file_type = 18" + + # Add a FK on `project_pages_metadata(artifacts_archive_id)` to `id_convert_to_bigint`, the old FK (fk_69366a119e) + # will be removed when ci_job_artifacts_pkey constraint is droppped. + fk_artifacts_archive_id = concurrent_foreign_key_name(:project_pages_metadata, :artifacts_archive_id) + fk_artifacts_archive_id_tmp = "#{fk_artifacts_archive_id}_tmp" + add_concurrent_foreign_key :project_pages_metadata, TABLE_NAME, + column: :artifacts_archive_id, target_column: :id_convert_to_bigint, + name: fk_artifacts_archive_id_tmp, + on_delete: :nullify, + reverse_lock_order: true + + with_lock_retries(raise_on_exhaustion: true) do + # We'll need ACCESS EXCLUSIVE lock on the related tables, + # lets make sure it can be acquired from the start + execute "LOCK TABLE #{TABLE_NAME}, project_pages_metadata IN ACCESS EXCLUSIVE MODE" + + # Swap column names + temp_name = 'id_tmp' + execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id)} TO #{quote_column_name(temp_name)}" + execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(:id_convert_to_bigint)} TO #{quote_column_name(:id)}" + execute "ALTER TABLE #{quote_table_name(TABLE_NAME)} RENAME COLUMN #{quote_column_name(temp_name)} TO #{quote_column_name(: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([:id, :job_id], [:id_convert_to_bigint, :job_id_convert_to_bigint]) + execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" + + # Swap defaults + execute "ALTER SEQUENCE ci_job_artifacts_id_seq OWNED BY #{TABLE_NAME}.id" + change_column_default TABLE_NAME, :id, -> { "nextval('ci_job_artifacts_id_seq'::regclass)" } + change_column_default TABLE_NAME, :id_convert_to_bigint, 0 + + # Swap PK constraint + execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT ci_job_artifacts_pkey CASCADE" # this will drop ci_job_artifacts_pkey primary key + rename_index TABLE_NAME, 'index_ci_job_artifact_on_id_convert_to_bigint', 'ci_job_artifacts_pkey' + execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT ci_job_artifacts_pkey PRIMARY KEY USING INDEX ci_job_artifacts_pkey" + + # Rename the rest of the indexes (we already hold an exclusive lock, so no need to use DROP INDEX CONCURRENTLY here + execute 'DROP INDEX index_ci_job_artifacts_for_terraform_reports' + rename_index TABLE_NAME, 'index_ci_job_artifacts_for_terraform_reports_bigint', 'index_ci_job_artifacts_for_terraform_reports' + execute 'DROP INDEX index_ci_job_artifacts_id_for_terraform_reports' + rename_index TABLE_NAME, 'index_ci_job_artifacts_id_for_terraform_reports_bigint', 'index_ci_job_artifacts_id_for_terraform_reports' + + # 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) + end + end +end diff --git a/db/schema_migrations/20210706212710 b/db/schema_migrations/20210706212710 new file mode 100644 index 00000000000..7a4e6df37a4 --- /dev/null +++ b/db/schema_migrations/20210706212710 @@ -0,0 +1 @@ +33162af4ef99c32d3c5b38479e407d4911a8d3dce53407dbee6e5745c8e945ae
\ No newline at end of file diff --git a/db/schema_migrations/20210806152104 b/db/schema_migrations/20210806152104 new file mode 100644 index 00000000000..a8bdc0615d5 --- /dev/null +++ b/db/schema_migrations/20210806152104 @@ -0,0 +1 @@ +1bdbcc6ef5ccf7a2bfb1f9571885e218e230a81b632a2d993302bd87432963f3
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 8955a08a6ba..f107a569313 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9624,6 +9624,7 @@ CREATE TABLE application_settings ( usage_ping_features_enabled boolean DEFAULT false NOT NULL, encrypted_customers_dot_jwt_signing_key bytea, encrypted_customers_dot_jwt_signing_key_iv bytea, + pypi_package_requests_forwarding boolean DEFAULT true NOT NULL, CONSTRAINT app_settings_container_reg_cleanup_tags_max_list_size_positive CHECK ((container_registry_cleanup_tags_service_max_list_size >= 0)), CONSTRAINT app_settings_ext_pipeline_validation_service_url_text_limit CHECK ((char_length(external_pipeline_validation_service_url) <= 255)), CONSTRAINT app_settings_registry_exp_policies_worker_capacity_positive CHECK ((container_registry_expiration_policies_worker_capacity >= 0)), @@ -10785,7 +10786,7 @@ CREATE SEQUENCE ci_instance_variables_id_seq ALTER SEQUENCE ci_instance_variables_id_seq OWNED BY ci_instance_variables.id; CREATE TABLE ci_job_artifacts ( - id integer NOT NULL, + id_convert_to_bigint integer DEFAULT 0 NOT NULL, project_id integer NOT NULL, job_id_convert_to_bigint integer DEFAULT 0 NOT NULL, file_type integer NOT NULL, @@ -10798,7 +10799,7 @@ CREATE TABLE ci_job_artifacts ( file_sha256 bytea, file_format smallint, file_location smallint, - id_convert_to_bigint bigint DEFAULT 0 NOT NULL, + id bigint NOT NULL, job_id bigint NOT NULL, CONSTRAINT check_27f0f6dbab CHECK ((file_store IS NOT NULL)) ); |