From e64f04ac671780713a1b16b45b4e24cfb3c9287c Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Wed, 9 Aug 2023 19:37:52 +0100 Subject: [PATCH 1/2] Save pages_deployments path_prefix and build.ref As part of the GitLab Pages Multiple Versions Support[^1], we need to add `path_prefix` and `build_ref` to PagesDeployment: - the path_prefix will be used to build the versioned url - the ref (git reference) will be used to clear deployments when the ref is deleted (branch/tag) New pages builds must save the build.ref in the PagesDeployment#ref column. [^1]: https://gitlab.com/groups/gitlab-org/-/epics/10914 Related to: https://gitlab.com/gitlab-org/gitlab/-/issues/416488 Changelog: added --- ...efix_and_build_ref_to_pages_deployments.rb | 15 +++++++++++ ...efix_and_build_ref_to_pages_deployments.rb | 25 +++++++++++++++++++ db/schema_migrations/20230809165212 | 1 + db/schema_migrations/20230809165213 | 1 + db/structure.sql | 6 +++++ 5 files changed, 48 insertions(+) create mode 100644 db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb create mode 100644 db/migrate/20230809165213_add_index_to_path_prefix_and_build_ref_to_pages_deployments.rb create mode 100644 db/schema_migrations/20230809165212 create mode 100644 db/schema_migrations/20230809165213 diff --git a/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb b/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb new file mode 100644 index 00000000000000..39fd702ec7c566 --- /dev/null +++ b/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddPathPrefixAndBuildRefToPagesDeployments < Gitlab::Database::Migration[2.1] + TABLE_NAME = :pages_deployments + + enable_lock_retries! + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20230809165213_add_index_to_path_prefix_and_ref_to_pages_deployments + def change + add_column TABLE_NAME, :path_prefix, :text + add_column TABLE_NAME, :build_ref, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20230809165213_add_index_to_path_prefix_and_build_ref_to_pages_deployments.rb b/db/migrate/20230809165213_add_index_to_path_prefix_and_build_ref_to_pages_deployments.rb new file mode 100644 index 00000000000000..bea4346cfab942 --- /dev/null +++ b/db/migrate/20230809165213_add_index_to_path_prefix_and_build_ref_to_pages_deployments.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddIndexToPathPrefixAndBuildRefToPagesDeployments < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLE_NAME = :pages_deployments + INDEX_NAME = 'index_pages_deployments_unique_path_prefix_by_project' + + def up + add_text_limit TABLE_NAME, :path_prefix, 128 + add_text_limit TABLE_NAME, :build_ref, 512 + + add_concurrent_index TABLE_NAME, + [:project_id, :path_prefix], + name: INDEX_NAME, + unique: true + end + + def down + remove_text_limit TABLE_NAME, :path_prefix + remove_text_limit TABLE_NAME, :build_ref + + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end +end diff --git a/db/schema_migrations/20230809165212 b/db/schema_migrations/20230809165212 new file mode 100644 index 00000000000000..72d1751c42ef9b --- /dev/null +++ b/db/schema_migrations/20230809165212 @@ -0,0 +1 @@ +4137f5af1cb4a00144afecac7ad99e926be4f5a8fa501faaab00f4f017c90cf6 \ No newline at end of file diff --git a/db/schema_migrations/20230809165213 b/db/schema_migrations/20230809165213 new file mode 100644 index 00000000000000..c0bcff0566ed6a --- /dev/null +++ b/db/schema_migrations/20230809165213 @@ -0,0 +1 @@ +cdab5ff65d93b1883bd75c60efa21ce03031b2678f4535ae2a50a6ca4377c32d \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 8d694c00c6c72d..9cf19843a4fa0a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -20244,8 +20244,12 @@ CREATE TABLE pages_deployments ( file_sha256 bytea NOT NULL, size bigint, root_directory text DEFAULT 'public'::text, + path_prefix text, + build_ref text, + CONSTRAINT check_4d04b8dc9a CHECK ((char_length(path_prefix) <= 128)), CONSTRAINT check_5f9132a958 CHECK ((size IS NOT NULL)), CONSTRAINT check_7e938c810a CHECK ((char_length(root_directory) <= 255)), + CONSTRAINT check_b44e900e5c CHECK ((char_length(build_ref) <= 512)), CONSTRAINT check_f0fe8032dd CHECK ((char_length(file) <= 255)) ); @@ -32701,6 +32705,8 @@ CREATE INDEX index_pages_deployments_on_file_store_and_id ON pages_deployments U CREATE INDEX index_pages_deployments_on_project_id ON pages_deployments USING btree (project_id); +CREATE UNIQUE INDEX index_pages_deployments_unique_path_prefix_by_project ON pages_deployments USING btree (project_id, path_prefix); + CREATE INDEX index_pages_domain_acme_orders_on_challenge_token ON pages_domain_acme_orders USING btree (challenge_token); CREATE INDEX index_pages_domain_acme_orders_on_pages_domain_id ON pages_domain_acme_orders USING btree (pages_domain_id); -- GitLab From b28ca986f84020c5daddd4a78b3b04e76540ec7c Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Fri, 11 Aug 2023 15:31:59 +0100 Subject: [PATCH 2/2] Fix CI by removing constant --- ...12_add_path_prefix_and_build_ref_to_pages_deployments.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb b/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb index 39fd702ec7c566..d2fc8bfc9bca1d 100644 --- a/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb +++ b/db/migrate/20230809165212_add_path_prefix_and_build_ref_to_pages_deployments.rb @@ -1,15 +1,13 @@ # frozen_string_literal: true class AddPathPrefixAndBuildRefToPagesDeployments < Gitlab::Database::Migration[2.1] - TABLE_NAME = :pages_deployments - enable_lock_retries! # rubocop:disable Migration/AddLimitToTextColumns # limit is added in 20230809165213_add_index_to_path_prefix_and_ref_to_pages_deployments def change - add_column TABLE_NAME, :path_prefix, :text - add_column TABLE_NAME, :build_ref, :text + add_column :pages_deployments, :path_prefix, :text + add_column :pages_deployments, :build_ref, :text end # rubocop:enable Migration/AddLimitToTextColumns end -- GitLab