Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20231116201338_add_require_admin_two_factor_authentication_to_application_settings.rb12
-rw-r--r--db/migrate/20231123160255_add_token_to_chat_names.rb (renamed from db/migrate/20231219120134_add_token_to_chat_names.rb)0
-rw-r--r--db/migrate/20231124022520_add_sms_sent_at_and_sms_send_count_to_phone_number_validations.rb16
-rw-r--r--db/migrate/20231129173649_add_terraform_module_duplicates_allowed_to_namespace_package_settings.rb35
-rw-r--r--db/migrate/20231130124606_add_project_id_name_version_id_index_to_installable_terraform_modules.rb23
-rw-r--r--db/migrate/20231205165049_add_slug_to_topics.rb21
-rw-r--r--db/migrate/20231206165856_create_zoekt_enabled_namespaces.rb18
-rw-r--r--db/migrate/20231206184344_create_zoekt_enabled_namespaces_namespace_foreign_key.rb16
-rw-r--r--db/migrate/20231206190206_create_zoekt_indices.rb24
-rw-r--r--db/migrate/20231206191102_create_zoekt_indices_zoekt_node_foreign_key.rb16
-rw-r--r--db/migrate/20231206212252_create_zoekt_indices_zoekt_enabled_namespace_foreign_key.rb17
-rw-r--r--db/migrate/20231212090606_add_partition_id_to_pipeline_chat_data.rb10
-rw-r--r--db/migrate/20231212154022_add_release_published_at_to_release.rb10
-rw-r--r--db/migrate/20231213065249_deprecate_ci_editor_ai_conversation_related_workers.rb20
-rw-r--r--db/migrate/20231213170159_add_remove_project_to_member_roles.rb10
-rw-r--r--db/migrate/20231214095546_add_issue_id_to_epics.rb18
-rw-r--r--db/migrate/20231214222351_drop_index_users_forbidden_state.rb19
-rw-r--r--db/migrate/20231215101640_add_cascading_toggle_security_policies_policy_scope_setting.rb17
-rw-r--r--db/migrate/20231215192706_create_ml_model_version_metadata.rb21
-rw-r--r--db/migrate/20231216190018_add_index_topics_on_slug.rb17
-rw-r--r--db/migrate/20231218172621_add_manage_group_access_tokens_to_member_roles.rb10
-rw-r--r--db/migrate/20231219091924_initialize_conversion_of_geo_event_id_from_int_to_bigint.rb18
-rw-r--r--db/migrate/20231220094609_add_release_published_at_index_to_release.rb14
-rw-r--r--db/migrate/20231220113459_add_work_item_color.rb20
-rw-r--r--db/migrate/20231221033539_create_sbom_source_packages_table.rb42
-rw-r--r--db/migrate/20231221113948_create_cloud_connector_access.rb13
-rw-r--r--db/migrate/20231221171135_create_namespace_descendants_table.rb35
-rw-r--r--db/migrate/20231222071942_add_description_to_ci_instance_variables.rb12
-rw-r--r--db/migrate/20231226052618_add_work_item_colors_foreign_keys.rb18
-rw-r--r--db/migrate/20231227090634_deprecate_summarize_merge_request_worker.rb21
-rw-r--r--db/migrate/20231227103059_replace_fk_on_epics_issue_id.rb20
-rw-r--r--db/migrate/20231227104408_validate_fk_epics_issue_id_with_on_delete_nullify.rb16
-rw-r--r--db/migrate/20231227104711_remove_fk_epics_issue_id.rb21
-rw-r--r--db/migrate/20231229112819_add_finished_at_index_for_p_ci_finished_build_ch_sync_events.rb20
-rw-r--r--db/migrate/20240101031938_add_admin_terraform_state_to_member_roles.rb10
-rw-r--r--db/migrate/20240102184844_add_access_level_to_organization_users.rb9
-rw-r--r--db/migrate/20240103200822_replace_fk_on_approval_merge_request_rules_scan_result_policy_id.rb27
-rw-r--r--db/migrate/20240103202629_validate_fk_on_approval_merge_request_rules_scan_result_policy_id.rb16
-rw-r--r--db/migrate/20240103203314_remove_old_fk_on_approval_merge_request_rules_scan_result_policy_id.rb29
-rw-r--r--db/migrate/20240104124057_add_category_to_timelogs.rb22
-rw-r--r--db/migrate/20240104150106_add_partition_id_to_pipeline_metadata.rb10
-rw-r--r--db/migrate/20240104191736_migrate_zoekt_indexed_namespaces_to_zoekt_enabled_namespaces.rb30
-rw-r--r--db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb46
-rw-r--r--db/migrate/20240105000000_rename_workspace_url_domain_to_dns_zone.rb14
-rw-r--r--db/migrate/20240107084243_add_previous_weight_to_resource_weight_events.rb9
-rw-r--r--db/migrate/20240108121335_copy_internal_ids_for_epics_and_issues_usage_on_groups.rb74
-rw-r--r--db/migrate/20240108123023_create_ai_agents_table.rb18
-rw-r--r--db/migrate/20240108123115_create_ai_agent_versions_table.rb19
-rw-r--r--db/migrate/20240108123509_add_fk_on_ai_agent_versions_to_ai_agents.rb17
-rw-r--r--db/migrate/20240109082354_add_partition_id_to_pipeline_artifact.rb10
-rw-r--r--db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb10
-rw-r--r--db/migrate/20240110085226_add_rate_limits_to_application_settings.rb10
-rw-r--r--db/migrate/20240111134328_routing_table_prepare_async_constraint_for_pipeline_variables.rb33
-rw-r--r--db/migrate/20240115115029_add_rate_limits_hash_constraint_to_application_settings.rb20
54 files changed, 1053 insertions, 0 deletions
diff --git a/db/migrate/20231116201338_add_require_admin_two_factor_authentication_to_application_settings.rb b/db/migrate/20231116201338_add_require_admin_two_factor_authentication_to_application_settings.rb
new file mode 100644
index 00000000000..9f6c4feff34
--- /dev/null
+++ b/db/migrate/20231116201338_add_require_admin_two_factor_authentication_to_application_settings.rb
@@ -0,0 +1,12 @@
+# 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 AddRequireAdminTwoFactorAuthenticationToApplicationSettings < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ def change
+ add_column :application_settings, :require_admin_two_factor_authentication, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20231219120134_add_token_to_chat_names.rb b/db/migrate/20231123160255_add_token_to_chat_names.rb
index af8550b9020..af8550b9020 100644
--- a/db/migrate/20231219120134_add_token_to_chat_names.rb
+++ b/db/migrate/20231123160255_add_token_to_chat_names.rb
diff --git a/db/migrate/20231124022520_add_sms_sent_at_and_sms_send_count_to_phone_number_validations.rb b/db/migrate/20231124022520_add_sms_sent_at_and_sms_send_count_to_phone_number_validations.rb
new file mode 100644
index 00000000000..40508d8da6e
--- /dev/null
+++ b/db/migrate/20231124022520_add_sms_sent_at_and_sms_send_count_to_phone_number_validations.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddSmsSentAtAndSmsSendCountToPhoneNumberValidations < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def up
+ add_column :user_phone_number_validations, :sms_sent_at, :datetime_with_timezone, null: true
+ add_column :user_phone_number_validations, :sms_send_count, :smallint, default: 0, null: false
+ end
+
+ def down
+ remove_column :user_phone_number_validations, :sms_sent_at, if_exists: true
+ remove_column :user_phone_number_validations, :sms_send_count, if_exists: true
+ end
+end
diff --git a/db/migrate/20231129173649_add_terraform_module_duplicates_allowed_to_namespace_package_settings.rb b/db/migrate/20231129173649_add_terraform_module_duplicates_allowed_to_namespace_package_settings.rb
new file mode 100644
index 00000000000..ea465de5873
--- /dev/null
+++ b/db/migrate/20231129173649_add_terraform_module_duplicates_allowed_to_namespace_package_settings.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class AddTerraformModuleDuplicatesAllowedToNamespacePackageSettings < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column(:namespace_package_settings,
+ :terraform_module_duplicates_allowed,
+ :boolean,
+ null: false,
+ default: false,
+ if_not_exists: true
+ )
+
+ add_column(:namespace_package_settings,
+ :terraform_module_duplicate_exception_regex,
+ :text,
+ null: false,
+ default: '',
+ if_not_exists: true
+ )
+ end
+
+ add_text_limit(:namespace_package_settings, :terraform_module_duplicate_exception_regex, 255)
+ end
+
+ def down
+ with_lock_retries do
+ remove_column(:namespace_package_settings, :terraform_module_duplicates_allowed, if_exists: true)
+ remove_column(:namespace_package_settings, :terraform_module_duplicate_exception_regex, if_exists: true)
+ end
+ end
+end
diff --git a/db/migrate/20231130124606_add_project_id_name_version_id_index_to_installable_terraform_modules.rb b/db/migrate/20231130124606_add_project_id_name_version_id_index_to_installable_terraform_modules.rb
new file mode 100644
index 00000000000..0b305843bd5
--- /dev/null
+++ b/db/migrate/20231130124606_add_project_id_name_version_id_index_to_installable_terraform_modules.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddProjectIdNameVersionIdIndexToInstallableTerraformModules < Gitlab::Database::Migration[2.2]
+ milestone '16.7'
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'idx_pkgs_on_project_id_name_version_on_installable_terraform'
+ PACKAGE_TYPE_TERRAFORM_MODULE = 12
+ INSTALLABLE_CONDITION = 'status IN (0, 1)'
+
+ def up
+ add_concurrent_index(
+ :packages_packages,
+ %i[project_id name version id],
+ name: INDEX_NAME,
+ where: "package_type = #{PACKAGE_TYPE_TERRAFORM_MODULE} AND #{INSTALLABLE_CONDITION}"
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name(:packages_packages, INDEX_NAME)
+ end
+end
diff --git a/db/migrate/20231205165049_add_slug_to_topics.rb b/db/migrate/20231205165049_add_slug_to_topics.rb
new file mode 100644
index 00000000000..dedd871473d
--- /dev/null
+++ b/db/migrate/20231205165049_add_slug_to_topics.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddSlugToTopics < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ milestone '16.8'
+
+ def up
+ with_lock_retries do
+ add_column :topics, :slug, :text, if_not_exists: true
+ end
+
+ add_text_limit :topics, :slug, 255
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :topics, :slug, if_exists: true
+ end
+ end
+end
diff --git a/db/migrate/20231206165856_create_zoekt_enabled_namespaces.rb b/db/migrate/20231206165856_create_zoekt_enabled_namespaces.rb
new file mode 100644
index 00000000000..a2a328706f1
--- /dev/null
+++ b/db/migrate/20231206165856_create_zoekt_enabled_namespaces.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class CreateZoektEnabledNamespaces < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ UNIQUE_ROOT_NAMESPACE_ID_INDEX_NAME = 'unique_zoekt_enabled_namespaces_on_root_namespace_id'
+ SEARCH_INDEX_NAME = 'index_zoekt_enabled_namespaces_on_search'
+
+ def change
+ create_table :zoekt_enabled_namespaces do |t|
+ t.bigint :root_namespace_id, null: false
+ t.timestamps_with_timezone null: false
+ t.boolean :search, null: false, default: true
+
+ t.index :root_namespace_id, unique: true, name: UNIQUE_ROOT_NAMESPACE_ID_INDEX_NAME, using: :btree
+ end
+ end
+end
diff --git a/db/migrate/20231206184344_create_zoekt_enabled_namespaces_namespace_foreign_key.rb b/db/migrate/20231206184344_create_zoekt_enabled_namespaces_namespace_foreign_key.rb
new file mode 100644
index 00000000000..93e3cd5433a
--- /dev/null
+++ b/db/migrate/20231206184344_create_zoekt_enabled_namespaces_namespace_foreign_key.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateZoektEnabledNamespacesNamespaceForeignKey < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ def up
+ add_concurrent_foreign_key :zoekt_enabled_namespaces, :namespaces, column: :root_namespace_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :zoekt_enabled_namespaces, column: :root_namespace_id
+ end
+ end
+end
diff --git a/db/migrate/20231206190206_create_zoekt_indices.rb b/db/migrate/20231206190206_create_zoekt_indices.rb
new file mode 100644
index 00000000000..05549f7c152
--- /dev/null
+++ b/db/migrate/20231206190206_create_zoekt_indices.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class CreateZoektIndices < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ ZOEKT_NODE_ID_INDEX_NAME = 'index_zoekt_indices_on_zoekt_node_id'
+ STATE_INDEX_NAME = 'index_zoekt_indices_on_state'
+ ZOEKT_ENABLED_NAMESPACE_ID_AND_NODE_ID_INDEX_NAME = 'u_zoekt_indices_zoekt_enabled_namespace_id_and_zoekt_node_id'
+
+ def change
+ create_table :zoekt_indices do |t|
+ t.bigint :zoekt_enabled_namespace_id, null: true
+ t.bigint :zoekt_node_id, null: false
+ t.bigint :namespace_id, null: false
+ t.timestamps_with_timezone null: false
+ t.integer :state, null: false, default: 0, limit: 2
+
+ t.index :state, name: STATE_INDEX_NAME, using: :btree
+ t.index :zoekt_node_id, name: ZOEKT_NODE_ID_INDEX_NAME, using: :btree
+ t.index [:zoekt_enabled_namespace_id, :zoekt_node_id],
+ name: ZOEKT_ENABLED_NAMESPACE_ID_AND_NODE_ID_INDEX_NAME, unique: true, using: :btree
+ end
+ end
+end
diff --git a/db/migrate/20231206191102_create_zoekt_indices_zoekt_node_foreign_key.rb b/db/migrate/20231206191102_create_zoekt_indices_zoekt_node_foreign_key.rb
new file mode 100644
index 00000000000..389e52e37a6
--- /dev/null
+++ b/db/migrate/20231206191102_create_zoekt_indices_zoekt_node_foreign_key.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateZoektIndicesZoektNodeForeignKey < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ def up
+ add_concurrent_foreign_key :zoekt_indices, :zoekt_nodes, column: :zoekt_node_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :zoekt_indices, column: :zoekt_node_id
+ end
+ end
+end
diff --git a/db/migrate/20231206212252_create_zoekt_indices_zoekt_enabled_namespace_foreign_key.rb b/db/migrate/20231206212252_create_zoekt_indices_zoekt_enabled_namespace_foreign_key.rb
new file mode 100644
index 00000000000..c36849cec0a
--- /dev/null
+++ b/db/migrate/20231206212252_create_zoekt_indices_zoekt_enabled_namespace_foreign_key.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class CreateZoektIndicesZoektEnabledNamespaceForeignKey < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ def up
+ add_concurrent_foreign_key :zoekt_indices, :zoekt_enabled_namespaces,
+ column: :zoekt_enabled_namespace_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :zoekt_indices, column: :zoekt_enabled_namespace_id
+ end
+ end
+end
diff --git a/db/migrate/20231212090606_add_partition_id_to_pipeline_chat_data.rb b/db/migrate/20231212090606_add_partition_id_to_pipeline_chat_data.rb
new file mode 100644
index 00000000000..bf3c87f9816
--- /dev/null
+++ b/db/migrate/20231212090606_add_partition_id_to_pipeline_chat_data.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddPartitionIdToPipelineChatData < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column(:ci_pipeline_chat_data, :partition_id, :bigint, default: 100, null: false)
+ end
+end
diff --git a/db/migrate/20231212154022_add_release_published_at_to_release.rb b/db/migrate/20231212154022_add_release_published_at_to_release.rb
new file mode 100644
index 00000000000..8ecb51a8cf1
--- /dev/null
+++ b/db/migrate/20231212154022_add_release_published_at_to_release.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddReleasePublishedAtToRelease < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column :releases, :release_published_at, :datetime_with_timezone
+ end
+end
diff --git a/db/migrate/20231213065249_deprecate_ci_editor_ai_conversation_related_workers.rb b/db/migrate/20231213065249_deprecate_ci_editor_ai_conversation_related_workers.rb
new file mode 100644
index 00000000000..f0dd4775eb1
--- /dev/null
+++ b/db/migrate/20231213065249_deprecate_ci_editor_ai_conversation_related_workers.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class DeprecateCiEditorAiConversationRelatedWorkers < Gitlab::Database::Migration[2.2]
+ DEPRECATED_JOB_CLASSES = %w[
+ Ci::LLM::GenerateConfigWorker
+ OpenAi::ClearConversationsWorker
+ ]
+
+ disable_ddl_transaction!
+
+ milestone '16.8'
+
+ def up
+ sidekiq_remove_jobs(job_klasses: DEPRECATED_JOB_CLASSES)
+ end
+
+ def down
+ # This migration removes any instances of deprecated workers and cannot be undone.
+ end
+end
diff --git a/db/migrate/20231213170159_add_remove_project_to_member_roles.rb b/db/migrate/20231213170159_add_remove_project_to_member_roles.rb
new file mode 100644
index 00000000000..d13777c1df1
--- /dev/null
+++ b/db/migrate/20231213170159_add_remove_project_to_member_roles.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddRemoveProjectToMemberRoles < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column :member_roles, :remove_project, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20231214095546_add_issue_id_to_epics.rb b/db/migrate/20231214095546_add_issue_id_to_epics.rb
new file mode 100644
index 00000000000..0db34041726
--- /dev/null
+++ b/db/migrate/20231214095546_add_issue_id_to_epics.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIssueIdToEpics < Gitlab::Database::Migration[2.2]
+ INDEX_NAME = 'index_unique_epics_on_issue_id'
+
+ disable_ddl_transaction!
+ milestone '16.7'
+
+ def up
+ add_column :epics, :issue_id, :int, if_not_exists: true
+ add_concurrent_index :epics, :issue_id, unique: true, name: INDEX_NAME
+ add_concurrent_foreign_key(:epics, :issues, column: :issue_id, validate: true)
+ end
+
+ def down
+ remove_column :epics, :issue_id, if_exists: true
+ end
+end
diff --git a/db/migrate/20231214222351_drop_index_users_forbidden_state.rb b/db/migrate/20231214222351_drop_index_users_forbidden_state.rb
new file mode 100644
index 00000000000..aa51702c93e
--- /dev/null
+++ b/db/migrate/20231214222351_drop_index_users_forbidden_state.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class DropIndexUsersForbiddenState < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ disable_ddl_transaction!
+
+ INDEX_NAME = :users_forbidden_state_idx
+ TABLE_NAME = :users
+
+ def up
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index TABLE_NAME, :id,
+ name: INDEX_NAME,
+ where: "confirmed_at IS NOT NULL AND (state <> ALL (ARRAY['blocked', 'banned', 'ldap_blocked']))"
+ end
+end
diff --git a/db/migrate/20231215101640_add_cascading_toggle_security_policies_policy_scope_setting.rb b/db/migrate/20231215101640_add_cascading_toggle_security_policies_policy_scope_setting.rb
new file mode 100644
index 00000000000..9ef0c70173b
--- /dev/null
+++ b/db/migrate/20231215101640_add_cascading_toggle_security_policies_policy_scope_setting.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddCascadingToggleSecurityPoliciesPolicyScopeSetting < Gitlab::Database::Migration[2.2]
+ milestone '16.7'
+
+ include Gitlab::Database::MigrationHelpers::CascadingNamespaceSettings
+
+ enable_lock_retries!
+
+ def up
+ add_cascading_namespace_setting :toggle_security_policies_policy_scope, :boolean, default: false, null: false
+ end
+
+ def down
+ remove_cascading_namespace_setting :toggle_security_policies_policy_scope
+ end
+end
diff --git a/db/migrate/20231215192706_create_ml_model_version_metadata.rb b/db/migrate/20231215192706_create_ml_model_version_metadata.rb
new file mode 100644
index 00000000000..a4c0b08a2ee
--- /dev/null
+++ b/db/migrate/20231215192706_create_ml_model_version_metadata.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class CreateMlModelVersionMetadata < Gitlab::Database::Migration[2.2]
+ ML_MODEL_VERSION_METADATA_NAME_INDEX_NAME = "unique_index_ml_model_version_metadata_name"
+ milestone '16.8'
+
+ def change
+ create_table :ml_model_version_metadata do |t|
+ t.timestamps_with_timezone null: false
+ t.references :project, foreign_key: { on_delete: :cascade }, index: true, null: false
+ t.references :model_version,
+ foreign_key: { to_table: :ml_model_versions, on_delete: :cascade },
+ index: false,
+ null: false
+ t.text :name, limit: 255, null: false
+ t.text :value, limit: 5000, null: false
+
+ t.index [:model_version_id, :name], unique: true, name: ML_MODEL_VERSION_METADATA_NAME_INDEX_NAME
+ end
+ end
+end
diff --git a/db/migrate/20231216190018_add_index_topics_on_slug.rb b/db/migrate/20231216190018_add_index_topics_on_slug.rb
new file mode 100644
index 00000000000..f83d733c008
--- /dev/null
+++ b/db/migrate/20231216190018_add_index_topics_on_slug.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexTopicsOnSlug < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ milestone '16.8'
+
+ INDEX_NAME = 'index_topics_on_slug'
+
+ def up
+ add_concurrent_index :topics, :slug, unique: true, where: 'slug IS NOT NULL', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :topics, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20231218172621_add_manage_group_access_tokens_to_member_roles.rb b/db/migrate/20231218172621_add_manage_group_access_tokens_to_member_roles.rb
new file mode 100644
index 00000000000..58f9f94a880
--- /dev/null
+++ b/db/migrate/20231218172621_add_manage_group_access_tokens_to_member_roles.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddManageGroupAccessTokensToMemberRoles < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column :member_roles, :manage_group_access_tokens, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20231219091924_initialize_conversion_of_geo_event_id_from_int_to_bigint.rb b/db/migrate/20231219091924_initialize_conversion_of_geo_event_id_from_int_to_bigint.rb
new file mode 100644
index 00000000000..10d67394435
--- /dev/null
+++ b/db/migrate/20231219091924_initialize_conversion_of_geo_event_id_from_int_to_bigint.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class InitializeConversionOfGeoEventIdFromIntToBigint < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ disable_ddl_transaction!
+
+ TABLE = :geo_event_log
+ COLUMNS = %i[geo_event_id]
+
+ def up
+ initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+end
diff --git a/db/migrate/20231220094609_add_release_published_at_index_to_release.rb b/db/migrate/20231220094609_add_release_published_at_index_to_release.rb
new file mode 100644
index 00000000000..bc5891ad198
--- /dev/null
+++ b/db/migrate/20231220094609_add_release_published_at_index_to_release.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddReleasePublishedAtIndexToRelease < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :releases, :release_published_at, name: 'releases_published_at_index'
+ end
+
+ def down
+ remove_concurrent_index :releases, :release_published_at, name: 'releases_published_at_index'
+ end
+end
diff --git a/db/migrate/20231220113459_add_work_item_color.rb b/db/migrate/20231220113459_add_work_item_color.rb
new file mode 100644
index 00000000000..127f93f41ea
--- /dev/null
+++ b/db/migrate/20231220113459_add_work_item_color.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddWorkItemColor < Gitlab::Database::Migration[2.2]
+ enable_lock_retries!
+ milestone '16.8'
+
+ def up
+ create_table :work_item_colors, id: false do |t|
+ t.timestamps_with_timezone null: false
+ t.references :issue, primary_key: true, index: false, default: nil,
+ foreign_key: { on_delete: :cascade, to_table: :issues }
+ t.bigint :namespace_id, null: false
+ t.text :color, null: false, limit: 7
+ end
+ end
+
+ def down
+ drop_table :work_item_colors
+ end
+end
diff --git a/db/migrate/20231221033539_create_sbom_source_packages_table.rb b/db/migrate/20231221033539_create_sbom_source_packages_table.rb
new file mode 100644
index 00000000000..6e2389baf8e
--- /dev/null
+++ b/db/migrate/20231221033539_create_sbom_source_packages_table.rb
@@ -0,0 +1,42 @@
+# 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 CreateSbomSourcePackagesTable < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ SBOM_SOURCE_PACKAGES_INDEX_NAME = 'idx_sbom_source_packages_on_name_and_purl_type'
+ SBOM_OCCURRENCES_SOURCE_PACKAGE_ID_AND_ID_INDEX_NAME = 'index_sbom_source_packages_on_source_package_id_and_id'
+
+ def up
+ with_lock_retries do
+ add_column :sbom_occurrences, :source_package_id, :bigint, if_not_exists: true
+ end
+
+ create_table :sbom_source_packages, if_not_exists: true do |t|
+ t.text :name, null: false, limit: 255
+ t.integer :purl_type, limit: 2, null: false
+ t.index [:name, :purl_type], unique: true, name: SBOM_SOURCE_PACKAGES_INDEX_NAME
+ end
+
+ add_concurrent_index :sbom_occurrences, [:source_package_id, :id],
+ name: SBOM_OCCURRENCES_SOURCE_PACKAGE_ID_AND_ID_INDEX_NAME
+
+ add_concurrent_foreign_key :sbom_occurrences, :sbom_source_packages,
+ column: :source_package_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ :sbom_occurrences,
+ column: :source_package_id,
+ on_delete: :cascade
+ )
+ remove_column :sbom_occurrences, :source_package_id, if_exists: true
+ drop_table :sbom_source_packages, if_exists: true
+ end
+ end
+end
diff --git a/db/migrate/20231221113948_create_cloud_connector_access.rb b/db/migrate/20231221113948_create_cloud_connector_access.rb
new file mode 100644
index 00000000000..0b3950fc51d
--- /dev/null
+++ b/db/migrate/20231221113948_create_cloud_connector_access.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class CreateCloudConnectorAccess < Gitlab::Database::Migration[2.2]
+ enable_lock_retries!
+ milestone '16.8'
+
+ def change
+ create_table :cloud_connector_access do |t|
+ t.timestamps_with_timezone null: false
+ t.jsonb :data, null: false
+ end
+ end
+end
diff --git a/db/migrate/20231221171135_create_namespace_descendants_table.rb b/db/migrate/20231221171135_create_namespace_descendants_table.rb
new file mode 100644
index 00000000000..5201b132582
--- /dev/null
+++ b/db/migrate/20231221171135_create_namespace_descendants_table.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class CreateNamespaceDescendantsTable < Gitlab::Database::Migration[2.2]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ milestone '16.8'
+
+ def up
+ execute <<~SQL
+ CREATE TABLE namespace_descendants (
+ namespace_id bigint NOT NULL,
+ self_and_descendant_group_ids bigint[] NOT NULL DEFAULT ARRAY[]::bigint[],
+ all_project_ids bigint[] NOT NULL DEFAULT ARRAY[]::bigint[],
+ traversal_ids bigint[] NOT NULL DEFAULT ARRAY[]::bigint[],
+ outdated_at timestamp with time zone,
+ calculated_at timestamp with time zone,
+ PRIMARY KEY(namespace_id)
+ )
+ PARTITION BY HASH (namespace_id);
+ SQL
+
+ execute <<~SQL
+ CREATE INDEX
+ index_on_namespace_descendants_outdated
+ ON namespace_descendants (namespace_id)
+ WHERE outdated_at IS NOT NULL
+ SQL
+
+ create_hash_partitions(:namespace_descendants, 32)
+ end
+
+ def down
+ drop_table :namespace_descendants
+ end
+end
diff --git a/db/migrate/20231222071942_add_description_to_ci_instance_variables.rb b/db/migrate/20231222071942_add_description_to_ci_instance_variables.rb
new file mode 100644
index 00000000000..e71f27411eb
--- /dev/null
+++ b/db/migrate/20231222071942_add_description_to_ci_instance_variables.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class AddDescriptionToCiInstanceVariables < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ # rubocop:disable Migration/AddLimitToTextColumns -- text limit is added in 20231222072237_add_text_limit_to_ci_instance_variables_description.rb migration
+ def change
+ add_column(:ci_instance_variables, :description, :text)
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+end
diff --git a/db/migrate/20231226052618_add_work_item_colors_foreign_keys.rb b/db/migrate/20231226052618_add_work_item_colors_foreign_keys.rb
new file mode 100644
index 00000000000..4fa0806a28a
--- /dev/null
+++ b/db/migrate/20231226052618_add_work_item_colors_foreign_keys.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddWorkItemColorsForeignKeys < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ TABLE = :work_item_colors
+
+ def up
+ add_concurrent_index TABLE, :namespace_id, name: "wi_colors_namespace_id_index"
+ add_concurrent_foreign_key TABLE, :namespaces, column: :namespace_id, on_delete: :nullify
+ end
+
+ def down
+ remove_concurrent_index_by_name TABLE, name: "wi_colors_namespace_id_index"
+ remove_foreign_key_if_exists TABLE, :namespaces, column: :namespace_id
+ end
+end
diff --git a/db/migrate/20231227090634_deprecate_summarize_merge_request_worker.rb b/db/migrate/20231227090634_deprecate_summarize_merge_request_worker.rb
new file mode 100644
index 00000000000..b201028762c
--- /dev/null
+++ b/db/migrate/20231227090634_deprecate_summarize_merge_request_worker.rb
@@ -0,0 +1,21 @@
+# 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 DeprecateSummarizeMergeRequestWorker < Gitlab::Database::Migration[2.2]
+ DEPRECATED_JOB_CLASSES = %w[
+ MergeRequests::Llm::SummarizeMergeRequestWorker
+ ]
+
+ milestone '16.8'
+ disable_ddl_transaction!
+
+ def up
+ sidekiq_remove_jobs(job_klasses: DEPRECATED_JOB_CLASSES)
+ end
+
+ def down
+ # This migration removes any instances of deprecated workers and cannot be undone.
+ end
+end
diff --git a/db/migrate/20231227103059_replace_fk_on_epics_issue_id.rb b/db/migrate/20231227103059_replace_fk_on_epics_issue_id.rb
new file mode 100644
index 00000000000..e5dd4e868f0
--- /dev/null
+++ b/db/migrate/20231227103059_replace_fk_on_epics_issue_id.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class ReplaceFkOnEpicsIssueId < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ milestone '16.8'
+
+ FK_NAME = :fk_epics_issue_id_with_on_delete_nullify
+
+ def up
+ # This will replace the existing fk_893ee302e5
+ add_concurrent_foreign_key(:epics, :issues, column: :issue_id, on_delete: :nullify, validate: false, name: FK_NAME)
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(:epics, column: :issue_id, on_delete: :nullify, name: FK_NAME)
+ end
+ end
+end
diff --git a/db/migrate/20231227104408_validate_fk_epics_issue_id_with_on_delete_nullify.rb b/db/migrate/20231227104408_validate_fk_epics_issue_id_with_on_delete_nullify.rb
new file mode 100644
index 00000000000..9f7601a704b
--- /dev/null
+++ b/db/migrate/20231227104408_validate_fk_epics_issue_id_with_on_delete_nullify.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class ValidateFkEpicsIssueIdWithOnDeleteNullify < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ FK_NAME = :fk_epics_issue_id_with_on_delete_nullify
+
+ # foreign key added in db/migrate/20231227103059_replace_fk_on_epics_issue_id.rb
+ def up
+ validate_foreign_key(:epics, :issue_id, name: FK_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20231227104711_remove_fk_epics_issue_id.rb b/db/migrate/20231227104711_remove_fk_epics_issue_id.rb
new file mode 100644
index 00000000000..29752e8741c
--- /dev/null
+++ b/db/migrate/20231227104711_remove_fk_epics_issue_id.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RemoveFkEpicsIssueId < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ milestone '16.8'
+
+ FK_NAME = :fk_893ee302e5
+
+ # new foreign key added in db/migrate/20231227103059_replace_fk_on_epics_issue_id.rb
+ # and validated in db/migrate/20231227104408_validate_fk_epics_issue_id_with_on_delete_nullify.rb
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:epics, column: :issue_id, on_delete: :cascade, name: FK_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:epics, :issues, column: :issue_id, on_delete: :cascade, validate: false, name: FK_NAME)
+ end
+end
diff --git a/db/migrate/20231229112819_add_finished_at_index_for_p_ci_finished_build_ch_sync_events.rb b/db/migrate/20231229112819_add_finished_at_index_for_p_ci_finished_build_ch_sync_events.rb
new file mode 100644
index 00000000000..f52c1abcd49
--- /dev/null
+++ b/db/migrate/20231229112819_add_finished_at_index_for_p_ci_finished_build_ch_sync_events.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddFinishedAtIndexForPCiFinishedBuildChSyncEvents < Gitlab::Database::Migration[2.2]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ INDEX_NAME = :index_p_ci_finished_build_ch_sync_events_finished_at
+ TABLE_NAME = :p_ci_finished_build_ch_sync_events
+ COLUMNS = [:partition, :build_finished_at]
+
+ def up
+ add_concurrent_partitioned_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_partitioned_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/migrate/20240101031938_add_admin_terraform_state_to_member_roles.rb b/db/migrate/20240101031938_add_admin_terraform_state_to_member_roles.rb
new file mode 100644
index 00000000000..89222664d01
--- /dev/null
+++ b/db/migrate/20240101031938_add_admin_terraform_state_to_member_roles.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddAdminTerraformStateToMemberRoles < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column :member_roles, :admin_terraform_state, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20240102184844_add_access_level_to_organization_users.rb b/db/migrate/20240102184844_add_access_level_to_organization_users.rb
new file mode 100644
index 00000000000..8e37d056e56
--- /dev/null
+++ b/db/migrate/20240102184844_add_access_level_to_organization_users.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddAccessLevelToOrganizationUsers < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ def change
+ add_column :organization_users, :access_level, :integer, default: 10, limit: 2, null: false
+ end
+end
diff --git a/db/migrate/20240103200822_replace_fk_on_approval_merge_request_rules_scan_result_policy_id.rb b/db/migrate/20240103200822_replace_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
new file mode 100644
index 00000000000..431183e7212
--- /dev/null
+++ b/db/migrate/20240103200822_replace_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class ReplaceFkOnApprovalMergeRequestRulesScanResultPolicyId < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ NEW_CONSTRAINT_NAME = 'fk_approval_merge_request_rules_on_scan_result_policy_id'
+
+ def up
+ add_concurrent_foreign_key(
+ :approval_merge_request_rules,
+ :scan_result_policies,
+ column: :scan_result_policy_id,
+ on_delete: :nullify,
+ validate: false,
+ name: NEW_CONSTRAINT_NAME)
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(:approval_merge_request_rules,
+ column: :scan_result_policy_id,
+ on_delete: :nullify,
+ name: NEW_CONSTRAINT_NAME)
+ end
+ end
+end
diff --git a/db/migrate/20240103202629_validate_fk_on_approval_merge_request_rules_scan_result_policy_id.rb b/db/migrate/20240103202629_validate_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
new file mode 100644
index 00000000000..fee02ce91de
--- /dev/null
+++ b/db/migrate/20240103202629_validate_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class ValidateFkOnApprovalMergeRequestRulesScanResultPolicyId < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ NEW_CONSTRAINT_NAME = 'fk_approval_merge_request_rules_on_scan_result_policy_id'
+
+ # foreign key added in db/migrate/20240103200822_replace_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
+ def up
+ validate_foreign_key(:approval_merge_request_rules, :scan_result_policy_id, name: NEW_CONSTRAINT_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20240103203314_remove_old_fk_on_approval_merge_request_rules_scan_result_policy_id.rb b/db/migrate/20240103203314_remove_old_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
new file mode 100644
index 00000000000..7758b230242
--- /dev/null
+++ b/db/migrate/20240103203314_remove_old_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class RemoveOldFkOnApprovalMergeRequestRulesScanResultPolicyId < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.8'
+
+ OLD_CONSTRAINT_NAME = 'fk_f726c79756'
+
+ # new foreign key added in
+ # db/migrate/20240103200822_replace_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
+ # and validated in db/migrate/20240103202629_validate_fk_on_approval_merge_request_rules_scan_result_policy_id.rb
+ def up
+ remove_foreign_key_if_exists(
+ :approval_merge_request_rules,
+ column: :scan_result_policy_id,
+ on_delete: :cascade,
+ name: OLD_CONSTRAINT_NAME)
+ end
+
+ def down
+ add_concurrent_foreign_key(
+ :approval_merge_request_rules,
+ :scan_result_policies,
+ column: :scan_result_policy_id,
+ on_delete: :cascade,
+ validate: false,
+ name: OLD_CONSTRAINT_NAME)
+ end
+end
diff --git a/db/migrate/20240104124057_add_category_to_timelogs.rb b/db/migrate/20240104124057_add_category_to_timelogs.rb
new file mode 100644
index 00000000000..adda5fef873
--- /dev/null
+++ b/db/migrate/20240104124057_add_category_to_timelogs.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddCategoryToTimelogs < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ milestone '16.8'
+
+ def up
+ add_column :timelogs, :timelog_category_id, :bigint
+ add_concurrent_index(:timelogs, :timelog_category_id)
+ add_concurrent_foreign_key(
+ :timelogs,
+ :timelog_categories,
+ column: :timelog_category_id,
+ on_delete: :nullify
+ )
+ end
+
+ def down
+ remove_column :timelogs, :timelog_category_id
+ end
+end
diff --git a/db/migrate/20240104150106_add_partition_id_to_pipeline_metadata.rb b/db/migrate/20240104150106_add_partition_id_to_pipeline_metadata.rb
new file mode 100644
index 00000000000..cdada059306
--- /dev/null
+++ b/db/migrate/20240104150106_add_partition_id_to_pipeline_metadata.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddPartitionIdToPipelineMetadata < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column(:ci_pipeline_metadata, :partition_id, :bigint, default: 100, null: false)
+ end
+end
diff --git a/db/migrate/20240104191736_migrate_zoekt_indexed_namespaces_to_zoekt_enabled_namespaces.rb b/db/migrate/20240104191736_migrate_zoekt_indexed_namespaces_to_zoekt_enabled_namespaces.rb
new file mode 100644
index 00000000000..3c3ef67e322
--- /dev/null
+++ b/db/migrate/20240104191736_migrate_zoekt_indexed_namespaces_to_zoekt_enabled_namespaces.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class MigrateZoektIndexedNamespacesToZoektEnabledNamespaces < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ milestone '16.8'
+
+ INSERTED_COLUMNS = %w[
+ root_namespace_id
+ search
+ created_at
+ updated_at
+ ].join(',')
+
+ def up
+ connection.execute(<<~SQL)
+ INSERT INTO zoekt_enabled_namespaces (#{INSERTED_COLUMNS})
+ (SELECT DISTINCT ON (namespace_id) namespace_id, search, created_at, updated_at
+ FROM zoekt_indexed_namespaces ORDER BY namespace_id, search)
+ SQL
+ end
+
+ def down
+ connection.execute(<<~SQL)
+ DELETE FROM zoekt_enabled_namespaces
+ SQL
+ end
+end
diff --git a/db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb b/db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb
new file mode 100644
index 00000000000..5461ad5094b
--- /dev/null
+++ b/db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+class MigrateZoektIndexedNamespacesToZoektIndices < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ milestone '16.8'
+
+ INSERTED_COLUMNS = %w[
+ zoekt_enabled_namespace_id
+ namespace_id
+ zoekt_node_id
+ state
+ created_at
+ updated_at
+ ].join(',')
+
+ STATE_READY = 10
+
+ def up
+ connection.execute(<<~SQL)
+ WITH indexed_namespaces AS (
+ (SELECT DISTINCT ON (namespace_id) namespace_id, search, zoekt_node_id
+ FROM zoekt_indexed_namespaces ORDER BY namespace_id, search)
+ )
+
+ INSERT INTO zoekt_indices (#{INSERTED_COLUMNS})
+ SELECT
+ zoekt_enabled_namespaces.id,
+ indexed_namespaces.namespace_id,
+ indexed_namespaces.zoekt_node_id,
+ #{STATE_READY},
+ NOW(),
+ NOW()
+ FROM zoekt_enabled_namespaces
+ JOIN indexed_namespaces ON indexed_namespaces.namespace_id = zoekt_enabled_namespaces.root_namespace_id
+ SQL
+ end
+
+ def down
+ connection.execute(<<~SQL)
+ DELETE FROM zoekt_indices
+ SQL
+ end
+end
diff --git a/db/migrate/20240105000000_rename_workspace_url_domain_to_dns_zone.rb b/db/migrate/20240105000000_rename_workspace_url_domain_to_dns_zone.rb
new file mode 100644
index 00000000000..72e7ea566a8
--- /dev/null
+++ b/db/migrate/20240105000000_rename_workspace_url_domain_to_dns_zone.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class RenameWorkspaceUrlDomainToDnsZone < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ disable_ddl_transaction!
+
+ def up
+ rename_column_concurrently :workspaces, :url_domain, :dns_zone
+ end
+
+ def down
+ undo_rename_column_concurrently :workspaces, :url_domain, :dns_zone
+ end
+end
diff --git a/db/migrate/20240107084243_add_previous_weight_to_resource_weight_events.rb b/db/migrate/20240107084243_add_previous_weight_to_resource_weight_events.rb
new file mode 100644
index 00000000000..913f96933af
--- /dev/null
+++ b/db/migrate/20240107084243_add_previous_weight_to_resource_weight_events.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddPreviousWeightToResourceWeightEvents < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ def change
+ add_column :resource_weight_events, :previous_weight, :integer
+ end
+end
diff --git a/db/migrate/20240108121335_copy_internal_ids_for_epics_and_issues_usage_on_groups.rb b/db/migrate/20240108121335_copy_internal_ids_for_epics_and_issues_usage_on_groups.rb
new file mode 100644
index 00000000000..205f7b88026
--- /dev/null
+++ b/db/migrate/20240108121335_copy_internal_ids_for_epics_and_issues_usage_on_groups.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+class CopyInternalIdsForEpicsAndIssuesUsageOnGroups < Gitlab::Database::Migration[2.2]
+ include Gitlab::Database::SchemaHelpers
+
+ milestone '16.8'
+ disable_ddl_transaction!
+
+ TRIGGER_ON_INSERT = 'trigger_copy_usage_on_internal_ids_on_insert'
+ TRIGGER_ON_UPDATE = 'trigger_copy_usage_on_internal_ids_on_update'
+ INSERT_OR_UPDATE_FUNCTION_NAME = 'insert_or_update_internal_ids_usage'
+
+ def up
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION #{INSERT_OR_UPDATE_FUNCTION_NAME}()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+ DECLARE
+ namespace_type varchar;
+ copy_usage smallint;
+ BEGIN
+ IF (NEW.usage = 0) THEN
+ copy_usage = 4;
+
+ -- we only care about group level internal_ids so we check namespace type here
+ namespace_type = (SELECT type FROM namespaces WHERE id = NEW.namespace_id);
+ IF (namespace_type <> 'Group') THEN
+ RETURN NULL;
+ END IF;
+ ELSIF (NEW.usage = 4) THEN
+ copy_usage = 0;
+ ELSE
+ RETURN NULL;
+ END IF;
+
+ -- if value is the same there is nothing to update
+ IF (OLD.last_value = NEW.last_value AND (TG_OP = 'INSERT' OR TG_OP = 'UPDATE')) THEN
+ RETURN NULL;
+ END IF;
+
+ INSERT INTO internal_ids (usage, last_value, namespace_id)
+ VALUES (copy_usage, NEW.last_value, NEW.namespace_id)
+ ON CONFLICT (usage, namespace_id) WHERE namespace_id IS NOT NULL
+ DO UPDATE SET last_value = NEW.last_value;
+
+ RETURN NULL;
+ END
+ $$
+ SQL
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{TRIGGER_ON_INSERT}
+ AFTER INSERT ON internal_ids
+ FOR EACH ROW
+ WHEN (((NEW.usage = 0) OR (NEW.usage = 4)) AND NEW.namespace_id IS NOT NULL)
+ EXECUTE FUNCTION #{INSERT_OR_UPDATE_FUNCTION_NAME}();
+ SQL
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{TRIGGER_ON_UPDATE}
+ AFTER UPDATE ON internal_ids
+ FOR EACH ROW
+ WHEN (((NEW.usage = 0) OR (NEW.usage = 4)) AND NEW.namespace_id IS NOT NULL)
+ EXECUTE FUNCTION #{INSERT_OR_UPDATE_FUNCTION_NAME}();
+ SQL
+ end
+
+ def down
+ drop_trigger(:internal_ids, TRIGGER_ON_INSERT)
+ drop_trigger(:internal_ids, TRIGGER_ON_UPDATE)
+ drop_function(INSERT_OR_UPDATE_FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20240108123023_create_ai_agents_table.rb b/db/migrate/20240108123023_create_ai_agents_table.rb
new file mode 100644
index 00000000000..87d43af3a30
--- /dev/null
+++ b/db/migrate/20240108123023_create_ai_agents_table.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class CreateAiAgentsTable < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ def change
+ create_table :ai_agents do |t|
+ t.timestamps_with_timezone null: false
+ # Queries by project_id are covered by the project_id, name index
+ # because project_id is the leftmost column.
+ t.references :project, foreign_key: { on_delete: :cascade }, index: false, null: false
+
+ t.text :name, limit: 255, null: false
+
+ t.index [:project_id, :name], unique: true
+ end
+ end
+end
diff --git a/db/migrate/20240108123115_create_ai_agent_versions_table.rb b/db/migrate/20240108123115_create_ai_agent_versions_table.rb
new file mode 100644
index 00000000000..bfb09ec03e8
--- /dev/null
+++ b/db/migrate/20240108123115_create_ai_agent_versions_table.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class CreateAiAgentVersionsTable < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ def change
+ create_table :ai_agent_versions do |t|
+ t.timestamps_with_timezone null: false
+ t.references :project, foreign_key: { on_delete: :cascade }, index: true, null: false
+
+ t.bigint :agent_id, null: false # fk cascade
+
+ t.text :prompt, limit: 5000, null: false
+ t.text :model, limit: 255, null: false
+
+ t.index :agent_id
+ end
+ end
+end
diff --git a/db/migrate/20240108123509_add_fk_on_ai_agent_versions_to_ai_agents.rb b/db/migrate/20240108123509_add_fk_on_ai_agent_versions_to_ai_agents.rb
new file mode 100644
index 00000000000..cf7c49c2db4
--- /dev/null
+++ b/db/migrate/20240108123509_add_fk_on_ai_agent_versions_to_ai_agents.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddFkOnAiAgentVersionsToAiAgents < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key(:ai_agent_versions, :ai_agents, column: :agent_id, on_delete: :cascade)
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ai_agent_versions, column: :agent_id, on_delete: :cascade)
+ end
+ end
+end
diff --git a/db/migrate/20240109082354_add_partition_id_to_pipeline_artifact.rb b/db/migrate/20240109082354_add_partition_id_to_pipeline_artifact.rb
new file mode 100644
index 00000000000..8a922aed648
--- /dev/null
+++ b/db/migrate/20240109082354_add_partition_id_to_pipeline_artifact.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddPartitionIdToPipelineArtifact < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column(:ci_pipeline_artifacts, :partition_id, :bigint, default: 100, null: false)
+ end
+end
diff --git a/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb b/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb
new file mode 100644
index 00000000000..e4f661a5e31
--- /dev/null
+++ b/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddPartitionIdToPipelineConfig < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ enable_lock_retries!
+
+ def change
+ add_column(:ci_pipelines_config, :partition_id, :bigint, default: 100, null: false)
+ end
+end
diff --git a/db/migrate/20240110085226_add_rate_limits_to_application_settings.rb b/db/migrate/20240110085226_add_rate_limits_to_application_settings.rb
new file mode 100644
index 00000000000..2560977f979
--- /dev/null
+++ b/db/migrate/20240110085226_add_rate_limits_to_application_settings.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddRateLimitsToApplicationSettings < Gitlab::Database::Migration[2.2]
+ milestone '16.9'
+ enable_lock_retries!
+
+ def change
+ add_column :application_settings, :rate_limits, :jsonb, default: {}, null: false
+ end
+end
diff --git a/db/migrate/20240111134328_routing_table_prepare_async_constraint_for_pipeline_variables.rb b/db/migrate/20240111134328_routing_table_prepare_async_constraint_for_pipeline_variables.rb
new file mode 100644
index 00000000000..4cf3d9c1721
--- /dev/null
+++ b/db/migrate/20240111134328_routing_table_prepare_async_constraint_for_pipeline_variables.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class RoutingTablePrepareAsyncConstraintForPipelineVariables < Gitlab::Database::Migration[2.2]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ milestone '16.8'
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_pipeline_variables
+ PARENT_TABLE_NAME = :p_ci_pipeline_variables
+ FIRST_PARTITION = [100, 101]
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ prepare_constraint_for_list_partitioning(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION,
+ async: true
+ )
+ end
+
+ def down
+ revert_preparing_constraint_for_list_partitioning(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION
+ )
+ end
+end
diff --git a/db/migrate/20240115115029_add_rate_limits_hash_constraint_to_application_settings.rb b/db/migrate/20240115115029_add_rate_limits_hash_constraint_to_application_settings.rb
new file mode 100644
index 00000000000..14ab736b5d2
--- /dev/null
+++ b/db/migrate/20240115115029_add_rate_limits_hash_constraint_to_application_settings.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddRateLimitsHashConstraintToApplicationSettings < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+ milestone '16.9'
+
+ CONSTRAINT_NAME = 'check_application_settings_rate_limits_is_hash'
+
+ def up
+ add_check_constraint(
+ :application_settings,
+ "(jsonb_typeof(rate_limits) = 'object')",
+ CONSTRAINT_NAME
+ )
+ end
+
+ def down
+ remove_check_constraint :application_settings, CONSTRAINT_NAME
+ end
+end