From 2a021f0c120fc56762c672ee51a5d49eac79f63e Mon Sep 17 00:00:00 2001 From: Ryan Cobb Date: Wed, 19 Nov 2025 14:13:56 -0700 Subject: [PATCH 1/3] Add plan name UID columns Adds plan name UID columns to tables. These will eventually be the new foreign keys, replacing Plan id. --- ...195901_add_plan_name_uid_to_plan_limits.rb | 24 +++++++++++++++++++ ..._add_plan_name_uid_to_ci_pending_builds.rb | 24 +++++++++++++++++++ ...d_plan_name_uid_to_gitlab_subscriptions.rb | 24 +++++++++++++++++++ ...me_uid_to_gitlab_subscription_histories.rb | 24 +++++++++++++++++++ ...dd_allowed_plan_name_uids_to_ci_runners.rb | 14 +++++++++++ db/schema_migrations/20251119195901 | 1 + db/schema_migrations/20251119202845 | 1 + db/schema_migrations/20251119203450 | 1 + db/schema_migrations/20251119203834 | 1 + db/schema_migrations/20251119210931 | 1 + db/structure.sql | 20 ++++++++++++++-- 11 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb create mode 100644 db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb create mode 100644 db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb create mode 100644 db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb create mode 100644 db/migrate/20251119210931_add_allowed_plan_name_uids_to_ci_runners.rb create mode 100644 db/schema_migrations/20251119195901 create mode 100644 db/schema_migrations/20251119202845 create mode 100644 db/schema_migrations/20251119203450 create mode 100644 db/schema_migrations/20251119203834 create mode 100644 db/schema_migrations/20251119210931 diff --git a/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb b/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb new file mode 100644 index 00000000000000..a287901e9481d6 --- /dev/null +++ b/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddPlanNameUidToPlanLimits < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_plan_limits_on_plan_name_uid' + + def up + with_lock_retries do + add_column :plan_limits, :plan_name_uid, :smallint, if_not_exists: true + end + + add_concurrent_index :plan_limits, :plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :plan_limits, INDEX_NAME + + with_lock_retries do + remove_column :plan_limits, :plan_name_uid, if_exists: true + end + end +end diff --git a/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb b/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb new file mode 100644 index 00000000000000..138b35365e829e --- /dev/null +++ b/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddPlanNameUidToCiPendingBuilds < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_ci_pending_builds_on_plan_name_uid' + + def up + with_lock_retries do + add_column :ci_pending_builds, :plan_name_uid, :smallint, if_not_exists: true + end + + add_concurrent_index :ci_pending_builds, :plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :ci_pending_builds, INDEX_NAME + + with_lock_retries do + remove_column :ci_pending_builds, :plan_name_uid, if_exists: true + end + end +end diff --git a/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb b/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb new file mode 100644 index 00000000000000..34a567d9bee547 --- /dev/null +++ b/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddHostedPlanNameUidToGitlabSubscriptions < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_name_uid' + + def up + with_lock_retries do + add_column :gitlab_subscriptions, :hosted_plan_name_uid, :smallint, if_not_exists: true + end + + add_concurrent_index :gitlab_subscriptions, :hosted_plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :gitlab_subscriptions, INDEX_NAME + + with_lock_retries do + remove_column :gitlab_subscriptions, :hosted_plan_name_uid, if_exists: true + end + end +end diff --git a/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb b/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb new file mode 100644 index 00000000000000..4e9a624cbb4a1f --- /dev/null +++ b/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddHostedPlanNameUidToGitlabSubscriptionHistories < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_gitlab_subscription_histories_on_hosted_plan_name_uid' + + def up + with_lock_retries do + add_column :gitlab_subscription_histories, :hosted_plan_name_uid, :smallint, if_not_exists: true + end + + add_concurrent_index :gitlab_subscription_histories, :hosted_plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :gitlab_subscription_histories, INDEX_NAME + + with_lock_retries do + remove_column :gitlab_subscription_histories, :hosted_plan_name_uid, if_exists: true + end + end +end diff --git a/db/migrate/20251119210931_add_allowed_plan_name_uids_to_ci_runners.rb b/db/migrate/20251119210931_add_allowed_plan_name_uids_to_ci_runners.rb new file mode 100644 index 00000000000000..8dd63edc24e317 --- /dev/null +++ b/db/migrate/20251119210931_add_allowed_plan_name_uids_to_ci_runners.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddAllowedPlanNameUidsToCiRunners < Gitlab::Database::Migration[2.3] + milestone '18.7' + + def up + add_column :ci_runners, :allowed_plan_name_uids, :smallint, + array: true, default: [], null: false, if_not_exists: true + end + + def down + remove_column :ci_runners, :allowed_plan_name_uids, if_exists: true + end +end diff --git a/db/schema_migrations/20251119195901 b/db/schema_migrations/20251119195901 new file mode 100644 index 00000000000000..13219522dc3b87 --- /dev/null +++ b/db/schema_migrations/20251119195901 @@ -0,0 +1 @@ +8fdfaf8892ed7fe46a2665993fd15e317d3a883d78eed5e4b82686dc17f8365a \ No newline at end of file diff --git a/db/schema_migrations/20251119202845 b/db/schema_migrations/20251119202845 new file mode 100644 index 00000000000000..c11eec401a73b3 --- /dev/null +++ b/db/schema_migrations/20251119202845 @@ -0,0 +1 @@ +68d103cfc6b7ea7436c11d607a34d0419600934f68f6e7666c9e1b59c0c456d9 \ No newline at end of file diff --git a/db/schema_migrations/20251119203450 b/db/schema_migrations/20251119203450 new file mode 100644 index 00000000000000..a1a64b1ae6c354 --- /dev/null +++ b/db/schema_migrations/20251119203450 @@ -0,0 +1 @@ +ee5b2b0328e7fb831f4dd9585f36671d063ccc50af3e31db3133ba39a88a6ad5 \ No newline at end of file diff --git a/db/schema_migrations/20251119203834 b/db/schema_migrations/20251119203834 new file mode 100644 index 00000000000000..da5079137da7ff --- /dev/null +++ b/db/schema_migrations/20251119203834 @@ -0,0 +1 @@ +f17decd5f3edd0c3145a3fe5a44e44f8f0fbf96e3384d6f2feba56aa8d21b7f2 \ No newline at end of file diff --git a/db/schema_migrations/20251119210931 b/db/schema_migrations/20251119210931 new file mode 100644 index 00000000000000..a1882f789c66e6 --- /dev/null +++ b/db/schema_migrations/20251119210931 @@ -0,0 +1 @@ +07c26698f88dfa06873af8b2f203cdcb33f9653907379eb342e2579ab7ddd1fc \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 5e97e6deab537f..aaeeb6a87753d9 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -14559,7 +14559,8 @@ CREATE TABLE ci_pending_builds ( tag_ids bigint[] DEFAULT '{}'::bigint[], namespace_traversal_ids bigint[] DEFAULT '{}'::bigint[], partition_id bigint NOT NULL, - plan_id bigint + plan_id bigint, + plan_name_uid smallint ); CREATE SEQUENCE ci_pending_builds_id_seq @@ -15024,6 +15025,7 @@ CREATE TABLE ci_runners ( allowed_plans text[] DEFAULT '{}'::text[] NOT NULL, allowed_plan_ids bigint[] DEFAULT '{}'::bigint[] NOT NULL, organization_id bigint, + allowed_plan_name_uids smallint[] DEFAULT '{}'::smallint[] NOT NULL, CONSTRAINT check_030ad0773d CHECK ((char_length(token_encrypted) <= 512)), CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), @@ -17998,6 +18000,7 @@ CREATE TABLE gitlab_subscription_histories ( auto_renew boolean, trial_extension_type smallint, seats_in_use integer, + hosted_plan_name_uid smallint, CONSTRAINT check_6d5f27a106 CHECK ((namespace_id IS NOT NULL)) ); @@ -18029,6 +18032,7 @@ CREATE TABLE gitlab_subscriptions ( trial_extension_type smallint, max_seats_used_changed_at timestamp with time zone, last_seat_refresh_at timestamp with time zone, + hosted_plan_name_uid smallint, CONSTRAINT check_77fea3f0e7 CHECK ((namespace_id IS NOT NULL)) ); @@ -18497,6 +18501,7 @@ CREATE TABLE group_type_ci_runners ( allowed_plans text[] DEFAULT '{}'::text[] NOT NULL, allowed_plan_ids bigint[] DEFAULT '{}'::bigint[] NOT NULL, organization_id bigint, + allowed_plan_name_uids smallint[] DEFAULT '{}'::smallint[] NOT NULL, CONSTRAINT check_030ad0773d CHECK ((char_length(token_encrypted) <= 512)), CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), @@ -19161,6 +19166,7 @@ CREATE TABLE instance_type_ci_runners ( allowed_plans text[] DEFAULT '{}'::text[] NOT NULL, allowed_plan_ids bigint[] DEFAULT '{}'::bigint[] NOT NULL, organization_id bigint, + allowed_plan_name_uids smallint[] DEFAULT '{}'::smallint[] NOT NULL, CONSTRAINT check_030ad0773d CHECK ((char_length(token_encrypted) <= 512)), CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), @@ -23606,7 +23612,8 @@ CREATE TABLE plan_limits ( import_placeholder_user_limit_tier_4 integer DEFAULT 0 NOT NULL, ci_max_artifact_size_slsa_provenance_statement bigint DEFAULT 0 NOT NULL, cargo_max_file_size bigint DEFAULT '5368709120'::bigint NOT NULL, - ci_max_artifact_size_scip integer DEFAULT 200 NOT NULL + ci_max_artifact_size_scip integer DEFAULT 200 NOT NULL, + plan_name_uid smallint ); CREATE SEQUENCE plan_limits_id_seq @@ -25208,6 +25215,7 @@ CREATE TABLE project_type_ci_runners ( allowed_plans text[] DEFAULT '{}'::text[] NOT NULL, allowed_plan_ids bigint[] DEFAULT '{}'::bigint[] NOT NULL, organization_id bigint, + allowed_plan_name_uids smallint[] DEFAULT '{}'::smallint[] NOT NULL, CONSTRAINT check_030ad0773d CHECK ((char_length(token_encrypted) <= 512)), CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), @@ -40581,6 +40589,8 @@ CREATE UNIQUE INDEX index_ci_pending_builds_on_partition_id_build_id ON ci_pendi CREATE INDEX index_ci_pending_builds_on_plan_id ON ci_pending_builds USING btree (plan_id); +CREATE INDEX index_ci_pending_builds_on_plan_name_uid ON ci_pending_builds USING btree (plan_name_uid); + CREATE INDEX index_ci_pending_builds_on_project_id ON ci_pending_builds USING btree (project_id); CREATE INDEX index_ci_pending_builds_on_tag_ids ON ci_pending_builds USING btree (tag_ids) WHERE (cardinality(tag_ids) > 0); @@ -41447,10 +41457,14 @@ CREATE INDEX index_gitlab_subscription_histories_on_end_date ON gitlab_subscript CREATE INDEX index_gitlab_subscription_histories_on_gitlab_subscription_id ON gitlab_subscription_histories USING btree (gitlab_subscription_id); +CREATE INDEX index_gitlab_subscription_histories_on_hosted_plan_name_uid ON gitlab_subscription_histories USING btree (hosted_plan_name_uid); + CREATE INDEX index_gitlab_subscriptions_on_end_date_and_namespace_id ON gitlab_subscriptions USING btree (end_date, namespace_id); CREATE INDEX index_gitlab_subscriptions_on_hosted_plan_id_and_trial ON gitlab_subscriptions USING btree (hosted_plan_id, trial); +CREATE INDEX index_gitlab_subscriptions_on_hosted_plan_name_uid ON gitlab_subscriptions USING btree (hosted_plan_name_uid); + CREATE INDEX index_gitlab_subscriptions_on_max_seats_used_changed_at ON gitlab_subscriptions USING btree (max_seats_used_changed_at, namespace_id); CREATE UNIQUE INDEX index_gitlab_subscriptions_on_namespace_id ON gitlab_subscriptions USING btree (namespace_id); @@ -43087,6 +43101,8 @@ CREATE INDEX index_pipl_users_on_initial_email_sent_at ON pipl_users USING btree CREATE UNIQUE INDEX index_plan_limits_on_plan_id ON plan_limits USING btree (plan_id); +CREATE INDEX index_plan_limits_on_plan_name_uid ON plan_limits USING btree (plan_name_uid); + CREATE UNIQUE INDEX index_plans_on_name ON plans USING btree (name); CREATE UNIQUE INDEX index_plans_on_plan_name_uid ON plans USING btree (plan_name_uid); -- GitLab From 65efe0e4c686c6904edf223154effe825207cde1 Mon Sep 17 00:00:00 2001 From: Ryan Cobb Date: Mon, 24 Nov 2025 14:50:24 -0700 Subject: [PATCH 2/3] Move index creation to post migrations Move index creation to post migrations --- ...119195901_add_plan_name_uid_to_plan_limits.rb | 15 ++------------- ...845_add_plan_name_uid_to_ci_pending_builds.rb | 15 ++------------- ...sted_plan_name_uid_to_gitlab_subscriptions.rb | 15 ++------------- ..._name_uid_to_gitlab_subscription_histories.rb | 15 ++------------- ..._add_index_on_plan_name_uid_to_plan_limits.rb | 16 ++++++++++++++++ ...ndex_on_plan_name_uid_to_ci_pending_builds.rb | 16 ++++++++++++++++ ...sted_plan_name_uid_to_gitlab_subscriptions.rb | 16 ++++++++++++++++ ..._name_uid_to_gitlab_subscription_histories.rb | 16 ++++++++++++++++ db/schema_migrations/20251124211745 | 1 + db/schema_migrations/20251124211809 | 1 + db/schema_migrations/20251124211820 | 1 + db/schema_migrations/20251124211831 | 1 + .../gitlab_subscriptions/subscription_history.rb | 1 + ee/spec/models/ee/namespace_spec.rb | 2 +- spec/models/plan_limits_spec.rb | 2 +- 15 files changed, 79 insertions(+), 54 deletions(-) create mode 100644 db/post_migrate/20251124211745_add_index_on_plan_name_uid_to_plan_limits.rb create mode 100644 db/post_migrate/20251124211809_add_index_on_plan_name_uid_to_ci_pending_builds.rb create mode 100644 db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb create mode 100644 db/post_migrate/20251124211831_add_index_on_hosted_plan_name_uid_to_gitlab_subscription_histories.rb create mode 100644 db/schema_migrations/20251124211745 create mode 100644 db/schema_migrations/20251124211809 create mode 100644 db/schema_migrations/20251124211820 create mode 100644 db/schema_migrations/20251124211831 diff --git a/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb b/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb index a287901e9481d6..539bfc739b185d 100644 --- a/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb +++ b/db/migrate/20251119195901_add_plan_name_uid_to_plan_limits.rb @@ -2,23 +2,12 @@ class AddPlanNameUidToPlanLimits < Gitlab::Database::Migration[2.3] milestone '18.7' - disable_ddl_transaction! - - INDEX_NAME = 'index_plan_limits_on_plan_name_uid' def up - with_lock_retries do - add_column :plan_limits, :plan_name_uid, :smallint, if_not_exists: true - end - - add_concurrent_index :plan_limits, :plan_name_uid, name: INDEX_NAME + add_column :plan_limits, :plan_name_uid, :smallint, if_not_exists: true end def down - remove_concurrent_index_by_name :plan_limits, INDEX_NAME - - with_lock_retries do - remove_column :plan_limits, :plan_name_uid, if_exists: true - end + remove_column :plan_limits, :plan_name_uid, if_exists: true end end diff --git a/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb b/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb index 138b35365e829e..d2e7c03ae60dd4 100644 --- a/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb +++ b/db/migrate/20251119202845_add_plan_name_uid_to_ci_pending_builds.rb @@ -2,23 +2,12 @@ class AddPlanNameUidToCiPendingBuilds < Gitlab::Database::Migration[2.3] milestone '18.7' - disable_ddl_transaction! - - INDEX_NAME = 'index_ci_pending_builds_on_plan_name_uid' def up - with_lock_retries do - add_column :ci_pending_builds, :plan_name_uid, :smallint, if_not_exists: true - end - - add_concurrent_index :ci_pending_builds, :plan_name_uid, name: INDEX_NAME + add_column :ci_pending_builds, :plan_name_uid, :smallint, if_not_exists: true end def down - remove_concurrent_index_by_name :ci_pending_builds, INDEX_NAME - - with_lock_retries do - remove_column :ci_pending_builds, :plan_name_uid, if_exists: true - end + remove_column :ci_pending_builds, :plan_name_uid, if_exists: true end end diff --git a/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb b/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb index 34a567d9bee547..69f5b431c9016f 100644 --- a/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb +++ b/db/migrate/20251119203450_add_hosted_plan_name_uid_to_gitlab_subscriptions.rb @@ -2,23 +2,12 @@ class AddHostedPlanNameUidToGitlabSubscriptions < Gitlab::Database::Migration[2.3] milestone '18.7' - disable_ddl_transaction! - - INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_name_uid' def up - with_lock_retries do - add_column :gitlab_subscriptions, :hosted_plan_name_uid, :smallint, if_not_exists: true - end - - add_concurrent_index :gitlab_subscriptions, :hosted_plan_name_uid, name: INDEX_NAME + add_column :gitlab_subscriptions, :hosted_plan_name_uid, :smallint, if_not_exists: true end def down - remove_concurrent_index_by_name :gitlab_subscriptions, INDEX_NAME - - with_lock_retries do - remove_column :gitlab_subscriptions, :hosted_plan_name_uid, if_exists: true - end + remove_column :gitlab_subscriptions, :hosted_plan_name_uid, if_exists: true end end diff --git a/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb b/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb index 4e9a624cbb4a1f..d56a6847e7c18f 100644 --- a/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb +++ b/db/migrate/20251119203834_add_hosted_plan_name_uid_to_gitlab_subscription_histories.rb @@ -2,23 +2,12 @@ class AddHostedPlanNameUidToGitlabSubscriptionHistories < Gitlab::Database::Migration[2.3] milestone '18.7' - disable_ddl_transaction! - - INDEX_NAME = 'index_gitlab_subscription_histories_on_hosted_plan_name_uid' def up - with_lock_retries do - add_column :gitlab_subscription_histories, :hosted_plan_name_uid, :smallint, if_not_exists: true - end - - add_concurrent_index :gitlab_subscription_histories, :hosted_plan_name_uid, name: INDEX_NAME + add_column :gitlab_subscription_histories, :hosted_plan_name_uid, :smallint, if_not_exists: true end def down - remove_concurrent_index_by_name :gitlab_subscription_histories, INDEX_NAME - - with_lock_retries do - remove_column :gitlab_subscription_histories, :hosted_plan_name_uid, if_exists: true - end + remove_column :gitlab_subscription_histories, :hosted_plan_name_uid, if_exists: true end end diff --git a/db/post_migrate/20251124211745_add_index_on_plan_name_uid_to_plan_limits.rb b/db/post_migrate/20251124211745_add_index_on_plan_name_uid_to_plan_limits.rb new file mode 100644 index 00000000000000..e95abb7a0474e6 --- /dev/null +++ b/db/post_migrate/20251124211745_add_index_on_plan_name_uid_to_plan_limits.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddIndexOnPlanNameUidToPlanLimits < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_plan_limits_on_plan_name_uid' + + def up + add_concurrent_index :plan_limits, :plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :plan_limits, INDEX_NAME + end +end diff --git a/db/post_migrate/20251124211809_add_index_on_plan_name_uid_to_ci_pending_builds.rb b/db/post_migrate/20251124211809_add_index_on_plan_name_uid_to_ci_pending_builds.rb new file mode 100644 index 00000000000000..c1bb531dd61af6 --- /dev/null +++ b/db/post_migrate/20251124211809_add_index_on_plan_name_uid_to_ci_pending_builds.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddIndexOnPlanNameUidToCiPendingBuilds < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_ci_pending_builds_on_plan_name_uid' + + def up + add_concurrent_index :ci_pending_builds, :plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :ci_pending_builds, INDEX_NAME + end +end diff --git a/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb b/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb new file mode 100644 index 00000000000000..8a4a452d05c097 --- /dev/null +++ b/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddIndexOnHostedPlanNameUidToGitlabSubscriptions < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_name_uid' + + def up + add_concurrent_index :gitlab_subscriptions, :hosted_plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :gitlab_subscriptions, INDEX_NAME + end +end diff --git a/db/post_migrate/20251124211831_add_index_on_hosted_plan_name_uid_to_gitlab_subscription_histories.rb b/db/post_migrate/20251124211831_add_index_on_hosted_plan_name_uid_to_gitlab_subscription_histories.rb new file mode 100644 index 00000000000000..3d148b7bc06ea0 --- /dev/null +++ b/db/post_migrate/20251124211831_add_index_on_hosted_plan_name_uid_to_gitlab_subscription_histories.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddIndexOnHostedPlanNameUidToGitlabSubscriptionHistories < Gitlab::Database::Migration[2.3] + milestone '18.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_gitlab_subscription_histories_on_hosted_plan_name_uid' + + def up + add_concurrent_index :gitlab_subscription_histories, :hosted_plan_name_uid, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :gitlab_subscription_histories, INDEX_NAME + end +end diff --git a/db/schema_migrations/20251124211745 b/db/schema_migrations/20251124211745 new file mode 100644 index 00000000000000..c0df53858bb990 --- /dev/null +++ b/db/schema_migrations/20251124211745 @@ -0,0 +1 @@ +e90702be646e9b8b4707aa53b16e9a7086f12836dad34d50e1a30e24bc6ac5ef \ No newline at end of file diff --git a/db/schema_migrations/20251124211809 b/db/schema_migrations/20251124211809 new file mode 100644 index 00000000000000..d35ac2e282755b --- /dev/null +++ b/db/schema_migrations/20251124211809 @@ -0,0 +1 @@ +4c49bc9a9e49f605d57b8fc436e58a943f67b66fa47e684fc339aa7a5e1abeef \ No newline at end of file diff --git a/db/schema_migrations/20251124211820 b/db/schema_migrations/20251124211820 new file mode 100644 index 00000000000000..6900a13b08b9e4 --- /dev/null +++ b/db/schema_migrations/20251124211820 @@ -0,0 +1 @@ +ee46811b0cbffddc9eb8b23a4a772c481fa5eb5d632c6407358482b8cedba38c \ No newline at end of file diff --git a/db/schema_migrations/20251124211831 b/db/schema_migrations/20251124211831 new file mode 100644 index 00000000000000..81e3d739bd9a34 --- /dev/null +++ b/db/schema_migrations/20251124211831 @@ -0,0 +1 @@ +6f458c0adcc6e23af9bd8706e19ce9651efc7a29a6f5782031f1ec6f275e59ea \ No newline at end of file diff --git a/ee/app/models/gitlab_subscriptions/subscription_history.rb b/ee/app/models/gitlab_subscriptions/subscription_history.rb index e77c859946452b..c1f9caa1b09831 100644 --- a/ee/app/models/gitlab_subscriptions/subscription_history.rb +++ b/ee/app/models/gitlab_subscriptions/subscription_history.rb @@ -28,6 +28,7 @@ class SubscriptionHistory < ApplicationRecord trial_ends_on namespace_id hosted_plan_id + hosted_plan_name_uid seats_in_use max_seats_used seats diff --git a/ee/spec/models/ee/namespace_spec.rb b/ee/spec/models/ee/namespace_spec.rb index ac50834a0a60b8..32b121d04ea7bf 100644 --- a/ee/spec/models/ee/namespace_spec.rb +++ b/ee/spec/models/ee/namespace_spec.rb @@ -1050,7 +1050,7 @@ end it 'has all limits defined' do - limits = subject.attributes.except('id', 'plan_id', 'repository_size', 'dashboard_limit_enabled_at', 'updated_at') + limits = subject.attributes.except('id', 'plan_id', 'repository_size', 'plan_name_uid', 'dashboard_limit_enabled_at', 'updated_at') limits.each do |_attribute, limit| expect(limit).not_to be_nil end diff --git a/spec/models/plan_limits_spec.rb b/spec/models/plan_limits_spec.rb index 3d598659130ef9..0ac6287adbfc43 100644 --- a/spec/models/plan_limits_spec.rb +++ b/spec/models/plan_limits_spec.rb @@ -279,7 +279,7 @@ end let(:columns_with_nil) do - %w[repository_size] + %w[repository_size plan_name_uid] end let(:datetime_columns) do -- GitLab From 0478f8147fbc3ffa239fd02dedf6ecec62c3686c Mon Sep 17 00:00:00 2001 From: Ryan Cobb Date: Mon, 1 Dec 2025 15:20:53 -0700 Subject: [PATCH 3/3] Index on hosted_plan_name_uid and trial --- ...d_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb | 4 ++-- db/structure.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb b/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb index 8a4a452d05c097..5c4638b5f7d0a7 100644 --- a/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb +++ b/db/post_migrate/20251124211820_add_index_on_hosted_plan_name_uid_to_gitlab_subscriptions.rb @@ -4,10 +4,10 @@ class AddIndexOnHostedPlanNameUidToGitlabSubscriptions < Gitlab::Database::Migra milestone '18.7' disable_ddl_transaction! - INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_name_uid' + INDEX_NAME = 'index_gitlab_subscriptions_on_hosted_plan_name_uid_and_trial' def up - add_concurrent_index :gitlab_subscriptions, :hosted_plan_name_uid, name: INDEX_NAME + add_concurrent_index :gitlab_subscriptions, [:hosted_plan_name_uid, :trial], name: INDEX_NAME end def down diff --git a/db/structure.sql b/db/structure.sql index aaeeb6a87753d9..0c68c6b025df7b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -41463,7 +41463,7 @@ CREATE INDEX index_gitlab_subscriptions_on_end_date_and_namespace_id ON gitlab_s CREATE INDEX index_gitlab_subscriptions_on_hosted_plan_id_and_trial ON gitlab_subscriptions USING btree (hosted_plan_id, trial); -CREATE INDEX index_gitlab_subscriptions_on_hosted_plan_name_uid ON gitlab_subscriptions USING btree (hosted_plan_name_uid); +CREATE INDEX index_gitlab_subscriptions_on_hosted_plan_name_uid_and_trial ON gitlab_subscriptions USING btree (hosted_plan_name_uid, trial); CREATE INDEX index_gitlab_subscriptions_on_max_seats_used_changed_at ON gitlab_subscriptions USING btree (max_seats_used_changed_at, namespace_id); -- GitLab