diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /db/post_migrate | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'db/post_migrate')
46 files changed, 1092 insertions, 77 deletions
diff --git a/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb b/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb index b4570c8398b..0377df7a46b 100644 --- a/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb +++ b/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb @@ -1,44 +1,14 @@ # frozen_string_literal: true class RescheduleArtifactExpiryBackfillAgain < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'BackfillArtifactExpiryDate' - SWITCH_DATE = Date.new(2020, 06, 22).freeze - - disable_ddl_transaction! - - class JobArtifact < ActiveRecord::Base - include EachBatch - - self.inheritance_column = :_type_disabled - self.table_name = 'ci_job_artifacts' - - scope :without_expiry_date, -> { where(expire_at: nil) } - scope :before_switch, -> { where("date(created_at AT TIME ZONE 'UTC') < ?::date", SWITCH_DATE) } - end + # This migration has been disabled as it was causing a regression bug for self instances + # preventing artifact deletion, see https://gitlab.com/gitlab-org/gitlab/-/issues/355955 def up - Gitlab::BackgroundMigration.steal(MIGRATION) do |job| - job.delete - - false - end - - queue_background_migration_jobs_by_range_at_intervals( - JobArtifact.without_expiry_date.before_switch, - MIGRATION, - 2.minutes, - batch_size: 200_000 - ) + # no-op end def down - Gitlab::BackgroundMigration.steal(MIGRATION) do |job| - job.delete - - false - end + # no-op end end diff --git a/db/post_migrate/20211103184303_drop_runner_features_from_ci_builds_metadata.rb b/db/post_migrate/20211103184303_drop_runner_features_from_ci_builds_metadata.rb new file mode 100644 index 00000000000..00580b2f933 --- /dev/null +++ b/db/post_migrate/20211103184303_drop_runner_features_from_ci_builds_metadata.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class DropRunnerFeaturesFromCiBuildsMetadata < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + remove_column :ci_builds_metadata, :runner_features + end + + def down + add_column :ci_builds_metadata, :runner_features, :jsonb, default: {}, null: false + end +end diff --git a/db/post_migrate/20220213103859_remove_integrations_type.rb b/db/post_migrate/20220213103859_remove_integrations_type.rb new file mode 100644 index 00000000000..c3633d1e7d3 --- /dev/null +++ b/db/post_migrate/20220213103859_remove_integrations_type.rb @@ -0,0 +1,132 @@ +# frozen_string_literal: true + +class RemoveIntegrationsType < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'BackfillIntegrationsTypeNew' + BATCH_SIZE = 50 + TABLE_NAME = :integrations + COLUMN = :type + + # see db/post_migrate/20220213104531_create_indexes_on_integration_type_new.rb + def indices + [ + { + name: "index_integrations_on_project_and_#{COLUMN}_where_inherit_null", + columns: [:project_id, COLUMN], + where: 'inherit_from_id IS NULL' + }, + { + name: "index_integrations_on_project_id_and_#{COLUMN}_unique", + columns: [:project_id, COLUMN], + unique: true + }, + { + name: "index_integrations_on_#{COLUMN}", + columns: [COLUMN] + }, + { + name: "index_integrations_on_#{COLUMN}_and_instance_partial", + columns: [COLUMN, :instance], + where: 'instance = true', + unique: true + }, + { + name: 'index_integrations_on_type_id_when_active_and_project_id_not_nu', + columns: [COLUMN, :id], + where: '((active = true) AND (project_id IS NOT NULL))' + }, + { + name: "index_integrations_on_unique_group_id_and_#{COLUMN}", + columns: [:group_id, COLUMN], + unique: true + } + ] + end + + def up + ensure_batched_background_migration_is_finished( + job_class_name: MIGRATION, + table_name: TABLE_NAME, + column_name: :id, + job_arguments: []) + + cleanup_unmigrated_rows! + + remove_column :integrations, :type, :text + end + + # WARNING: this migration is not really safe to be reverted, since doing so + # will leave the type column empty. If this migration is reverted, we will + # need to backfill it from type_new + def down + add_column :integrations, :type, 'character varying' + + indices.each do |index| + add_concurrent_index TABLE_NAME, index[:columns], index.except(:columns) + end + end + + # Convert any remaining unmigrated rows + def cleanup_unmigrated_rows! + tmp_index_name = 'tmp_idx_integrations_unmigrated_type_new' + add_concurrent_index :integrations, :id, where: 'type_new is null', name: tmp_index_name + + define_batchable_model(:integrations).where(type_new: nil).each_batch do |batch| + min_id, max_id = batch.pluck(Arel.sql('MIN(id), MAX(id)')).first + + connection.execute(<<~SQL) + WITH mapping(old_type, new_type) AS (VALUES + ('AsanaService', 'Integrations::Asana'), + ('AssemblaService', 'Integrations::Assembla'), + ('BambooService', 'Integrations::Bamboo'), + ('BugzillaService', 'Integrations::Bugzilla'), + ('BuildkiteService', 'Integrations::Buildkite'), + ('CampfireService', 'Integrations::Campfire'), + ('ConfluenceService', 'Integrations::Confluence'), + ('CustomIssueTrackerService', 'Integrations::CustomIssueTracker'), + ('DatadogService', 'Integrations::Datadog'), + ('DiscordService', 'Integrations::Discord'), + ('DroneCiService', 'Integrations::DroneCi'), + ('EmailsOnPushService', 'Integrations::EmailsOnPush'), + ('EwmService', 'Integrations::Ewm'), + ('ExternalWikiService', 'Integrations::ExternalWiki'), + ('FlowdockService', 'Integrations::Flowdock'), + ('HangoutsChatService', 'Integrations::HangoutsChat'), + ('IrkerService', 'Integrations::Irker'), + ('JenkinsService', 'Integrations::Jenkins'), + ('JiraService', 'Integrations::Jira'), + ('MattermostService', 'Integrations::Mattermost'), + ('MattermostSlashCommandsService', 'Integrations::MattermostSlashCommands'), + ('MicrosoftTeamsService', 'Integrations::MicrosoftTeams'), + ('MockCiService', 'Integrations::MockCi'), + ('MockMonitoringService', 'Integrations::MockMonitoring'), + ('PackagistService', 'Integrations::Packagist'), + ('PipelinesEmailService', 'Integrations::PipelinesEmail'), + ('PivotaltrackerService', 'Integrations::Pivotaltracker'), + ('PrometheusService', 'Integrations::Prometheus'), + ('PushoverService', 'Integrations::Pushover'), + ('RedmineService', 'Integrations::Redmine'), + ('SlackService', 'Integrations::Slack'), + ('SlackSlashCommandsService', 'Integrations::SlackSlashCommands'), + ('TeamcityService', 'Integrations::Teamcity'), + ('UnifyCircuitService', 'Integrations::UnifyCircuit'), + ('WebexTeamsService', 'Integrations::WebexTeams'), + ('YoutrackService', 'Integrations::Youtrack'), + + -- EE-only integrations + ('GithubService', 'Integrations::Github'), + ('GitlabSlackApplicationService', 'Integrations::GitlabSlackApplication') + ) + + UPDATE integrations SET type_new = mapping.new_type + FROM mapping + WHERE integrations.type_new IS NULL + AND integrations.id BETWEEN #{min_id} AND #{max_id} + AND integrations.type = mapping.old_type + SQL + end + ensure + remove_concurrent_index_by_name(:integrations, tmp_index_name) + end +end diff --git a/db/post_migrate/20220314154235_migrate_vulnerability_approval_rules.rb b/db/post_migrate/20220314154235_migrate_vulnerability_approval_rules.rb new file mode 100644 index 00000000000..f9ad2ba4f0c --- /dev/null +++ b/db/post_migrate/20220314154235_migrate_vulnerability_approval_rules.rb @@ -0,0 +1,17 @@ +# 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 MigrateVulnerabilityApprovalRules < Gitlab::Database::Migration[2.0] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # no-op + end + + def down + # no-op + # Vulnerability-Check feature has been removed as part of 15.0 + end +end diff --git a/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb index 8838a27f233..2249413b1e4 100644 --- a/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb +++ b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb @@ -1,40 +1,13 @@ # frozen_string_literal: true class BackfillWorkItemTypeIdOnIssues < Gitlab::Database::Migration[1.0] - MIGRATION = 'BackfillWorkItemTypeIdForIssues' - BATCH_CLASS_NAME = 'BackfillIssueWorkItemTypeBatchingStrategy' - BATCH_SIZE = 10_000 - MAX_BATCH_SIZE = 30_000 - SUB_BATCH_SIZE = 100 - INTERVAL = 2.minutes - - class MigrationWorkItemType < ApplicationRecord - self.table_name = 'work_item_types' - - def self.id_by_type - where(namespace_id: nil).order(:base_type).pluck(:base_type, :id).to_h - end - end - def up - # We expect no more than 5 types. Only 3 of them are expected to have associated issues at the moment - MigrationWorkItemType.id_by_type.each do |base_type, type_id| - queue_batched_background_migration( - MIGRATION, - :issues, - :id, - base_type, - type_id, - job_interval: INTERVAL, - batch_size: BATCH_SIZE, - max_batch_size: MAX_BATCH_SIZE, - sub_batch_size: SUB_BATCH_SIZE, - batch_class_name: BATCH_CLASS_NAME - ) - end + # no-op + # This migration will be rescheduled as described in + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85212 end def down - Gitlab::Database::BackgroundMigration::BatchedMigration.where(job_class_name: MIGRATION).delete_all + # no-op end end diff --git a/db/post_migrate/20220324165436_schedule_backfill_project_settings.rb b/db/post_migrate/20220324165436_schedule_backfill_project_settings.rb new file mode 100644 index 00000000000..c1aaea44bfd --- /dev/null +++ b/db/post_migrate/20220324165436_schedule_backfill_project_settings.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ScheduleBackfillProjectSettings < Gitlab::Database::Migration[1.0] + MIGRATION = 'BackfillProjectSettings' + INTERVAL = 2.minutes + BATCH_SIZE = 5_000 + SUB_BATCH_SIZE = 200 + + def up + queue_batched_background_migration( + MIGRATION, + :projects, + :id, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :projects, :id, []) + .delete_all + end +end diff --git a/db/post_migrate/20220328095848_delete_failed_reset_duplicate_ci_runners_token_migration_records.rb b/db/post_migrate/20220328095848_delete_failed_reset_duplicate_ci_runners_token_migration_records.rb new file mode 100644 index 00000000000..3c1a6a48ef5 --- /dev/null +++ b/db/post_migrate/20220328095848_delete_failed_reset_duplicate_ci_runners_token_migration_records.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DeleteFailedResetDuplicateCiRunnersTokenMigrationRecords < Gitlab::Database::Migration[1.0] + def up + # Delete remaining records of botched migrations before we start the new migrations + Gitlab::Database::BackgroundMigrationJob + .for_migration_class('ResetDuplicateCiRunnersTokenValuesOnProjects') + .delete_all + Gitlab::Database::BackgroundMigrationJob + .for_migration_class('ResetDuplicateCiRunnersTokenEncryptedValuesOnProjects') + .delete_all + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220328100456_schedule20220328_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb b/db/post_migrate/20220328100456_schedule20220328_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb new file mode 100644 index 00000000000..326a8e30ecb --- /dev/null +++ b/db/post_migrate/20220328100456_schedule20220328_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class Schedule20220328ResetDuplicateCiRunnersTokenEncryptedValuesOnProjects < Gitlab::Database::Migration[1.0] + MIGRATION = 'ResetDuplicateCiRunnersTokenEncryptedValuesOnProjects' + BATCH_SIZE = 2_000 + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + class Project < ActiveRecord::Base # rubocop:disable Style/Documentation + include ::EachBatch + + self.table_name = 'projects' + + scope :base_query, -> { where.not(runners_token_encrypted: nil) } + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Project.base_query, + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220328100457_schedule20220328_reset_duplicate_ci_runners_token_values_on_projects.rb b/db/post_migrate/20220328100457_schedule20220328_reset_duplicate_ci_runners_token_values_on_projects.rb new file mode 100644 index 00000000000..d999def0078 --- /dev/null +++ b/db/post_migrate/20220328100457_schedule20220328_reset_duplicate_ci_runners_token_values_on_projects.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class Schedule20220328ResetDuplicateCiRunnersTokenValuesOnProjects < Gitlab::Database::Migration[1.0] + MIGRATION = 'ResetDuplicateCiRunnersTokenValuesOnProjects' + BATCH_SIZE = 2_000 + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + class Project < ActiveRecord::Base # rubocop:disable Style/Documentation + include ::EachBatch + + self.table_name = 'projects' + + scope :base_query, -> { where.not(runners_token: nil) } + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Project.base_query, + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220331133802_schedule_backfill_topics_title.rb b/db/post_migrate/20220331133802_schedule_backfill_topics_title.rb new file mode 100644 index 00000000000..8e594a9df52 --- /dev/null +++ b/db/post_migrate/20220331133802_schedule_backfill_topics_title.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class ScheduleBackfillTopicsTitle < Gitlab::Database::Migration[1.0] + MIGRATION = 'BackfillTopicsTitle' + DELAY_INTERVAL = 2.minutes + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('topics'), + MIGRATION, + DELAY_INTERVAL, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb b/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb index 1f2c0715f04..9b74cef144f 100644 --- a/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb +++ b/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb @@ -1,21 +1,13 @@ # frozen_string_literal: true class ReplaceWorkItemTypeBackfillNextBatchStrategy < Gitlab::Database::Migration[1.0] - JOB_CLASS_NAME = 'BackfillWorkItemTypeIdForIssues' - NEW_STRATEGY_CLASS = 'BackfillIssueWorkItemTypeBatchingStrategy' - OLD_STRATEGY_CLASS = 'PrimaryKeyBatchingStrategy' - - class InlineBatchedMigration < ApplicationRecord - self.table_name = :batched_background_migrations - end - def up - InlineBatchedMigration.where(job_class_name: JOB_CLASS_NAME) - .update_all(batch_class_name: NEW_STRATEGY_CLASS) + # no-op + # migrations will be rescheduled with the correct batching class + # no need for this migration end def down - InlineBatchedMigration.where(job_class_name: JOB_CLASS_NAME) - .update_all(batch_class_name: OLD_STRATEGY_CLASS) + # no-op end end diff --git a/db/post_migrate/20220405092619_toggle_vsa_aggregations_enable.rb b/db/post_migrate/20220405092619_toggle_vsa_aggregations_enable.rb new file mode 100644 index 00000000000..da1353b5cf9 --- /dev/null +++ b/db/post_migrate/20220405092619_toggle_vsa_aggregations_enable.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ToggleVsaAggregationsEnable < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + model = define_batchable_model('analytics_cycle_analytics_aggregations') + + model.each_batch(of: 100) do |relation| + relation.where('enabled IS FALSE').update_all(enabled: true) + end + end + + def down + # noop + end +end diff --git a/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb b/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb new file mode 100644 index 00000000000..f7132407adb --- /dev/null +++ b/db/post_migrate/20220411173544_cleanup_orphans_approval_project_rules.rb @@ -0,0 +1,38 @@ +# 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 CleanupOrphansApprovalProjectRules < Gitlab::Database::Migration[1.0] + class ApprovalProjectRule < ActiveRecord::Base + self.table_name = 'approval_project_rules' + end + + def up + return unless Gitlab.ee? + + ApprovalProjectRule.reset_column_information + + logger = ::Gitlab::BackgroundMigration::Logger.build + records_ids = [] + + # Related enum: report_type: { vulnerability: 1, license_scanning: 2, code_coverage: 3, scan_finding: 4 } + ApprovalProjectRule.where(report_type: 4) + .joins("LEFT JOIN security_orchestration_policy_configurations + ON approval_project_rules.project_id = security_orchestration_policy_configurations.project_id") + .where(security_orchestration_policy_configurations: { project_id: nil }).each do |record| + records_ids << record.id + logger.info( + message: "CleanupOrphansApprovalProjectRules with record id: #{record.id}", + class: ApprovalProjectRule.name, + attributes: record.attributes + ) + end + + ApprovalProjectRule.where(id: records_ids).delete_all + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb b/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb index f2aa9c0b717..fb43e13364d 100644 --- a/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb +++ b/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class FinalizeTraversalIdsBackgroundMigrations < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + def up finalize_background_migration('BackfillNamespaceTraversalIdsRoots') finalize_background_migration('BackfillNamespaceTraversalIdsChildren') diff --git a/db/post_migrate/20220415124802_remove_job_artifact_deprecated_geo_fields.rb b/db/post_migrate/20220415124802_remove_job_artifact_deprecated_geo_fields.rb new file mode 100644 index 00000000000..65432ba3ce1 --- /dev/null +++ b/db/post_migrate/20220415124802_remove_job_artifact_deprecated_geo_fields.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class RemoveJobArtifactDeprecatedGeoFields < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + with_lock_retries do + remove_column :geo_event_log, :job_artifact_deleted_event_id, :bigint + end + end + + def down + with_lock_retries do + unless column_exists?(:geo_event_log, :job_artifact_deleted_event_id) + add_column(:geo_event_log, :job_artifact_deleted_event_id, :bigint) + end + end + + add_concurrent_foreign_key :geo_event_log, :geo_job_artifact_deleted_events, + column: :job_artifact_deleted_event_id, + name: 'fk_176d3fbb5d', + on_delete: :cascade + + add_concurrent_index :geo_event_log, + :job_artifact_deleted_event_id, + name: 'index_geo_event_log_on_job_artifact_deleted_event_id', + where: "(job_artifact_deleted_event_id IS NOT NULL)" + end +end diff --git a/db/post_migrate/20220415124804_remove_job_artifact_deleted_event_table.rb b/db/post_migrate/20220415124804_remove_job_artifact_deleted_event_table.rb new file mode 100644 index 00000000000..05b716f26ab --- /dev/null +++ b/db/post_migrate/20220415124804_remove_job_artifact_deleted_event_table.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class RemoveJobArtifactDeletedEventTable < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + drop_table :geo_job_artifact_deleted_events + end + + def down + create_table :geo_job_artifact_deleted_events, id: :bigserial do |t| + t.bigint :job_artifact_id, null: false, index: true + t.string :file_path, null: false + end + end +end diff --git a/db/post_migrate/20220420061439_add_notes_null_discussion_id_temp_index.rb b/db/post_migrate/20220420061439_add_notes_null_discussion_id_temp_index.rb new file mode 100644 index 00000000000..35a6d5f5b10 --- /dev/null +++ b/db/post_migrate/20220420061439_add_notes_null_discussion_id_temp_index.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotesNullDiscussionIdTempIndex < Gitlab::Database::Migration[2.0] + # Temporary index to be removed in 15.0 https://gitlab.com/gitlab-org/gitlab/-/issues/357581 + INDEX_NAME = 'tmp_index_notes_on_id_where_discussion_id_is_null' + + disable_ddl_transaction! + + def up + add_concurrent_index :notes, :id, where: 'discussion_id IS NULL', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :notes, INDEX_NAME + end +end diff --git a/db/post_migrate/20220420061450_backfill_null_note_discussion_ids.rb b/db/post_migrate/20220420061450_backfill_null_note_discussion_ids.rb new file mode 100644 index 00000000000..8880bc2f748 --- /dev/null +++ b/db/post_migrate/20220420061450_backfill_null_note_discussion_ids.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class BackfillNullNoteDiscussionIds < Gitlab::Database::Migration[2.0] + MIGRATION = 'BackfillNoteDiscussionId' + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 10_000 + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + disable_ddl_transaction! + + class Note < MigrationRecord + include EachBatch + + self.table_name = 'notes' + self.inheritance_column = :_type_disabled + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Note.where(discussion_id: nil), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220420135946_update_batched_background_migration_arguments.rb b/db/post_migrate/20220420135946_update_batched_background_migration_arguments.rb new file mode 100644 index 00000000000..40ed98dcb5e --- /dev/null +++ b/db/post_migrate/20220420135946_update_batched_background_migration_arguments.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class UpdateBatchedBackgroundMigrationArguments < Gitlab::Database::Migration[1.0] + def up + execute(<<~SQL) + UPDATE batched_background_migrations + SET job_arguments = '[]' + WHERE job_arguments = '"[]"'; + SQL + end + + def down + execute(<<~SQL) + UPDATE batched_background_migrations + SET job_arguments = '"[]"' + WHERE job_arguments = '[]'; + SQL + end +end diff --git a/db/post_migrate/20220420214703_schedule_backfill_draft_status_on_merge_requests_corrected_regex.rb b/db/post_migrate/20220420214703_schedule_backfill_draft_status_on_merge_requests_corrected_regex.rb new file mode 100644 index 00000000000..1001aca583b --- /dev/null +++ b/db/post_migrate/20220420214703_schedule_backfill_draft_status_on_merge_requests_corrected_regex.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class ScheduleBackfillDraftStatusOnMergeRequestsCorrectedRegex < Gitlab::Database::Migration[1.0] + INDEX_NAME = "tmp_index_merge_requests_draft_and_status" + MIGRATION = "BackfillDraftStatusOnMergeRequestsWithCorrectedRegex" + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 50 + CORRECTED_REGEXP_STR = "^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)" + + disable_ddl_transaction! + + def up + add_concurrent_index :merge_requests, :id, + where: "draft = false AND state_id = 1 AND ((title)::text ~* '#{CORRECTED_REGEXP_STR}'::text)", + name: INDEX_NAME + + eligible_mrs = MergeRequest.where(state_id: 1) + .where(draft: false) + .where("title ~* ?", "#{CORRECTED_REGEXP_STR}") + + queue_background_migration_jobs_by_range_at_intervals( + eligible_mrs, + MIGRATION, + DELAY_INTERVAL, + track_jobs: true, + batch_size: BATCH_SIZE + ) + end + + def down + remove_concurrent_index_by_name :merge_requests, INDEX_NAME + end +end diff --git a/db/post_migrate/20220422121443_add_async_index_for_group_activity_events.rb b/db/post_migrate/20220422121443_add_async_index_for_group_activity_events.rb new file mode 100644 index 00000000000..92b97203eed --- /dev/null +++ b/db/post_migrate/20220422121443_add_async_index_for_group_activity_events.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddAsyncIndexForGroupActivityEvents < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_events_for_group_activity' + + def up + prepare_async_index :events, %I[group_id target_type action id], name: INDEX_NAME, where: 'group_id IS NOT NULL' + end + + def down + unprepare_async_index :events, %I[group_id target_type action id], name: INDEX_NAME, where: 'group_id IS NOT NULL' + end +end diff --git a/db/post_migrate/20220425111114_add_async_index_for_project_activity_events.rb b/db/post_migrate/20220425111114_add_async_index_for_project_activity_events.rb new file mode 100644 index 00000000000..b203ceca976 --- /dev/null +++ b/db/post_migrate/20220425111114_add_async_index_for_project_activity_events.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddAsyncIndexForProjectActivityEvents < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_events_for_project_activity' + + def up + prepare_async_index :events, %I[project_id target_type action id], name: INDEX_NAME + end + + def down + unprepare_async_index :events, %I[project_id target_type action id], name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220425111453_add_async_index_to_events_on_group_id_and_id.rb b/db/post_migrate/20220425111453_add_async_index_to_events_on_group_id_and_id.rb new file mode 100644 index 00000000000..313a31d8964 --- /dev/null +++ b/db/post_migrate/20220425111453_add_async_index_to_events_on_group_id_and_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddAsyncIndexToEventsOnGroupIdAndId < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_events_on_group_id_and_id' + + def up + prepare_async_index :events, %I[group_id id], name: INDEX_NAME, where: 'group_id IS NOT NULL' + end + + def down + unprepare_async_index :events, %I[group_id id], name: INDEX_NAME, where: 'group_id IS NOT NULL' + end +end diff --git a/db/post_migrate/20220425121410_add_temporary_index_for_backfill_integrations_enable_ssl_verification.rb b/db/post_migrate/20220425121410_add_temporary_index_for_backfill_integrations_enable_ssl_verification.rb new file mode 100644 index 00000000000..d0f8e60fa54 --- /dev/null +++ b/db/post_migrate/20220425121410_add_temporary_index_for_backfill_integrations_enable_ssl_verification.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddTemporaryIndexForBackfillIntegrationsEnableSslVerification < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'tmp_index_integrations_on_id_where_type_droneci_or_teamcity' + INDEX_CONDITION = "type_new IN ('Integrations::DroneCi', 'Integrations::Teamcity') " \ + "AND encrypted_properties IS NOT NULL" + + def up + # this index is used in 20220209121435_backfill_integrations_enable_ssl_verification + add_concurrent_index :integrations, :id, where: INDEX_CONDITION, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :integrations, INDEX_NAME + end +end diff --git a/db/post_migrate/20220425121435_backfill_integrations_enable_ssl_verification.rb b/db/post_migrate/20220425121435_backfill_integrations_enable_ssl_verification.rb new file mode 100644 index 00000000000..101bde975db --- /dev/null +++ b/db/post_migrate/20220425121435_backfill_integrations_enable_ssl_verification.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +class BackfillIntegrationsEnableSslVerification < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + MIGRATION = 'BackfillIntegrationsEnableSslVerification' + INTERVAL = 5.minutes + BATCH_SIZE = 1_000 + + class Integration < MigrationRecord + include EachBatch + include IgnorableColumns + + self.table_name = :integrations + self.inheritance_column = :_type_disabled + + ignore_column :template, remove_with: '15.0', remove_after: '2022-04-22' + ignore_column :type, remove_with: '15.0', remove_after: '2022-04-22' + ignore_column :properties, remove_with: '15.1', remove_after: '2022-05-22' + + scope :affected, -> do + where(type_new: %w[Integrations::DroneCi Integrations::Teamcity]).where.not(encrypted_properties: nil) + end + + attr_encrypted :properties, + mode: :per_attribute_iv, + key: Settings.attr_encrypted_db_key_base_32, + algorithm: 'aes-256-gcm', + marshal: true, + marshaler: ::Gitlab::Json, + encode: false, + encode_iv: false + + # Handle assignment of props with symbol keys. + # To do this correctly, we need to call the method generated by attr_encrypted. + alias_method :attr_encrypted_props=, :properties= + private :attr_encrypted_props= + + def properties=(props) + self.attr_encrypted_props = props&.with_indifferent_access&.freeze + end + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Integration.affected, + MIGRATION, + INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + end +end diff --git a/db/post_migrate/20220426185933_backfill_deployments_finished_at.rb b/db/post_migrate/20220426185933_backfill_deployments_finished_at.rb new file mode 100644 index 00000000000..860756de298 --- /dev/null +++ b/db/post_migrate/20220426185933_backfill_deployments_finished_at.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class BackfillDeploymentsFinishedAt < Gitlab::Database::Migration[2.0] + DEPLOYMENT_STATUS_SUCCESS = 2 # Equivalent to Deployment.statuses[:success] + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + BATCH_SIZE = 100 + + def up + define_batchable_model('deployments') + .where(finished_at: nil) + .where(status: DEPLOYMENT_STATUS_SUCCESS) + .each_batch(of: BATCH_SIZE) { |relation| relation.update_all('finished_at = created_at') } + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220428133724_schedule_expire_o_auth_tokens.rb b/db/post_migrate/20220428133724_schedule_expire_o_auth_tokens.rb new file mode 100644 index 00000000000..3e0e9b8af0e --- /dev/null +++ b/db/post_migrate/20220428133724_schedule_expire_o_auth_tokens.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ScheduleExpireOAuthTokens < Gitlab::Database::Migration[2.0] + def up + # reschedulled with db/post_migrate/20220513043344_reschedule_expire_o_auth_tokens.rb + end + + def down + # reschedulled with db/post_migrate/20220513043344_reschedule_expire_o_auth_tokens.rb + end +end diff --git a/db/post_migrate/20220502015011_clean_up_fix_merge_request_diff_commit_users.rb b/db/post_migrate/20220502015011_clean_up_fix_merge_request_diff_commit_users.rb new file mode 100644 index 00000000000..582a0f5cf37 --- /dev/null +++ b/db/post_migrate/20220502015011_clean_up_fix_merge_request_diff_commit_users.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CleanUpFixMergeRequestDiffCommitUsers < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION_CLASS = 'FixMergeRequestDiffCommitUsers' + + def up + finalize_background_migration(MIGRATION_CLASS) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220502173045_reset_too_many_tags_skipped_registry_imports.rb b/db/post_migrate/20220502173045_reset_too_many_tags_skipped_registry_imports.rb new file mode 100644 index 00000000000..e327035d6c9 --- /dev/null +++ b/db/post_migrate/20220502173045_reset_too_many_tags_skipped_registry_imports.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class ResetTooManyTagsSkippedRegistryImports < Gitlab::Database::Migration[2.0] + MIGRATION = 'ResetTooManyTagsSkippedRegistryImports' + DELAY_INTERVAL = 2.minutes.to_i + BATCH_SIZE = 10_000 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('container_repositories').where( + migration_state: 'import_skipped', + migration_skipped_reason: 2 + ), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE, + track_jobs: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20220503114353_prepare_confidential_note_index.rb b/db/post_migrate/20220503114353_prepare_confidential_note_index.rb new file mode 100644 index 00000000000..08e60f3d935 --- /dev/null +++ b/db/post_migrate/20220503114353_prepare_confidential_note_index.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class PrepareConfidentialNoteIndex < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'index_notes_on_confidential' + + def up + prepare_async_index :notes, :confidential, where: 'confidential = true', name: INDEX_NAME + end + + def down + unprepare_async_index :notes, :confidential, name: INDEX_NAME + end +end diff --git a/db/post_migrate/20220503134610_remove_requirements_management_test_reports_requirement_id.rb b/db/post_migrate/20220503134610_remove_requirements_management_test_reports_requirement_id.rb new file mode 100644 index 00000000000..4c46a02c99f --- /dev/null +++ b/db/post_migrate/20220503134610_remove_requirements_management_test_reports_requirement_id.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class RemoveRequirementsManagementTestReportsRequirementId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + TARGET_TABLE = :requirements_management_test_reports + CONSTRAINT_NAME = 'fk_rails_fb3308ad55' + + def up + with_lock_retries do + remove_column TARGET_TABLE, :requirement_id + end + end + + def down + unless column_exists?(TARGET_TABLE, :requirement_id) + with_lock_retries do + add_column TARGET_TABLE, :requirement_id, :bigint, after: :created_at + end + end + + add_concurrent_index TARGET_TABLE, :requirement_id, + name: :index_requirements_management_test_reports_on_requirement_id + + add_concurrent_foreign_key TARGET_TABLE, :requirements, + column: :requirement_id, name: CONSTRAINT_NAME, on_delete: :cascade + end +end diff --git a/db/post_migrate/20220504083348_add_indexes_for_primary_email_post_regression_cleanup_migration.rb b/db/post_migrate/20220504083348_add_indexes_for_primary_email_post_regression_cleanup_migration.rb new file mode 100644 index 00000000000..ba0457fa36e --- /dev/null +++ b/db/post_migrate/20220504083348_add_indexes_for_primary_email_post_regression_cleanup_migration.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddIndexesForPrimaryEmailPostRegressionCleanupMigration < Gitlab::Database::Migration[2.0] + USERS_INDEX = :index_users_on_id_for_primary_email_migration + EMAIL_INDEX = :index_emails_on_email_user_id + + disable_ddl_transaction! + + def up + unless index_exists_by_name?(:users, USERS_INDEX) + + disable_statement_timeout do + execute <<~SQL + CREATE INDEX CONCURRENTLY #{USERS_INDEX} + ON users (id) INCLUDE (email, confirmed_at) + WHERE confirmed_at IS NOT NULL + SQL + end + end + + add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX + end + + def down + remove_concurrent_index_by_name :users, USERS_INDEX + remove_concurrent_index_by_name :emails, EMAIL_INDEX + end +end diff --git a/db/post_migrate/20220504083836_cleanup_after_fixing_regression_with_new_users_emails.rb b/db/post_migrate/20220504083836_cleanup_after_fixing_regression_with_new_users_emails.rb new file mode 100644 index 00000000000..110e2578cd5 --- /dev/null +++ b/db/post_migrate/20220504083836_cleanup_after_fixing_regression_with_new_users_emails.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +class CleanupAfterFixingRegressionWithNewUsersEmails < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + BATCH_SIZE = 10_000 + + # Stubbed class to access the User table + class User < MigrationRecord + include ::EachBatch + + self.table_name = 'users' + self.inheritance_column = :_type_disabled + + scope :confirmed, -> { where.not(confirmed_at: nil) } + + has_many :emails + end + + # Stubbed class to access the Emails table + class Email < MigrationRecord + self.table_name = 'emails' + self.inheritance_column = :_type_disabled + + belongs_to :user + end + + # rubocop: disable Layout/LineLength + def up + # Select confirmed users that do not have their primary email in the emails table, + # and create the email record. + not_exists_condition = 'NOT EXISTS (SELECT 1 FROM emails WHERE emails.email = users.email AND emails.user_id = users.id)' + + User.confirmed.each_batch(of: BATCH_SIZE) do |user_batch| + user_batch.select(:id, :email, :confirmed_at).where(not_exists_condition).each do |user| + current_time = Time.now.utc + + begin + Email.create( + user_id: user.id, + email: user.email, + confirmed_at: user.confirmed_at, + created_at: current_time, + updated_at: current_time + ) + rescue StandardError => error + Gitlab::AppLogger.error("Could not add primary email #{user.email} to emails for user with ID #{user.id} due to #{error}") + end + end + end + end + # rubocop: enable Layout/LineLength + + def down + # Intentionally left blank + end +end diff --git a/db/post_migrate/20220504084136_drop_temporary_indexes_for_primary_email_post_regression_cleanup.rb b/db/post_migrate/20220504084136_drop_temporary_indexes_for_primary_email_post_regression_cleanup.rb new file mode 100644 index 00000000000..60c69426a8a --- /dev/null +++ b/db/post_migrate/20220504084136_drop_temporary_indexes_for_primary_email_post_regression_cleanup.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class DropTemporaryIndexesForPrimaryEmailPostRegressionCleanup < Gitlab::Database::Migration[2.0] + USERS_INDEX = :index_users_on_id_for_primary_email_migration + EMAIL_INDEX = :index_emails_on_email_user_id + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :users, USERS_INDEX + remove_concurrent_index_by_name :emails, EMAIL_INDEX + end + + def down + unless index_exists_by_name?(:users, USERS_INDEX) + + disable_statement_timeout do + execute <<~SQL + CREATE INDEX CONCURRENTLY #{USERS_INDEX} + ON users (id) INCLUDE (email, confirmed_at) + WHERE confirmed_at IS NOT NULL + SQL + end + end + + add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX + end +end diff --git a/db/post_migrate/20220505022001_add_index_to_deployments_on_created_at_cluster_id_and_project_id.rb b/db/post_migrate/20220505022001_add_index_to_deployments_on_created_at_cluster_id_and_project_id.rb new file mode 100644 index 00000000000..c78c3a86cf3 --- /dev/null +++ b/db/post_migrate/20220505022001_add_index_to_deployments_on_created_at_cluster_id_and_project_id.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class AddIndexToDeploymentsOnCreatedAtClusterIdAndProjectId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + # This temporary index was created to support the script that will be run as part o this + # Change Request: https://gitlab.com/gitlab-com/gl-infra/production/-/issues/6981 + # + # Issue to remove the temporary index: https://gitlab.com/gitlab-org/gitlab/-/issues/361389 + INDEX_NAME = 'tp_index_created_at_cluster_id_project_id_on_deployments' + + # The change request will only run for deployments newer than this date. This is what we'll + # be considering as "Active certificate based cluster Kubernetes Deployments". Namespaces with + # deployments older than this will have to be migrated to the agent and won't have their + # certificate based clusters life extended. + DEPLOYMENTS_START_DATE = '2022-04-03 00:00:00' + + def up + add_concurrent_index( + :deployments, + [:created_at, :cluster_id, :project_id], + name: INDEX_NAME, + where: "cluster_id is not null and created_at > '#{DEPLOYMENTS_START_DATE}'") + end + + def down + remove_concurrent_index_by_name(:deployments, INDEX_NAME) + end +end diff --git a/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb b/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb new file mode 100644 index 00000000000..90d70da1a28 --- /dev/null +++ b/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class FixAutomaticIterationsCadencesStartDate < Gitlab::Database::Migration[2.0] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + execute(<<~SQL) + UPDATE iterations_cadences + SET start_date=COALESCE( + ( + SELECT start_date + FROM sprints + WHERE iterations_cadences.id=sprints.iterations_cadence_id + ORDER BY sprints.start_date ASC + LIMIT 1 + ), + start_date + ) + WHERE iterations_cadences.automatic=true; + SQL + end + + def down + # no-op + # The migration updates the records for the feature used behind a non-default feature flag. + # The correct data can be computed with the records from 'sprints' table. + end +end diff --git a/db/post_migrate/20220505053504_remove_namespaces_id_parent_id_inverse_partial_index.rb b/db/post_migrate/20220505053504_remove_namespaces_id_parent_id_inverse_partial_index.rb new file mode 100644 index 00000000000..aca3ccaa03e --- /dev/null +++ b/db/post_migrate/20220505053504_remove_namespaces_id_parent_id_inverse_partial_index.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveNamespacesIdParentIdInversePartialIndex < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + NAME = 'index_namespaces_id_parent_id_is_not_null' + + def up + remove_concurrent_index :namespaces, :id, name: NAME + end + + def down + add_concurrent_index :namespaces, :id, where: 'parent_id IS NOT NULL', name: NAME + end +end diff --git a/db/post_migrate/20220505060011_remove_namespaces_id_parent_id_partial_index.rb b/db/post_migrate/20220505060011_remove_namespaces_id_parent_id_partial_index.rb new file mode 100644 index 00000000000..5125a97af7e --- /dev/null +++ b/db/post_migrate/20220505060011_remove_namespaces_id_parent_id_partial_index.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemoveNamespacesIdParentIdPartialIndex < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + NAME = 'index_namespaces_id_parent_id_is_null' + + def up + remove_concurrent_index :namespaces, :id, name: NAME + end + + def down + add_concurrent_index :namespaces, :id, where: 'parent_id IS NULL', name: NAME + end +end diff --git a/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb b/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb new file mode 100644 index 00000000000..5cffdb641d6 --- /dev/null +++ b/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class UpdateIndexOnAlertsToExcludeNullFingerprints < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_partial_am_alerts_on_project_id_and_fingerprint' + NEW_INDEX_NAME = 'index_unresolved_alerts_on_project_id_and_fingerprint' + + def up + add_concurrent_index :alert_management_alerts, + [:project_id, :fingerprint], + where: "fingerprint IS NOT NULL and status <> 2", + name: NEW_INDEX_NAME, + unique: true + + remove_concurrent_index_by_name :alert_management_alerts, OLD_INDEX_NAME + end + + def down + add_concurrent_index :alert_management_alerts, + [:project_id, :fingerprint], + where: "status <> 2", + name: OLD_INDEX_NAME, + unique: true + + remove_concurrent_index_by_name :alert_management_alerts, NEW_INDEX_NAME + end +end diff --git a/db/post_migrate/20220505193512_add_not_null_constraint_to_issues_work_item_type.rb b/db/post_migrate/20220505193512_add_not_null_constraint_to_issues_work_item_type.rb new file mode 100644 index 00000000000..3ea003383a6 --- /dev/null +++ b/db/post_migrate/20220505193512_add_not_null_constraint_to_issues_work_item_type.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddNotNullConstraintToIssuesWorkItemType < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_not_null_constraint :issues, :work_item_type_id, validate: false + end + + def down + remove_not_null_constraint :issues, :work_item_type_id + end +end diff --git a/db/post_migrate/20220506201639_remove_devops_adoption_security_scan_succeeded_column.rb b/db/post_migrate/20220506201639_remove_devops_adoption_security_scan_succeeded_column.rb new file mode 100644 index 00000000000..64722919aff --- /dev/null +++ b/db/post_migrate/20220506201639_remove_devops_adoption_security_scan_succeeded_column.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveDevopsAdoptionSecurityScanSucceededColumn < Gitlab::Database::Migration[2.0] + def up + remove_column :analytics_devops_adoption_snapshots, :security_scan_succeeded + end + + def down + add_column :analytics_devops_adoption_snapshots, :security_scan_succeeded, :boolean + end +end diff --git a/db/post_migrate/20220510003916_remove_tmp_empty_traversal_ids_root_namespace_index.rb b/db/post_migrate/20220510003916_remove_tmp_empty_traversal_ids_root_namespace_index.rb new file mode 100644 index 00000000000..424c6f164e7 --- /dev/null +++ b/db/post_migrate/20220510003916_remove_tmp_empty_traversal_ids_root_namespace_index.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class RemoveTmpEmptyTraversalIdsRootNamespaceIndex < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + ROOT_NS_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_root_namespaces' + + def up + remove_concurrent_index :namespaces, :id, name: ROOT_NS_INDEX_NAME + end + + def down + where_sql = "parent_id IS NULL AND traversal_ids = '{}'" + add_concurrent_index :namespaces, :id, where: where_sql, name: ROOT_NS_INDEX_NAME + end +end diff --git a/db/post_migrate/20220510004501_remove_tmp_empty_traversal_ids_child_namespace_index.rb b/db/post_migrate/20220510004501_remove_tmp_empty_traversal_ids_child_namespace_index.rb new file mode 100644 index 00000000000..804b20a38e9 --- /dev/null +++ b/db/post_migrate/20220510004501_remove_tmp_empty_traversal_ids_child_namespace_index.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class RemoveTmpEmptyTraversalIdsChildNamespaceIndex < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + CHILD_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_child_namespaces' + + def up + remove_concurrent_index :namespaces, :id, name: CHILD_INDEX_NAME + end + + def down + where_sql = "parent_id IS NOT NULL AND traversal_ids = '{}'" + add_concurrent_index :namespaces, :id, where: where_sql, name: CHILD_INDEX_NAME + end +end diff --git a/db/post_migrate/20220511152439_remove_not_null_constraint_from_work_item_type.rb b/db/post_migrate/20220511152439_remove_not_null_constraint_from_work_item_type.rb new file mode 100644 index 00000000000..f56763cdafb --- /dev/null +++ b/db/post_migrate/20220511152439_remove_not_null_constraint_from_work_item_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class RemoveNotNullConstraintFromWorkItemType < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85866 introduced a NOT NULL constraint on + # `issues` which caused QA failures (https://gitlab.com/gitlab-org/gitlab/-/issues/362023), and + # Helm database issues resulting in broken tests after restoring the database. + def up + remove_not_null_constraint :issues, :work_item_type_id, constraint_name: 'check_2addf801cd' + end + + def down + add_not_null_constraint :issues, :work_item_type_id, validate: false + end +end diff --git a/db/post_migrate/20220513043344_reschedule_expire_o_auth_tokens.rb b/db/post_migrate/20220513043344_reschedule_expire_o_auth_tokens.rb new file mode 100644 index 00000000000..0c8a2386583 --- /dev/null +++ b/db/post_migrate/20220513043344_reschedule_expire_o_auth_tokens.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class RescheduleExpireOAuthTokens < Gitlab::Database::Migration[2.0] + MIGRATION = 'ExpireOAuthTokens' + INTERVAL = 2.minutes.freeze + + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # remove the original migration from db/post_migrate/20220428133724_schedule_expire_o_auth_tokens.rb + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :oauth_access_tokens, :id, []) + .delete_all + + # reschedule + queue_batched_background_migration( + MIGRATION, + :oauth_access_tokens, + :id, + job_interval: INTERVAL + ) + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :oauth_access_tokens, :id, []) + .delete_all + end +end diff --git a/db/post_migrate/20220517144749_remove_vulnerability_approval_rules.rb b/db/post_migrate/20220517144749_remove_vulnerability_approval_rules.rb new file mode 100644 index 00000000000..83e3784c3aa --- /dev/null +++ b/db/post_migrate/20220517144749_remove_vulnerability_approval_rules.rb @@ -0,0 +1,29 @@ +# 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 RemoveVulnerabilityApprovalRules < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + class ApprovalProjectRule < MigrationRecord + self.table_name = 'approval_project_rules' + + enum report_type: { vulnerability: 1, license_scanning: 2, code_coverage: 3, scan_finding: 4 } + end + + def up + return unless Gitlab.ee? + + ApprovalProjectRule.reset_column_information + + ApprovalProjectRule.vulnerability.delete_all + end + + def down + # no-op + # Vulnerability-Check feature has been removed as part of 15.0 + end +end |