diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /db/migrate | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'db/migrate')
47 files changed, 691 insertions, 0 deletions
diff --git a/db/migrate/20220113164801_add_diffs_colors_to_user_preferences.rb b/db/migrate/20220113164801_add_diffs_colors_to_user_preferences.rb new file mode 100644 index 00000000000..00e8e574722 --- /dev/null +++ b/db/migrate/20220113164801_add_diffs_colors_to_user_preferences.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddDiffsColorsToUserPreferences < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220113164901_add_text_limit_to_user_preferences_diffs_colors.rb + def change + add_column :user_preferences, :diffs_deletion_color, :text + add_column :user_preferences, :diffs_addition_color, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220113164901_add_text_limit_to_user_preferences_diffs_colors.rb b/db/migrate/20220113164901_add_text_limit_to_user_preferences_diffs_colors.rb new file mode 100644 index 00000000000..9ae1c875194 --- /dev/null +++ b/db/migrate/20220113164901_add_text_limit_to_user_preferences_diffs_colors.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToUserPreferencesDiffsColors < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :user_preferences, :diffs_deletion_color, 7 + add_text_limit :user_preferences, :diffs_addition_color, 7 + end + + def down + remove_text_limit :user_preferences, :diffs_addition_color + remove_text_limit :user_preferences, :diffs_deletion_color + end +end diff --git a/db/migrate/20220120160625_remove_temp_index_on_id_from_vulnerability_occurrences.rb b/db/migrate/20220120160625_remove_temp_index_on_id_from_vulnerability_occurrences.rb new file mode 100644 index 00000000000..747cabcd865 --- /dev/null +++ b/db/migrate/20220120160625_remove_temp_index_on_id_from_vulnerability_occurrences.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveTempIndexOnIdFromVulnerabilityOccurrences < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'tmp_idx_vulnerability_occurrences_on_id_where_report_type_7_99' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :vulnerability_occurrences, name: INDEX_NAME + end + + def down + add_concurrent_index :vulnerability_occurrences, :id, where: 'report_type IN (7, 99)', name: INDEX_NAME + end +end diff --git a/db/migrate/20220302110724_add_group_features_table.rb b/db/migrate/20220302110724_add_group_features_table.rb new file mode 100644 index 00000000000..9d9204afec2 --- /dev/null +++ b/db/migrate/20220302110724_add_group_features_table.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddGroupFeaturesTable < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + create_table :group_features, id: false do |t| + t.references :group, index: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }, null: false + t.timestamps_with_timezone null: false + t.integer :wiki_access_level, default: Featurable::ENABLED, null: false, limit: 2 + end + + execute('ALTER TABLE group_features ADD PRIMARY KEY (group_id)') + end + + def down + drop_table :group_features + end +end diff --git a/db/migrate/20220310011530_add_database_grafana_config_to_application_settings.rb b/db/migrate/20220310011530_add_database_grafana_config_to_application_settings.rb new file mode 100644 index 00000000000..7752fbba12f --- /dev/null +++ b/db/migrate/20220310011530_add_database_grafana_config_to_application_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddDatabaseGrafanaConfigToApplicationSettings < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220307002607_add_text_limit_to_db_reindexing_grafana_application_settings + def change + add_column :application_settings, :encrypted_database_grafana_api_key, :binary + add_column :application_settings, :encrypted_database_grafana_api_key_iv, :binary + add_column :application_settings, :database_grafana_api_url, :text + add_column :application_settings, :database_grafana_tag, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220310011613_add_text_limit_to_database_grafana_application_settings.rb b/db/migrate/20220310011613_add_text_limit_to_database_grafana_application_settings.rb new file mode 100644 index 00000000000..72bcf493d6e --- /dev/null +++ b/db/migrate/20220310011613_add_text_limit_to_database_grafana_application_settings.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToDatabaseGrafanaApplicationSettings < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :database_grafana_api_url, 255 + add_text_limit :application_settings, :database_grafana_tag, 255 + end + + def down + remove_text_limit :application_settings, :database_grafana_tag + remove_text_limit :application_settings, :database_grafana_api_url + end +end diff --git a/db/migrate/20220314184009_create_protected_environment_approval_rules.rb b/db/migrate/20220314184009_create_protected_environment_approval_rules.rb new file mode 100644 index 00000000000..f0db2c004ed --- /dev/null +++ b/db/migrate/20220314184009_create_protected_environment_approval_rules.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class CreateProtectedEnvironmentApprovalRules < Gitlab::Database::Migration[1.0] + def up + create_table :protected_environment_approval_rules do |t| + t.references :protected_environment, + index: { name: :index_approval_rule_on_protected_environment_id }, + foreign_key: { to_table: :protected_environments, on_delete: :cascade }, + null: false + + t.bigint :user_id + t.bigint :group_id + t.timestamps_with_timezone null: false + t.integer :access_level, limit: 2 + t.integer :required_approvals, null: false, limit: 2 + + t.index :user_id + t.index :group_id + + t.check_constraint "((access_level IS NOT NULL) AND (group_id IS NULL) AND (user_id IS NULL)) OR " \ + "((user_id IS NOT NULL) AND (access_level IS NULL) AND (group_id IS NULL)) OR " \ + "((group_id IS NOT NULL) AND (user_id IS NULL) AND (access_level IS NULL))" + t.check_constraint "required_approvals > 0" + end + end + + def down + drop_table :protected_environment_approval_rules + end +end diff --git a/db/migrate/20220314184109_add_user_fk_to_protected_environment_approval_rules.rb b/db/migrate/20220314184109_add_user_fk_to_protected_environment_approval_rules.rb new file mode 100644 index 00000000000..c339f465da5 --- /dev/null +++ b/db/migrate/20220314184109_add_user_fk_to_protected_environment_approval_rules.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUserFkToProtectedEnvironmentApprovalRules < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :protected_environment_approval_rules, :users, column: :user_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :protected_environment_approval_rules, column: :user_id + end + end +end diff --git a/db/migrate/20220314184209_add_group_fk_to_protected_environment_approval_rules.rb b/db/migrate/20220314184209_add_group_fk_to_protected_environment_approval_rules.rb new file mode 100644 index 00000000000..57c4f7dea33 --- /dev/null +++ b/db/migrate/20220314184209_add_group_fk_to_protected_environment_approval_rules.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddGroupFkToProtectedEnvironmentApprovalRules < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :protected_environment_approval_rules, :namespaces, column: :group_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :protected_environment_approval_rules, column: :group_id + end + end +end diff --git a/db/migrate/20220314194009_add_approval_rule_id_to_deployment_approvals.rb b/db/migrate/20220314194009_add_approval_rule_id_to_deployment_approvals.rb new file mode 100644 index 00000000000..6e12f568f6e --- /dev/null +++ b/db/migrate/20220314194009_add_approval_rule_id_to_deployment_approvals.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddApprovalRuleIdToDeploymentApprovals < Gitlab::Database::Migration[1.0] + def change + add_column :deployment_approvals, :approval_rule_id, :bigint + end +end diff --git a/db/migrate/20220314204009_add_approval_rule_fk_to_deployment_approvals.rb b/db/migrate/20220314204009_add_approval_rule_fk_to_deployment_approvals.rb new file mode 100644 index 00000000000..ba49103b4d3 --- /dev/null +++ b/db/migrate/20220314204009_add_approval_rule_fk_to_deployment_approvals.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddApprovalRuleFkToDeploymentApprovals < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_deployment_approvals_on_approval_rule_id' + + def up + add_concurrent_index :deployment_approvals, :approval_rule_id, name: INDEX_NAME + add_concurrent_foreign_key :deployment_approvals, :protected_environment_approval_rules, column: :approval_rule_id, on_delete: :nullify + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :deployment_approvals, column: :approval_rule_id + end + + remove_concurrent_index_by_name :deployment_approvals, INDEX_NAME + end +end diff --git a/db/migrate/20220316095126_add_creator_id_to_deploy_tokens.rb b/db/migrate/20220316095126_add_creator_id_to_deploy_tokens.rb new file mode 100644 index 00000000000..22a92081b37 --- /dev/null +++ b/db/migrate/20220316095126_add_creator_id_to_deploy_tokens.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddCreatorIdToDeployTokens < Gitlab::Database::Migration[1.0] + def change + add_column :deploy_tokens, :creator_id, :bigint + end +end diff --git a/db/migrate/20220316202200_add_migration_plan_to_container_repositories.rb b/db/migrate/20220316202200_add_migration_plan_to_container_repositories.rb new file mode 100644 index 00000000000..baeff52542f --- /dev/null +++ b/db/migrate/20220316202200_add_migration_plan_to_container_repositories.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddMigrationPlanToContainerRepositories < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220316202402_add_text_limit_to_container_repositories_migration_plan + def change + add_column(:container_repositories, :migration_plan, :text) + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220316202402_add_text_limit_to_container_repositories_migration_plan.rb b/db/migrate/20220316202402_add_text_limit_to_container_repositories_migration_plan.rb new file mode 100644 index 00000000000..a9f653c742f --- /dev/null +++ b/db/migrate/20220316202402_add_text_limit_to_container_repositories_migration_plan.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToContainerRepositoriesMigrationPlan < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :container_repositories, :migration_plan, 255 + end + + def down + remove_text_limit :container_repositories, :migration_plan + end +end diff --git a/db/migrate/20220317170122_add_notification_level_to_namespace_root_storage_statistics.rb b/db/migrate/20220317170122_add_notification_level_to_namespace_root_storage_statistics.rb new file mode 100644 index 00000000000..3c0b41e0b42 --- /dev/null +++ b/db/migrate/20220317170122_add_notification_level_to_namespace_root_storage_statistics.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddNotificationLevelToNamespaceRootStorageStatistics < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + add_column :namespace_root_storage_statistics, :notification_level, :integer, limit: 2, default: 100, null: false + end + + def down + remove_column :namespace_root_storage_statistics, :notification_level + end +end diff --git a/db/migrate/20220318120802_add_target_platforms_to_project_setting.rb b/db/migrate/20220318120802_add_target_platforms_to_project_setting.rb new file mode 100644 index 00000000000..0e8f206e56d --- /dev/null +++ b/db/migrate/20220318120802_add_target_platforms_to_project_setting.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTargetPlatformsToProjectSetting < Gitlab::Database::Migration[1.0] + def change + add_column :project_settings, :target_platforms, :string, array: true, default: [], null: false, if_not_exists: true + end +end diff --git a/db/migrate/20220318141037_add_pages_onboarding_state.rb b/db/migrate/20220318141037_add_pages_onboarding_state.rb new file mode 100644 index 00000000000..e320bee63c4 --- /dev/null +++ b/db/migrate/20220318141037_add_pages_onboarding_state.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddPagesOnboardingState < Gitlab::Database::Migration[1.0] + def up + add_column :project_pages_metadata, :onboarding_complete, :boolean, default: false, null: false + end + + def down + remove_column :project_pages_metadata, :onboarding_complete + end +end diff --git a/db/migrate/20220321150028_add_started_at_to_batched_background_migrations_table.rb b/db/migrate/20220321150028_add_started_at_to_batched_background_migrations_table.rb new file mode 100644 index 00000000000..38a2c4de2f9 --- /dev/null +++ b/db/migrate/20220321150028_add_started_at_to_batched_background_migrations_table.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddStartedAtToBatchedBackgroundMigrationsTable < Gitlab::Database::Migration[1.0] + def change + add_column :batched_background_migrations, :started_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20220321234317_remove_all_issuable_escalation_statuses.rb b/db/migrate/20220321234317_remove_all_issuable_escalation_statuses.rb new file mode 100644 index 00000000000..a6ea1820160 --- /dev/null +++ b/db/migrate/20220321234317_remove_all_issuable_escalation_statuses.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RemoveAllIssuableEscalationStatuses < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 5_000 + + disable_ddl_transaction! + + # Removes records from previous backfill. Records for + # existing incidents will be created entirely as-needed. + # + # See db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb, + # & IncidentManagement::IssuableEscalationStatuses::[BuildService,PrepareUpdateService] + def up + each_batch_range('incident_management_issuable_escalation_statuses', of: BATCH_SIZE) do |min, max| + execute <<~SQL + DELETE FROM incident_management_issuable_escalation_statuses + WHERE id BETWEEN #{min} AND #{max} + SQL + end + end + + def down + # no-op + # + # Potential rollback/re-run should not have impact, as these + # records are not required to be present in the application. + # The corresponding feature flag is also disabled, + # preventing any user-facing access to the records. + end +end diff --git a/db/migrate/20220322143441_add_dora_incidents_count.rb b/db/migrate/20220322143441_add_dora_incidents_count.rb new file mode 100644 index 00000000000..155bd979171 --- /dev/null +++ b/db/migrate/20220322143441_add_dora_incidents_count.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDoraIncidentsCount < Gitlab::Database::Migration[1.0] + def change + add_column :dora_daily_metrics, :incidents_count, :integer + end +end diff --git a/db/migrate/20220322205004_change_search_rate_limit_default_values.rb b/db/migrate/20220322205004_change_search_rate_limit_default_values.rb new file mode 100644 index 00000000000..34ebdddb8eb --- /dev/null +++ b/db/migrate/20220322205004_change_search_rate_limit_default_values.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class ChangeSearchRateLimitDefaultValues < Gitlab::Database::Migration[1.0] + def change + change_column_default :application_settings, :search_rate_limit, from: 30, to: 300 + change_column_default :application_settings, :search_rate_limit_unauthenticated, from: 10, to: 100 + end +end diff --git a/db/migrate/20220324171254_add_public_git_lab_runner_releases_url_to_application_settings.rb b/db/migrate/20220324171254_add_public_git_lab_runner_releases_url_to_application_settings.rb new file mode 100644 index 00000000000..af963fa5454 --- /dev/null +++ b/db/migrate/20220324171254_add_public_git_lab_runner_releases_url_to_application_settings.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddPublicGitLabRunnerReleasesUrlToApplicationSettings < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220324173554_add_text_limit_to_public_git_lab_runner_releases_url_application_settings + def change + add_column :application_settings, :public_runner_releases_url, :text, null: false, default: 'https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-runner/releases' + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220324173554_add_text_limit_to_public_git_lab_runner_releases_url_application_settings.rb b/db/migrate/20220324173554_add_text_limit_to_public_git_lab_runner_releases_url_application_settings.rb new file mode 100644 index 00000000000..26f7447021b --- /dev/null +++ b/db/migrate/20220324173554_add_text_limit_to_public_git_lab_runner_releases_url_application_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToPublicGitLabRunnerReleasesUrlApplicationSettings < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :public_runner_releases_url, 255 + end + + def down + remove_text_limit :application_settings, :public_runner_releases_url + end +end diff --git a/db/migrate/20220324175325_add_key_data_to_secure_files.rb b/db/migrate/20220324175325_add_key_data_to_secure_files.rb new file mode 100644 index 00000000000..70dfd64be27 --- /dev/null +++ b/db/migrate/20220324175325_add_key_data_to_secure_files.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddKeyDataToSecureFiles < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + unless column_exists? :ci_secure_files, :key_data + add_column :ci_secure_files, :key_data, :text + end + + add_text_limit :ci_secure_files, :key_data, 128 + end + + def down + remove_column :ci_secure_files, :key_data + end +end diff --git a/db/migrate/20220329061545_add_repository_size_to_plan_limits.rb b/db/migrate/20220329061545_add_repository_size_to_plan_limits.rb new file mode 100644 index 00000000000..2c84780dc2b --- /dev/null +++ b/db/migrate/20220329061545_add_repository_size_to_plan_limits.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddRepositorySizeToPlanLimits < Gitlab::Database::Migration[1.0] + def up + add_column(:plan_limits, :repository_size, :bigint, default: 0, null: false) + end + + def down + remove_column(:plan_limits, :repository_size) + end +end diff --git a/db/migrate/20220329095632_add_theme_to_broadcast_message.rb b/db/migrate/20220329095632_add_theme_to_broadcast_message.rb new file mode 100644 index 00000000000..ae5971469f9 --- /dev/null +++ b/db/migrate/20220329095632_add_theme_to_broadcast_message.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddThemeToBroadcastMessage < Gitlab::Database::Migration[1.0] + def change + add_column :broadcast_messages, :theme, :smallint, null: false, default: 0 + end +end diff --git a/db/migrate/20220329110630_add_ci_namespace_mirrors_unnest_index_on_traversal_ids.rb b/db/migrate/20220329110630_add_ci_namespace_mirrors_unnest_index_on_traversal_ids.rb new file mode 100644 index 00000000000..6f5d7b4c71e --- /dev/null +++ b/db/migrate/20220329110630_add_ci_namespace_mirrors_unnest_index_on_traversal_ids.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddCiNamespaceMirrorsUnnestIndexOnTraversalIds < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_ci_namespace_mirrors_on_traversal_ids_unnest' + + def up + return if index_exists_by_name?(:ci_namespace_mirrors, INDEX_NAME) + + # We add only 4-levels since on average it is not expected that namespaces + # will be so granular beyond this point + disable_statement_timeout do + execute <<-SQL + CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON ci_namespace_mirrors + USING btree ((traversal_ids[1]), (traversal_ids[2]), (traversal_ids[3]), (traversal_ids[4])) + INCLUDE (traversal_ids, namespace_id) + SQL + end + end + + def down + remove_concurrent_index_by_name(:ci_namespace_mirrors, INDEX_NAME) + end +end diff --git a/db/migrate/20220331174026_add_submit_field_to_dast_site_profiles.rb b/db/migrate/20220331174026_add_submit_field_to_dast_site_profiles.rb new file mode 100644 index 00000000000..00c46b59b1c --- /dev/null +++ b/db/migrate/20220331174026_add_submit_field_to_dast_site_profiles.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddSubmitFieldToDastSiteProfiles < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220331174459_add_text_limit_to_submit_field_dast_site_profiles + def change + add_column :dast_site_profiles, :auth_submit_field, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220331174459_add_text_limit_to_submit_field_dast_site_profiles.rb b/db/migrate/20220331174459_add_text_limit_to_submit_field_dast_site_profiles.rb new file mode 100644 index 00000000000..291d52a0122 --- /dev/null +++ b/db/migrate/20220331174459_add_text_limit_to_submit_field_dast_site_profiles.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToSubmitFieldDastSiteProfiles < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :dast_site_profiles, :auth_submit_field, 255 + end + + def down + remove_text_limit :dast_site_profiles, :auth_submit_field + end +end diff --git a/db/migrate/20220401044858_add_user_id_and_state_index_to_merge_request_assignees.rb b/db/migrate/20220401044858_add_user_id_and_state_index_to_merge_request_assignees.rb new file mode 100644 index 00000000000..b869b3d9b52 --- /dev/null +++ b/db/migrate/20220401044858_add_user_id_and_state_index_to_merge_request_assignees.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUserIdAndStateIndexToMergeRequestAssignees < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_on_merge_request_assignees_user_id_and_state' + + def up + add_concurrent_index :merge_request_assignees, [:user_id, :state], where: 'state = 2', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :merge_request_assignees, INDEX_NAME + end +end diff --git a/db/migrate/20220401045116_add_user_id_and_state_index_to_merge_request_reviewers.rb b/db/migrate/20220401045116_add_user_id_and_state_index_to_merge_request_reviewers.rb new file mode 100644 index 00000000000..0788dd9583c --- /dev/null +++ b/db/migrate/20220401045116_add_user_id_and_state_index_to_merge_request_reviewers.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUserIdAndStateIndexToMergeRequestReviewers < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_on_merge_request_reviewers_user_id_and_state' + + def up + add_concurrent_index :merge_request_reviewers, [:user_id, :state], where: 'state = 2', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :merge_request_reviewers, INDEX_NAME + end +end diff --git a/db/migrate/20220401110443_add_on_hold_until_column_for_batched_migration.rb b/db/migrate/20220401110443_add_on_hold_until_column_for_batched_migration.rb new file mode 100644 index 00000000000..4771b50d566 --- /dev/null +++ b/db/migrate/20220401110443_add_on_hold_until_column_for_batched_migration.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddOnHoldUntilColumnForBatchedMigration < Gitlab::Database::Migration[1.0] + def change + add_column :batched_background_migrations, :on_hold_until, :timestamptz, + comment: 'execution of this migration is on hold until this time' + end +end diff --git a/db/migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb b/db/migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb new file mode 100644 index 00000000000..09960c7add6 --- /dev/null +++ b/db/migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddRuntimeDataColumnsToVsaAggregations < Gitlab::Database::Migration[1.0] + def up + change_table(:analytics_cycle_analytics_aggregations, bulk: true) do |t| + t.integer :full_runtimes_in_seconds, array: true, default: [], null: false + t.integer :full_processed_records, array: true, default: [], null: false + t.column :last_full_merge_requests_updated_at, :datetime_with_timezone + t.column :last_full_issues_updated_at, :datetime_with_timezone + t.integer :last_full_issues_id + t.integer :last_full_merge_requests_id + end + end + + def down + remove_column :analytics_cycle_analytics_aggregations, :full_runtimes_in_seconds + remove_column :analytics_cycle_analytics_aggregations, :full_processed_records + remove_column :analytics_cycle_analytics_aggregations, :last_full_merge_requests_updated_at + remove_column :analytics_cycle_analytics_aggregations, :last_full_issues_updated_at + remove_column :analytics_cycle_analytics_aggregations, :last_full_issues_id + remove_column :analytics_cycle_analytics_aggregations, :last_full_merge_requests_id + end +end diff --git a/db/migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb b/db/migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb new file mode 100644 index 00000000000..4863a1f0030 --- /dev/null +++ b/db/migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddCheckConstraintToVsaAggregationRuntimeDataColumns < Gitlab::Database::Migration[1.0] + FULL_RUNTIMES_IN_SECONDS_CONSTRAINT = 'full_runtimes_in_seconds_size' + FULL_PROCESSED_RECORDS_CONSTRAINT = 'full_processed_records_size' + + disable_ddl_transaction! + + def up + add_check_constraint(:analytics_cycle_analytics_aggregations, + 'CARDINALITY(full_runtimes_in_seconds) <= 10', + FULL_RUNTIMES_IN_SECONDS_CONSTRAINT) + + add_check_constraint(:analytics_cycle_analytics_aggregations, + 'CARDINALITY(full_processed_records) <= 10', + FULL_PROCESSED_RECORDS_CONSTRAINT) + end + + def down + remove_check_constraint :analytics_cycle_analytics_aggregations, FULL_RUNTIMES_IN_SECONDS_CONSTRAINT + remove_check_constraint :analytics_cycle_analytics_aggregations, FULL_PROCESSED_RECORDS_CONSTRAINT + end +end diff --git a/db/migrate/20220404114106_add_container_registry_size_to_project_statistics.rb b/db/migrate/20220404114106_add_container_registry_size_to_project_statistics.rb new file mode 100644 index 00000000000..4f5778bf321 --- /dev/null +++ b/db/migrate/20220404114106_add_container_registry_size_to_project_statistics.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddContainerRegistrySizeToProjectStatistics < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + add_column :project_statistics, :container_registry_size, :bigint, default: 0, null: false + end +end diff --git a/db/migrate/20220404170446_add_index_for_non_requested_non_invited_awaiting_members.rb b/db/migrate/20220404170446_add_index_for_non_requested_non_invited_awaiting_members.rb new file mode 100644 index 00000000000..d1d2dc510cf --- /dev/null +++ b/db/migrate/20220404170446_add_index_for_non_requested_non_invited_awaiting_members.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexForNonRequestedNonInvitedAwaitingMembers < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_members_on_non_requested_non_invited_and_state_awaiting' + + disable_ddl_transaction! + + def up + add_concurrent_index :members, + :source_id, + where: '((requested_at IS NULL) AND (invite_token IS NULL) AND (access_level > 5) AND (state = 1))', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :members, INDEX_NAME + end +end diff --git a/db/migrate/20220405061122_add_license_scanning_action_to_onboarding_progresses.rb b/db/migrate/20220405061122_add_license_scanning_action_to_onboarding_progresses.rb new file mode 100644 index 00000000000..0c07d1f18ba --- /dev/null +++ b/db/migrate/20220405061122_add_license_scanning_action_to_onboarding_progresses.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddLicenseScanningActionToOnboardingProgresses < Gitlab::Database::Migration[1.0] + def change + add_column :onboarding_progresses, :license_scanning_run_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20220405125459_add_non_migrated_index_to_container_repositories.rb b/db/migrate/20220405125459_add_non_migrated_index_to_container_repositories.rb new file mode 100644 index 00000000000..7aad10c288b --- /dev/null +++ b/db/migrate/20220405125459_add_non_migrated_index_to_container_repositories.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddNonMigratedIndexToContainerRepositories < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + # follow up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/358407 + INDEX_NAME = 'tmp_idx_container_repos_on_non_migrated' + MIGRATION_PHASE_1_ENDED_AT = '2022-01-23' + + def up + add_concurrent_index :container_repositories, + [:project_id, :id], + name: INDEX_NAME, + where: "migration_state != 'import_done' AND created_at < '#{MIGRATION_PHASE_1_ENDED_AT}'" + end + + def down + remove_concurrent_index_by_name :container_repositories, INDEX_NAME + end +end diff --git a/db/migrate/20220405181814_add_arkose_settings_to_application_settings.rb b/db/migrate/20220405181814_add_arkose_settings_to_application_settings.rb new file mode 100644 index 00000000000..d8c06cd8229 --- /dev/null +++ b/db/migrate/20220405181814_add_arkose_settings_to_application_settings.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class AddArkoseSettingsToApplicationSettings < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220405203843_add_text_limit_to_arkose_verify_url_application_settings.rb + def up + add_column :application_settings, :encrypted_arkose_labs_public_api_key, :binary + add_column :application_settings, :encrypted_arkose_labs_public_api_key_iv, :binary + + add_column :application_settings, :encrypted_arkose_labs_private_api_key, :binary + add_column :application_settings, :encrypted_arkose_labs_private_api_key_iv, :binary + + add_column :application_settings, :arkose_labs_verify_api_url, :text + end + # rubocop:enable Migration/AddLimitToTextColumns + + def down + remove_column :application_settings, :encrypted_arkose_labs_public_api_key + remove_column :application_settings, :encrypted_arkose_labs_public_api_key_iv + + remove_column :application_settings, :encrypted_arkose_labs_private_api_key + remove_column :application_settings, :encrypted_arkose_labs_private_api_key_iv + + remove_column :application_settings, :arkose_labs_verify_api_url + end +end diff --git a/db/migrate/20220405203843_add_text_limit_to_arkose_verify_url_application_settings.rb b/db/migrate/20220405203843_add_text_limit_to_arkose_verify_url_application_settings.rb new file mode 100644 index 00000000000..f3c7960b29d --- /dev/null +++ b/db/migrate/20220405203843_add_text_limit_to_arkose_verify_url_application_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToArkoseVerifyUrlApplicationSettings < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :arkose_labs_verify_api_url, 255 + end + + def down + remove_text_limit :application_settings, :arkose_labs_verify_api_url + end +end diff --git a/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb b/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb new file mode 100644 index 00000000000..78970d308d9 --- /dev/null +++ b/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddInactiveProjectDeletionToApplicationSettings < Gitlab::Database::Migration[1.0] + def change + add_column :application_settings, :delete_inactive_projects, :boolean, default: false, null: false + add_column :application_settings, :inactive_projects_delete_after_months, :integer, default: 2, null: false + add_column :application_settings, :inactive_projects_min_size_mb, :integer, default: 0, null: false + add_column :application_settings, :inactive_projects_send_warning_email_after_months, :integer, default: 1, + null: false + end +end diff --git a/db/migrate/20220406121831_add_index_on_status_for_batched_background_migrations.rb b/db/migrate/20220406121831_add_index_on_status_for_batched_background_migrations.rb new file mode 100644 index 00000000000..bc3b9125b4b --- /dev/null +++ b/db/migrate/20220406121831_add_index_on_status_for_batched_background_migrations.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddIndexOnStatusForBatchedBackgroundMigrations < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_index :batched_background_migrations, :status + end + + def down + remove_concurrent_index_by_name :batched_background_migrations, :index_batched_background_migrations_on_status + end +end diff --git a/db/migrate/20220407135820_add_epics_relative_position.rb b/db/migrate/20220407135820_add_epics_relative_position.rb new file mode 100644 index 00000000000..8ab62667e1e --- /dev/null +++ b/db/migrate/20220407135820_add_epics_relative_position.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddEpicsRelativePosition < Gitlab::Database::Migration[1.0] + DOWNTIME = false + + def up + return unless table_exists?(:epics) + return if column_exists?(:epics, :relative_position) + + add_column :epics, :relative_position, :integer + + execute('UPDATE epics SET relative_position=id*500') + end + + def down + # no-op - this column should normally exist if epics table exists too + end +end diff --git a/db/migrate/20220408001450_add_work_item_type_name_unique_index_null_namespaces.rb b/db/migrate/20220408001450_add_work_item_type_name_unique_index_null_namespaces.rb new file mode 100644 index 00000000000..bcb0e32a4e7 --- /dev/null +++ b/db/migrate/20220408001450_add_work_item_type_name_unique_index_null_namespaces.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddWorkItemTypeNameUniqueIndexNullNamespaces < Gitlab::Database::Migration[1.0] + INDEX_NAME = :idx_work_item_types_on_namespace_id_and_name_null_namespace + + disable_ddl_transaction! + + def up + add_concurrent_index :work_item_types, + 'TRIM(BOTH FROM LOWER(name)), (namespace_id IS NULL)', + unique: true, + name: INDEX_NAME, + where: 'namespace_id IS NULL' + end + + def down + remove_concurrent_index_by_name :work_item_types, INDEX_NAME + end +end diff --git a/db/migrate/20220408135815_update_index_on_greated_done_at_on_container_repositories.rb b/db/migrate/20220408135815_update_index_on_greated_done_at_on_container_repositories.rb new file mode 100644 index 00000000000..b906a867895 --- /dev/null +++ b/db/migrate/20220408135815_update_index_on_greated_done_at_on_container_repositories.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UpdateIndexOnGreatedDoneAtOnContainerRepositories < Gitlab::Database::Migration[1.0] + OLD_INDEX_NAME = 'index_container_repositories_on_greatest_done_at' + NEW_INDEX_NAME = 'index_container_repositories_on_greatest_completed_at' + + disable_ddl_transaction! + + def up + add_concurrent_index :container_repositories, + 'GREATEST(migration_pre_import_done_at, migration_import_done_at, migration_aborted_at, migration_skipped_at)', + where: "migration_state IN ('import_done', 'pre_import_done', 'import_aborted', 'import_skipped')", + name: NEW_INDEX_NAME + remove_concurrent_index_by_name :container_repositories, OLD_INDEX_NAME + end + + def down + add_concurrent_index :container_repositories, + 'GREATEST(migration_pre_import_done_at, migration_import_done_at, migration_aborted_at)', + where: "migration_state IN ('import_done', 'pre_import_done', 'import_aborted')", + name: OLD_INDEX_NAME + remove_concurrent_index_by_name :container_repositories, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20220412171810_add_otp_secret_expires_at.rb b/db/migrate/20220412171810_add_otp_secret_expires_at.rb new file mode 100644 index 00000000000..883293c87f8 --- /dev/null +++ b/db/migrate/20220412171810_add_otp_secret_expires_at.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddOtpSecretExpiresAt < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + # rubocop: disable Migration/AddColumnsToWideTables + add_column :users, :otp_secret_expires_at, :datetime_with_timezone + # rubocop: enable Migration/AddColumnsToWideTables + end +end diff --git a/db/migrate/20220413075921_update_index_on_packages_build_infos.rb b/db/migrate/20220413075921_update_index_on_packages_build_infos.rb new file mode 100644 index 00000000000..96f37fab24e --- /dev/null +++ b/db/migrate/20220413075921_update_index_on_packages_build_infos.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class UpdateIndexOnPackagesBuildInfos < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + NEW_INDEX_NAME = 'index_packages_build_infos_package_id_pipeline_id_id' + OLD_INDEX_NAME = 'index_packages_build_infos_package_id_pipeline_id' + + def up + add_concurrent_index :packages_build_infos, + [:package_id, :pipeline_id, :id], + name: NEW_INDEX_NAME + remove_concurrent_index_by_name :packages_build_infos, OLD_INDEX_NAME + end + + def down + add_concurrent_index :packages_build_infos, + [:package_id, :pipeline_id], + name: OLD_INDEX_NAME + remove_concurrent_index_by_name :packages_build_infos, NEW_INDEX_NAME + end +end |