diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /db/migrate | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) | |
download | gitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'db/migrate')
45 files changed, 811 insertions, 0 deletions
diff --git a/db/migrate/20220213100000_remove_integration_type_triggers.rb b/db/migrate/20220213100000_remove_integration_type_triggers.rb new file mode 100644 index 00000000000..137e5648125 --- /dev/null +++ b/db/migrate/20220213100000_remove_integration_type_triggers.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class RemoveIntegrationTypeTriggers < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + FUNCTION_NAME = 'integrations_set_type_new' + TRIGGER_ON_INSERT_NAME = 'trigger_type_new_on_insert' + + def up + drop_trigger(:integrations, TRIGGER_ON_INSERT_NAME) + drop_function(FUNCTION_NAME) + end + + def down + create_trigger_function(FUNCTION_NAME, replace: true) do + <<~SQL.squish + UPDATE integrations + SET type_new = COALESCE(NEW.type_new, regexp_replace(NEW.type, '\\A(.+)Service\\Z', 'Integrations::\\1')) + , type = COALESCE(NEW.type, regexp_replace(NEW.type_new, '\\AIntegrations::(.+)\\Z', '\\1Service')) + WHERE integrations.id = NEW.id; + RETURN NULL; + SQL + end + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_ON_INSERT_NAME} + AFTER INSERT ON integrations + FOR EACH ROW + EXECUTE FUNCTION #{FUNCTION_NAME}(); + SQL + end +end diff --git a/db/migrate/20220324091224_add_enforce_auth_checks_on_uploads_to_project_settings.rb b/db/migrate/20220324091224_add_enforce_auth_checks_on_uploads_to_project_settings.rb new file mode 100644 index 00000000000..2c86d1d346d --- /dev/null +++ b/db/migrate/20220324091224_add_enforce_auth_checks_on_uploads_to_project_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddEnforceAuthChecksOnUploadsToProjectSettings < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + add_column :project_settings, :enforce_auth_checks_on_uploads, :boolean, null: false, default: true + end +end diff --git a/db/migrate/20220331125725_add_title_to_topic.rb b/db/migrate/20220331125725_add_title_to_topic.rb new file mode 100644 index 00000000000..0c6ccb6beb9 --- /dev/null +++ b/db/migrate/20220331125725_add_title_to_topic.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddTitleToTopic < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220331130726_add_text_limit_to_topics_title.rb + def change + add_column :topics, :title, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220331130726_add_text_limit_to_topics_title.rb b/db/migrate/20220331130726_add_text_limit_to_topics_title.rb new file mode 100644 index 00000000000..4a4b30edc0d --- /dev/null +++ b/db/migrate/20220331130726_add_text_limit_to_topics_title.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToTopicsTitle < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :topics, :title, 255 + end + + def down + remove_text_limit :topics, :title + end +end diff --git a/db/migrate/20220401071609_add_campaign_to_in_product_marketing_email.rb b/db/migrate/20220401071609_add_campaign_to_in_product_marketing_email.rb new file mode 100644 index 00000000000..f8d027cfd2e --- /dev/null +++ b/db/migrate/20220401071609_add_campaign_to_in_product_marketing_email.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class AddCampaignToInProductMarketingEmail < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + TARGET_TABLE = :in_product_marketing_emails + UNIQUE_INDEX_NAME = :index_in_product_marketing_emails_on_user_campaign + CONSTRAINT_NAME = :in_product_marketing_emails_track_and_series_or_campaign + TRACK_AND_SERIES_NOT_NULL_CONSTRAINT = 'track IS NOT NULL AND series IS NOT NULL AND campaign IS NULL' + CAMPAIGN_NOT_NULL_CONSTRAINT = 'track IS NULL AND series IS NULL AND campaign IS NOT NULL' + + def up + change_column_null TARGET_TABLE, :track, true + change_column_null TARGET_TABLE, :series, true + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220420034519_add_text_limit_to_in_product_marketing_email_campaign.rb + add_column :in_product_marketing_emails, :campaign, :text, if_not_exists: true + # rubocop:enable Migration/AddLimitToTextColumns + add_concurrent_index TARGET_TABLE, [:user_id, :campaign], unique: true, name: UNIQUE_INDEX_NAME + add_check_constraint TARGET_TABLE, + "(#{TRACK_AND_SERIES_NOT_NULL_CONSTRAINT}) OR (#{CAMPAIGN_NOT_NULL_CONSTRAINT})", + CONSTRAINT_NAME + end + + def down + remove_check_constraint TARGET_TABLE, CONSTRAINT_NAME + remove_concurrent_index TARGET_TABLE, [:user_id, :campaign], name: UNIQUE_INDEX_NAME + remove_column :in_product_marketing_emails, :campaign, if_exists: true + + # Records that previously had a value for campaign column will have NULL + # values for track and series columns so we can't reverse + # change_column_null. + end +end diff --git a/db/migrate/20220401151123_add_last_repository_updated_at_to_project_repository_state.rb b/db/migrate/20220401151123_add_last_repository_updated_at_to_project_repository_state.rb new file mode 100644 index 00000000000..d8ef5865576 --- /dev/null +++ b/db/migrate/20220401151123_add_last_repository_updated_at_to_project_repository_state.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddLastRepositoryUpdatedAtToProjectRepositoryState < Gitlab::Database::Migration[1.0] + def change + add_column :project_repository_states, :last_repository_updated_at, :datetime_with_timezone + add_column :project_repository_states, :last_wiki_updated_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20220406133049_add_delayed_group_deletion_to_application_settings.rb b/db/migrate/20220406133049_add_delayed_group_deletion_to_application_settings.rb new file mode 100644 index 00000000000..16ee7033021 --- /dev/null +++ b/db/migrate/20220406133049_add_delayed_group_deletion_to_application_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddDelayedGroupDeletionToApplicationSettings < Gitlab::Database::Migration[1.0] + def up + add_column :application_settings, :delayed_group_deletion, :boolean, default: true, null: false + end + + def down + remove_column :application_settings, :delayed_group_deletion + end +end diff --git a/db/migrate/20220412060931_add_nullify_build_data_trigger_on_merge_request_metrics.rb b/db/migrate/20220412060931_add_nullify_build_data_trigger_on_merge_request_metrics.rb new file mode 100644 index 00000000000..96ec44c16c5 --- /dev/null +++ b/db/migrate/20220412060931_add_nullify_build_data_trigger_on_merge_request_metrics.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddNullifyBuildDataTriggerOnMergeRequestMetrics < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + TABLE_NAME = 'merge_request_metrics' + FUNCTION_NAME = 'nullify_merge_request_metrics_build_data' + TRIGGER_NAME = 'nullify_merge_request_metrics_build_data_on_update' + + def up + create_trigger_function(FUNCTION_NAME) do + <<~SQL + IF (OLD.pipeline_id IS NOT NULL) AND (NEW.pipeline_id IS NULL) THEN + NEW.latest_build_started_at = NULL; + NEW.latest_build_finished_at = NULL; + END IF; + RETURN NEW; + SQL + end + + create_trigger(TABLE_NAME, TRIGGER_NAME, FUNCTION_NAME, fires: 'BEFORE UPDATE') + end + + def down + drop_trigger(TABLE_NAME, TRIGGER_NAME) + drop_function(FUNCTION_NAME) + end +end diff --git a/db/migrate/20220412135446_add_unique_fingerprint_sha256_index_to_key.rb b/db/migrate/20220412135446_add_unique_fingerprint_sha256_index_to_key.rb new file mode 100644 index 00000000000..3f2ea80ef30 --- /dev/null +++ b/db/migrate/20220412135446_add_unique_fingerprint_sha256_index_to_key.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddUniqueFingerprintSha256IndexToKey < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_keys_on_fingerprint_sha256' + NEW_INDEX_NAME = 'index_keys_on_fingerprint_sha256_unique' + + def up + add_concurrent_index :keys, :fingerprint_sha256, unique: true, name: NEW_INDEX_NAME + remove_concurrent_index_by_name :keys, OLD_INDEX_NAME + end + + def down + add_concurrent_index :keys, :fingerprint_sha256, name: OLD_INDEX_NAME + remove_concurrent_index_by_name :keys, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20220412140446_add_unique_fingerprint_sha256_index_to_group_deploy_key.rb b/db/migrate/20220412140446_add_unique_fingerprint_sha256_index_to_group_deploy_key.rb new file mode 100644 index 00000000000..db238394dd6 --- /dev/null +++ b/db/migrate/20220412140446_add_unique_fingerprint_sha256_index_to_group_deploy_key.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddUniqueFingerprintSha256IndexToGroupDeployKey < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_group_deploy_keys_on_fingerprint_sha256' + NEW_INDEX_NAME = 'index_group_deploy_keys_on_fingerprint_sha256_unique' + + def up + add_concurrent_index :group_deploy_keys, :fingerprint_sha256, unique: true, name: NEW_INDEX_NAME + remove_concurrent_index_by_name :group_deploy_keys, OLD_INDEX_NAME + end + + def down + add_concurrent_index :group_deploy_keys, :fingerprint_sha256, name: OLD_INDEX_NAME + remove_concurrent_index_by_name :group_deploy_keys, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20220412140755_drop_unique_fingerprint_md5_index_from_key.rb b/db/migrate/20220412140755_drop_unique_fingerprint_md5_index_from_key.rb new file mode 100644 index 00000000000..09fb7de0798 --- /dev/null +++ b/db/migrate/20220412140755_drop_unique_fingerprint_md5_index_from_key.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DropUniqueFingerprintMd5IndexFromKey < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_keys_on_fingerprint' + + def up + remove_concurrent_index_by_name :keys, INDEX_NAME + add_concurrent_index :keys, :fingerprint, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :keys, INDEX_NAME + add_concurrent_index :keys, :fingerprint, unique: true, name: INDEX_NAME + end +end diff --git a/db/migrate/20220412141020_drop_unique_fingerprint_md5_index_from_group_deploy_key.rb b/db/migrate/20220412141020_drop_unique_fingerprint_md5_index_from_group_deploy_key.rb new file mode 100644 index 00000000000..51ae664ed4a --- /dev/null +++ b/db/migrate/20220412141020_drop_unique_fingerprint_md5_index_from_group_deploy_key.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DropUniqueFingerprintMd5IndexFromGroupDeployKey < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_group_deploy_keys_on_fingerprint' + + def up + remove_concurrent_index_by_name :group_deploy_keys, INDEX_NAME + add_concurrent_index :group_deploy_keys, :fingerprint, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :group_deploy_keys, INDEX_NAME + add_concurrent_index :group_deploy_keys, :fingerprint, unique: true, name: INDEX_NAME + end +end diff --git a/db/migrate/20220413054910_backfill_delayed_group_deletion.rb b/db/migrate/20220413054910_backfill_delayed_group_deletion.rb new file mode 100644 index 00000000000..420f200be02 --- /dev/null +++ b/db/migrate/20220413054910_backfill_delayed_group_deletion.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class BackfillDelayedGroupDeletion < Gitlab::Database::Migration[1.0] + class ApplicationSetting < ActiveRecord::Base + self.table_name = 'application_settings' + end + + def up + ApplicationSetting.reset_column_information + + ApplicationSetting.find_each do |application_setting| + application_setting.update!(delayed_group_deletion: application_setting.deletion_adjourned_period > 0) + end + end + + def down + ApplicationSetting.reset_column_information + + ApplicationSetting.update_all(delayed_group_deletion: true) + end +end diff --git a/db/migrate/20220413124200_add_view_for_per_table_autovacuum_status.rb b/db/migrate/20220413124200_add_view_for_per_table_autovacuum_status.rb new file mode 100644 index 00000000000..977a16d1b54 --- /dev/null +++ b/db/migrate/20220413124200_add_view_for_per_table_autovacuum_status.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class AddViewForPerTableAutovacuumStatus < Gitlab::Database::Migration[1.0] + def up + execute <<~SQL + DROP VIEW IF EXISTS postgres_autovacuum_activity; + DROP FUNCTION IF EXISTS postgres_pg_stat_activity_autovacuum; + + CREATE FUNCTION postgres_pg_stat_activity_autovacuum() RETURNS SETOF pg_catalog.pg_stat_activity AS + $$ + SELECT * + FROM pg_stat_activity + WHERE datname = current_database() + AND state = 'active' + AND backend_type = 'autovacuum worker' + $$ + LANGUAGE sql + VOLATILE + SECURITY DEFINER + SET search_path = 'pg_catalog', 'pg_temp'; + + CREATE VIEW postgres_autovacuum_activity AS + WITH processes as + ( + SELECT query, query_start, (regexp_matches(query, '^autovacuum: VACUUM (\w+)\.(\w+)')) as matches + FROM postgres_pg_stat_activity_autovacuum() + WHERE query ~* '^autovacuum: VACUUM \w+\.\w+' + ) + SELECT matches[1] || '.' || matches[2] as table_identifier, + matches[1] as schema, + matches[2] as table, + query_start as vacuum_start + FROM processes; + + COMMENT ON VIEW postgres_autovacuum_activity IS 'Contains information about PostgreSQL backends currently performing autovacuum operations on the tables indicated here.'; + SQL + end + + def down + execute <<~SQL + DROP VIEW IF EXISTS postgres_autovacuum_activity; + DROP FUNCTION IF EXISTS postgres_pg_stat_activity_autovacuum; + SQL + end +end diff --git a/db/migrate/20220413164146_remove_max_seats_used_indices.rb b/db/migrate/20220413164146_remove_max_seats_used_indices.rb new file mode 100644 index 00000000000..d89ce6de4a4 --- /dev/null +++ b/db/migrate/20220413164146_remove_max_seats_used_indices.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class RemoveMaxSeatsUsedIndices < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + MAX_SEATS_USED_INDEX = 'tmp_gitlab_subscriptions_max_seats_used_migration' + MAX_SEATS_USED_INDEX_2 = 'tmp_gitlab_subscriptions_max_seats_used_migration_2' + + def up + remove_concurrent_index_by_name :gitlab_subscriptions, MAX_SEATS_USED_INDEX + remove_concurrent_index_by_name :gitlab_subscriptions, MAX_SEATS_USED_INDEX_2 + end + + def down + add_concurrent_index :gitlab_subscriptions, :id, + where: "start_date >= '2021-08-02' AND start_date <= '2021-11-20' AND max_seats_used != 0 " \ + "AND max_seats_used > seats_in_use AND max_seats_used > seats", + name: MAX_SEATS_USED_INDEX + add_concurrent_index :gitlab_subscriptions, :id, + where: "start_date < '2021-08-02' AND max_seats_used != 0 AND max_seats_used > seats_in_use " \ + "AND max_seats_used > seats", + name: MAX_SEATS_USED_INDEX_2 + end +end diff --git a/db/migrate/20220413235818_add_max_seats_used_changed_at_to_gitlab_subscriptions.rb b/db/migrate/20220413235818_add_max_seats_used_changed_at_to_gitlab_subscriptions.rb new file mode 100644 index 00000000000..34e3a59cfb7 --- /dev/null +++ b/db/migrate/20220413235818_add_max_seats_used_changed_at_to_gitlab_subscriptions.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddMaxSeatsUsedChangedAtToGitlabSubscriptions < Gitlab::Database::Migration[2.0] + def change + add_column :gitlab_subscriptions, :max_seats_used_changed_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20220414203622_add_index_for_columns_user_custom_attribute.rb b/db/migrate/20220414203622_add_index_for_columns_user_custom_attribute.rb new file mode 100644 index 00000000000..b461e656f1f --- /dev/null +++ b/db/migrate/20220414203622_add_index_for_columns_user_custom_attribute.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddIndexForColumnsUserCustomAttribute < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + INDEX_NAME = 'index_key_updated_at_on_user_custom_attribute' + + def up + add_concurrent_index(:user_custom_attributes, [:key, :updated_at], name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:user_custom_attributes, INDEX_NAME) + end +end diff --git a/db/migrate/20220415015143_replace_iterations_cadence_date_range_constraint.rb b/db/migrate/20220415015143_replace_iterations_cadence_date_range_constraint.rb new file mode 100644 index 00000000000..9788fd4a32b --- /dev/null +++ b/db/migrate/20220415015143_replace_iterations_cadence_date_range_constraint.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class ReplaceIterationsCadenceDateRangeConstraint < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + execute <<~SQL + ALTER TABLE sprints + DROP CONSTRAINT IF EXISTS iteration_start_and_due_date_iterations_cadence_id_constraint; + + ALTER TABLE sprints + ADD CONSTRAINT iteration_start_and_due_date_iterations_cadence_id_constraint + EXCLUDE USING gist + ( iterations_cadence_id WITH =, + daterange(start_date, due_date, '[]') WITH && + ) + WHERE (group_id IS NOT NULL) DEFERRABLE INITIALLY DEFERRED; + SQL + end + + def down + execute <<~SQL + ALTER TABLE sprints + DROP CONSTRAINT IF EXISTS iteration_start_and_due_date_iterations_cadence_id_constraint; + + ALTER TABLE sprints + ADD CONSTRAINT iteration_start_and_due_date_iterations_cadence_id_constraint + EXCLUDE USING gist + ( iterations_cadence_id WITH =, + daterange(start_date, due_date, '[]') WITH && + ) + WHERE (group_id IS NOT NULL); + SQL + end +end diff --git a/db/migrate/20220419223906_add_arkose_namespace_to_application_settings.rb b/db/migrate/20220419223906_add_arkose_namespace_to_application_settings.rb new file mode 100644 index 00000000000..1fc655228db --- /dev/null +++ b/db/migrate/20220419223906_add_arkose_namespace_to_application_settings.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddArkoseNamespaceToApplicationSettings < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + ARKOSE_LABS_DEFAULT_NAMESPACE = 'client' + + def up + unless column_exists?(:application_settings, :arkose_labs_namespace) + add_column :application_settings, + :arkose_labs_namespace, + :text, + default: ARKOSE_LABS_DEFAULT_NAMESPACE, + null: false + end + + add_text_limit :application_settings, :arkose_labs_namespace, 255 + end + + def down + remove_column :application_settings, :arkose_labs_namespace + end +end diff --git a/db/migrate/20220420034519_add_text_limit_to_in_product_marketing_email_campaign.rb b/db/migrate/20220420034519_add_text_limit_to_in_product_marketing_email_campaign.rb new file mode 100644 index 00000000000..c590111da21 --- /dev/null +++ b/db/migrate/20220420034519_add_text_limit_to_in_product_marketing_email_campaign.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToInProductMarketingEmailCampaign < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_text_limit :in_product_marketing_emails, :campaign, 255 + end + + def down + remove_text_limit :in_product_marketing_emails, :campaign + end +end diff --git a/db/migrate/20220420135245_fix_batched_background_migration_default_arguments.rb b/db/migrate/20220420135245_fix_batched_background_migration_default_arguments.rb new file mode 100644 index 00000000000..42a0ee32ecb --- /dev/null +++ b/db/migrate/20220420135245_fix_batched_background_migration_default_arguments.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class FixBatchedBackgroundMigrationDefaultArguments < Gitlab::Database::Migration[1.0] + def change + change_column_default :batched_background_migrations, :job_arguments, from: '[]', to: [] + end +end diff --git a/db/migrate/20220420173247_add_group_inheritance_type_to_pe_authorizable.rb b/db/migrate/20220420173247_add_group_inheritance_type_to_pe_authorizable.rb new file mode 100644 index 00000000000..f1ddf48304e --- /dev/null +++ b/db/migrate/20220420173247_add_group_inheritance_type_to_pe_authorizable.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddGroupInheritanceTypeToPeAuthorizable < Gitlab::Database::Migration[2.0] + def change + add_column :protected_environment_deploy_access_levels, + :group_inheritance_type, + :smallint, + default: 0, limit: 2, null: false + add_column :protected_environment_approval_rules, + :group_inheritance_type, + :smallint, + default: 0, limit: 2, null: false + end +end diff --git a/db/migrate/20220420192542_add_id_for_cleanup_index_packages_package_files.rb b/db/migrate/20220420192542_add_id_for_cleanup_index_packages_package_files.rb new file mode 100644 index 00000000000..a5a0001ab69 --- /dev/null +++ b/db/migrate/20220420192542_add_id_for_cleanup_index_packages_package_files.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIdForCleanupIndexPackagesPackageFiles < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_packages_package_files_on_id_for_cleanup' + + PACKAGE_FILE_STATUS_PENDING_DESTRUCTION = 1 + + def up + where = "status = #{PACKAGE_FILE_STATUS_PENDING_DESTRUCTION}" + + add_concurrent_index :packages_package_files, :id, name: INDEX_NAME, where: where + end + + def down + remove_concurrent_index_by_name :packages_package_files, name: INDEX_NAME + end +end diff --git a/db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb b/db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb new file mode 100644 index 00000000000..587ebf1289d --- /dev/null +++ b/db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class MakeFingerprintNullableForGroupDeployKey < Gitlab::Database::Migration[2.0] + def up + change_column_null :group_deploy_keys, :fingerprint, true + end + + def down + # There may now be nulls in the table, so we cannot re-add the constraint here. + end +end diff --git a/db/migrate/20220421141342_add_allowed_plans_to_ci_runners.rb b/db/migrate/20220421141342_add_allowed_plans_to_ci_runners.rb new file mode 100644 index 00000000000..46da684cfe2 --- /dev/null +++ b/db/migrate/20220421141342_add_allowed_plans_to_ci_runners.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddAllowedPlansToCiRunners < Gitlab::Database::Migration[1.0] + def change + # rubocop:disable Migration/AddLimitToTextColumns + add_column :ci_runners, :allowed_plans, :text, array: true, null: false, default: [] + # rubocop:enable Migration/AddLimitToTextColumns + end +end diff --git a/db/migrate/20220421144758_change_dotenv_plan_limits_for_old_plans.rb b/db/migrate/20220421144758_change_dotenv_plan_limits_for_old_plans.rb new file mode 100644 index 00000000000..a4dede974e2 --- /dev/null +++ b/db/migrate/20220421144758_change_dotenv_plan_limits_for_old_plans.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ChangeDotenvPlanLimitsForOldPlans < Gitlab::Database::Migration[2.0] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + create_or_update_plan_limit('dotenv_variables', 'early_adopter', 50) + create_or_update_plan_limit('dotenv_variables', 'bronze', 50) + create_or_update_plan_limit('dotenv_variables', 'silver', 100) + create_or_update_plan_limit('dotenv_variables', 'gold', 150) + end + + def down + create_or_update_plan_limit('dotenv_variables', 'early_adopter', 20) + create_or_update_plan_limit('dotenv_variables', 'bronze', 20) + create_or_update_plan_limit('dotenv_variables', 'silver', 20) + create_or_update_plan_limit('dotenv_variables', 'gold', 20) + end +end diff --git a/db/migrate/20220421180321_add_last_cleanup_deleted_tags_count_to_container_repository.rb b/db/migrate/20220421180321_add_last_cleanup_deleted_tags_count_to_container_repository.rb new file mode 100644 index 00000000000..141bc4b49e6 --- /dev/null +++ b/db/migrate/20220421180321_add_last_cleanup_deleted_tags_count_to_container_repository.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddLastCleanupDeletedTagsCountToContainerRepository < Gitlab::Database::Migration[2.0] + def change + add_column :container_repositories, :last_cleanup_deleted_tags_count, :integer + end +end diff --git a/db/migrate/20220422200633_fix_view_for_per_table_autovacuum_status.rb b/db/migrate/20220422200633_fix_view_for_per_table_autovacuum_status.rb new file mode 100644 index 00000000000..0af56d32674 --- /dev/null +++ b/db/migrate/20220422200633_fix_view_for_per_table_autovacuum_status.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +class FixViewForPerTableAutovacuumStatus < Gitlab::Database::Migration[2.0] + def up + execute <<~SQL + DROP VIEW IF EXISTS postgres_autovacuum_activity; + DROP FUNCTION IF EXISTS postgres_pg_stat_activity_autovacuum; + + CREATE FUNCTION postgres_pg_stat_activity_autovacuum() RETURNS TABLE(query text, query_start timestamptz) AS + $$ + SELECT query, query_start + FROM pg_stat_activity + WHERE datname = current_database() + AND state = 'active' + AND backend_type = 'autovacuum worker' + $$ + LANGUAGE sql + VOLATILE + SECURITY DEFINER + SET search_path = 'pg_catalog', 'pg_temp'; + + CREATE VIEW postgres_autovacuum_activity AS + WITH processes as + ( + SELECT query, query_start, (regexp_matches(query, '^autovacuum: VACUUM (\w+)\.(\w+)')) as matches + FROM postgres_pg_stat_activity_autovacuum() + WHERE query ~* '^autovacuum: VACUUM \w+\.\w+' + ) + SELECT matches[1] || '.' || matches[2] as table_identifier, + matches[1] as schema, + matches[2] as table, + query_start as vacuum_start + FROM processes; + + COMMENT ON VIEW postgres_autovacuum_activity IS 'Contains information about PostgreSQL backends currently performing autovacuum operations on the tables indicated here.'; + SQL + end + + def down + execute(<<~SQL) + DROP VIEW IF EXISTS postgres_autovacuum_activity; + DROP FUNCTION IF EXISTS postgres_pg_stat_activity_autovacuum; + + CREATE FUNCTION postgres_pg_stat_activity_autovacuum() RETURNS SETOF pg_catalog.pg_stat_activity AS + $$ + SELECT * + FROM pg_stat_activity + WHERE datname = current_database() + AND state = 'active' + AND backend_type = 'autovacuum worker' + $$ + LANGUAGE sql + VOLATILE + SECURITY DEFINER + SET search_path = 'pg_catalog', 'pg_temp'; + + CREATE VIEW postgres_autovacuum_activity AS + WITH processes as + ( + SELECT query, query_start, (regexp_matches(query, '^autovacuum: VACUUM (\w+)\.(\w+)')) as matches + FROM postgres_pg_stat_activity_autovacuum() + WHERE query ~* '^autovacuum: VACUUM \w+\.\w+' + ) + SELECT matches[1] || '.' || matches[2] as table_identifier, + matches[1] as schema, + matches[2] as table, + query_start as vacuum_start + FROM processes; + + COMMENT ON VIEW postgres_autovacuum_activity IS 'Contains information about PostgreSQL backends currently performing autovacuum operations on the tables indicated here.'; + SQL + end +end diff --git a/db/migrate/20220422220507_remove_tmp_index_supporting_leaky_regex_cleanup.rb b/db/migrate/20220422220507_remove_tmp_index_supporting_leaky_regex_cleanup.rb new file mode 100644 index 00000000000..15a3c4d579e --- /dev/null +++ b/db/migrate/20220422220507_remove_tmp_index_supporting_leaky_regex_cleanup.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class RemoveTmpIndexSupportingLeakyRegexCleanup < Gitlab::Database::Migration[2.0] + INDEX_NAME = "tmp_index_merge_requests_draft_and_status_leaky_regex" + LEAKY_REGEXP_STR = "^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP" + CORRECTED_REGEXP_STR = "^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)" + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :merge_requests, INDEX_NAME + end + + def down + where_clause = <<~SQL + draft = true AND + state_id = 1 AND + ((title)::text ~* '#{LEAKY_REGEXP_STR}'::text) AND ((title)::text !~* '#{CORRECTED_REGEXP_STR}'::text) + SQL + + add_concurrent_index :merge_requests, :id, + where: where_clause, + name: INDEX_NAME + end +end diff --git a/db/migrate/20220425120604_create_packages_cleanup_policies.rb b/db/migrate/20220425120604_create_packages_cleanup_policies.rb new file mode 100644 index 00000000000..0b04457235e --- /dev/null +++ b/db/migrate/20220425120604_create_packages_cleanup_policies.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CreatePackagesCleanupPolicies < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + create_table :packages_cleanup_policies, id: false do |t| + t.timestamps_with_timezone null: false + t.references :project, + primary_key: true, + default: nil, + index: false, + foreign_key: { to_table: :projects, on_delete: :cascade } + t.datetime_with_timezone :next_run_at, null: true + t.text :keep_n_duplicated_package_files, default: 'all', null: false, limit: 255 + end + end + + def down + drop_table :packages_cleanup_policies + end +end diff --git a/db/migrate/20220426130217_add_max_export_size_to_application_settings.rb b/db/migrate/20220426130217_add_max_export_size_to_application_settings.rb new file mode 100644 index 00000000000..d1488a77d14 --- /dev/null +++ b/db/migrate/20220426130217_add_max_export_size_to_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddMaxExportSizeToApplicationSettings < Gitlab::Database::Migration[2.0] + def change + add_column :application_settings, :max_export_size, :integer, default: 0 + end +end diff --git a/db/migrate/20220502125053_recreate_index_for_project_group_link_with_group_id_and_project_id.rb b/db/migrate/20220502125053_recreate_index_for_project_group_link_with_group_id_and_project_id.rb new file mode 100644 index 00000000000..1d9a18b7b23 --- /dev/null +++ b/db/migrate/20220502125053_recreate_index_for_project_group_link_with_group_id_and_project_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RecreateIndexForProjectGroupLinkWithGroupIdAndProjectId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_project_group_links_on_group_id' + NEW_INDEX_NAME = 'index_project_group_links_on_group_id_and_project_id' + + def up + add_concurrent_index :project_group_links, [:group_id, :project_id], name: NEW_INDEX_NAME + remove_concurrent_index_by_name :project_group_links, OLD_INDEX_NAME + end + + def down + add_concurrent_index :project_group_links, [:group_id], name: OLD_INDEX_NAME + remove_concurrent_index_by_name :project_group_links, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20220502150408_add_slack_integrations_bot_columns.rb b/db/migrate/20220502150408_add_slack_integrations_bot_columns.rb new file mode 100644 index 00000000000..cb5b201e71e --- /dev/null +++ b/db/migrate/20220502150408_add_slack_integrations_bot_columns.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddSlackIntegrationsBotColumns < Gitlab::Database::Migration[2.0] + def change + change_table :slack_integrations do |t| + t.column :bot_user_id, :text + t.column :encrypted_bot_access_token, :binary + t.column :encrypted_bot_access_token_iv, :binary + end + end +end diff --git a/db/migrate/20220502152633_add_slack_integrations_bot_user_id_text_limit.rb b/db/migrate/20220502152633_add_slack_integrations_bot_user_id_text_limit.rb new file mode 100644 index 00000000000..649d6ccf9d4 --- /dev/null +++ b/db/migrate/20220502152633_add_slack_integrations_bot_user_id_text_limit.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddSlackIntegrationsBotUserIdTextLimit < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_text_limit :slack_integrations, :bot_user_id, 255 + end + + def down + remove_text_limit :slack_integrations, :bot_user_id + end +end diff --git a/db/migrate/20220503073401_recreate_index_for_group_group_link_with_both_group_ids.rb b/db/migrate/20220503073401_recreate_index_for_group_group_link_with_both_group_ids.rb new file mode 100644 index 00000000000..214e9c5e0a7 --- /dev/null +++ b/db/migrate/20220503073401_recreate_index_for_group_group_link_with_both_group_ids.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RecreateIndexForGroupGroupLinkWithBothGroupIds < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_group_group_links_on_shared_with_group_id' + NEW_INDEX_NAME = 'index_group_group_links_on_shared_with_group_and_shared_group' + + def up + add_concurrent_index :group_group_links, [:shared_with_group_id, :shared_group_id], name: NEW_INDEX_NAME + remove_concurrent_index_by_name :group_group_links, OLD_INDEX_NAME + end + + def down + add_concurrent_index :group_group_links, [:shared_with_group_id], name: OLD_INDEX_NAME + remove_concurrent_index_by_name :group_group_links, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20220503102855_add_namespace_ci_cd_settings_table.rb b/db/migrate/20220503102855_add_namespace_ci_cd_settings_table.rb new file mode 100644 index 00000000000..532e80d1567 --- /dev/null +++ b/db/migrate/20220503102855_add_namespace_ci_cd_settings_table.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNamespaceCiCdSettingsTable < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + create_table :namespace_ci_cd_settings, id: false do |t| + t.references :namespace, primary_key: true, default: nil, index: false, foreign_key: { on_delete: :cascade } + t.boolean :allow_stale_runner_pruning, null: false, default: false + end + end + + def down + drop_table :namespace_ci_cd_settings, if_exists: true + end +end diff --git a/db/migrate/20220504042847_add_slack_signing_key_to_application_settings.rb b/db/migrate/20220504042847_add_slack_signing_key_to_application_settings.rb new file mode 100644 index 00000000000..ddfa7c63370 --- /dev/null +++ b/db/migrate/20220504042847_add_slack_signing_key_to_application_settings.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddSlackSigningKeyToApplicationSettings < Gitlab::Database::Migration[2.0] + def change + add_column :application_settings, :encrypted_slack_app_signing_secret, :binary + add_column :application_settings, :encrypted_slack_app_signing_secret_iv, :binary + end +end diff --git a/db/migrate/20220504140036_add_container_registry_size_to_namespace_root_storage_statistics.rb b/db/migrate/20220504140036_add_container_registry_size_to_namespace_root_storage_statistics.rb new file mode 100644 index 00000000000..0197b418cd8 --- /dev/null +++ b/db/migrate/20220504140036_add_container_registry_size_to_namespace_root_storage_statistics.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddContainerRegistrySizeToNamespaceRootStorageStatistics < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :namespace_root_storage_statistics, :container_registry_size, :bigint, default: 0, null: false + end +end diff --git a/db/migrate/20220505092254_add_allow_stale_runner_pruning_index_to_namespace_ci_cd_settings.rb b/db/migrate/20220505092254_add_allow_stale_runner_pruning_index_to_namespace_ci_cd_settings.rb new file mode 100644 index 00000000000..b7fd8fdee4f --- /dev/null +++ b/db/migrate/20220505092254_add_allow_stale_runner_pruning_index_to_namespace_ci_cd_settings.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddAllowStaleRunnerPruningIndexToNamespaceCiCdSettings < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_cicd_settings_on_namespace_id_where_stale_pruning_enabled' + + disable_ddl_transaction! + + def up + add_concurrent_index :namespace_ci_cd_settings, + :namespace_id, + where: '(allow_stale_runner_pruning = true)', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :namespace_ci_cd_settings, INDEX_NAME + end +end diff --git a/db/migrate/20220506180411_add_index_to_vulnerability_feedback_finding_uuid.rb b/db/migrate/20220506180411_add_index_to_vulnerability_feedback_finding_uuid.rb new file mode 100644 index 00000000000..a6f01ce5a0e --- /dev/null +++ b/db/migrate/20220506180411_add_index_to_vulnerability_feedback_finding_uuid.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToVulnerabilityFeedbackFindingUuid < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_vulnerability_feedback_finding_uuid' + + # We are indexing on UUID, a hash index should be smaller and faster + # details on https://gitlab.com/gitlab-org/gitlab/-/merge_requests/86808#note_943330140 + def up + add_concurrent_index :vulnerability_feedback, :finding_uuid, using: :hash, name: INDEX_NAME + end + + def down + remove_concurrent_index :vulnerability_feedback, :finding_uuid, using: :hash, name: INDEX_NAME + end +end diff --git a/db/migrate/20220507204024_add_separated_caches_option_to_project_ci_settings.rb b/db/migrate/20220507204024_add_separated_caches_option_to_project_ci_settings.rb new file mode 100644 index 00000000000..39daf9fe296 --- /dev/null +++ b/db/migrate/20220507204024_add_separated_caches_option_to_project_ci_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddSeparatedCachesOptionToProjectCiSettings < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :project_ci_cd_settings, :separated_caches, :boolean, default: true, null: false + end +end diff --git a/db/migrate/20220511090324_add_last_consistency_check_cursors_to_vsa_aggregations.rb b/db/migrate/20220511090324_add_last_consistency_check_cursors_to_vsa_aggregations.rb new file mode 100644 index 00000000000..53c09597be5 --- /dev/null +++ b/db/migrate/20220511090324_add_last_consistency_check_cursors_to_vsa_aggregations.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddLastConsistencyCheckCursorsToVsaAggregations < Gitlab::Database::Migration[2.0] + def up + change_table(:analytics_cycle_analytics_aggregations, bulk: true) do |t| + t.column :last_consistency_check_issues_stage_event_hash_id, :bigint, null: true + t.column :last_consistency_check_issues_start_event_timestamp, :datetime_with_timezone, null: true + t.column :last_consistency_check_issues_end_event_timestamp, :datetime_with_timezone, null: true + t.column :last_consistency_check_issues_issuable_id, :bigint, null: true + + t.column :last_consistency_check_merge_requests_stage_event_hash_id, :bigint, null: true + t.column :last_consistency_check_merge_requests_start_event_timestamp, :datetime_with_timezone, null: true + t.column :last_consistency_check_merge_requests_end_event_timestamp, :datetime_with_timezone, null: true + t.column :last_consistency_check_merge_requests_issuable_id, :bigint, null: true + end + end + + def down + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_issues_stage_event_hash_id + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_issues_start_event_timestamp + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_issues_end_event_timestamp + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_issues_issuable_id + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_merge_requests_stage_event_hash_id + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_merge_requests_start_event_timestamp + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_merge_requests_end_event_timestamp + remove_column :analytics_cycle_analytics_aggregations, :last_consistency_check_merge_requests_issuable_id + end +end diff --git a/db/migrate/20220511151646_add_exclude_from_free_user_cap_to_namespace_settings.rb b/db/migrate/20220511151646_add_exclude_from_free_user_cap_to_namespace_settings.rb new file mode 100644 index 00000000000..03f6ad5911c --- /dev/null +++ b/db/migrate/20220511151646_add_exclude_from_free_user_cap_to_namespace_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddExcludeFromFreeUserCapToNamespaceSettings < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + add_column :namespace_settings, :exclude_from_free_user_cap, :boolean, null: false, default: false + end + + def down + remove_column :namespace_settings, :exclude_from_free_user_cap + end +end diff --git a/db/migrate/20220511191502_add_registry_migration_guard_thresholds_to_application_settings.rb b/db/migrate/20220511191502_add_registry_migration_guard_thresholds_to_application_settings.rb new file mode 100644 index 00000000000..87a29bd5889 --- /dev/null +++ b/db/migrate/20220511191502_add_registry_migration_guard_thresholds_to_application_settings.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddRegistryMigrationGuardThresholdsToApplicationSettings < Gitlab::Database::Migration[2.0] + def change + add_column :application_settings, :container_registry_pre_import_timeout, + :integer, + default: 30.minutes, + null: false + + add_column :application_settings, :container_registry_import_timeout, + :integer, + default: 10.minutes, + null: false + end +end diff --git a/db/migrate/20220511191503_add_pipeline_create_limit_per_project_user_sha_to_application_settings.rb b/db/migrate/20220511191503_add_pipeline_create_limit_per_project_user_sha_to_application_settings.rb new file mode 100644 index 00000000000..6454bac629a --- /dev/null +++ b/db/migrate/20220511191503_add_pipeline_create_limit_per_project_user_sha_to_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPipelineCreateLimitPerProjectUserShaToApplicationSettings < Gitlab::Database::Migration[2.0] + def change + add_column :application_settings, :pipeline_limit_per_project_user_sha, :integer, default: 0, null: false + end +end |