diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /db/migrate | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'db/migrate')
66 files changed, 1320 insertions, 4 deletions
diff --git a/db/migrate/20201224144948_migrate_coverage_report_worker.rb b/db/migrate/20201224144948_migrate_coverage_report_worker.rb index a13e5e859e0..8580a15c256 100644 --- a/db/migrate/20201224144948_migrate_coverage_report_worker.rb +++ b/db/migrate/20201224144948_migrate_coverage_report_worker.rb @@ -6,10 +6,10 @@ class MigrateCoverageReportWorker < ActiveRecord::Migration[6.0] DOWNTIME = false def up - sidekiq_queue_migrate 'ci_pipelines_create_artifact', to: 'ci_pipeline_artifacts_coverage_report' + sidekiq_queue_migrate 'ci_pipelines_create_artifact', to: 'ci_pipeline_artifacts_coverage_report' # rubocop:disable Migration/SidekiqQueueMigrate end def down - sidekiq_queue_migrate 'ci_pipeline_artifacts_coverage_report', to: 'ci_pipelines_create_artifact' + sidekiq_queue_migrate 'ci_pipeline_artifacts_coverage_report', to: 'ci_pipelines_create_artifact' # rubocop:disable Migration/SidekiqQueueMigrate end end diff --git a/db/migrate/20210317210338_add_valid_runner_registrars.rb b/db/migrate/20210317210338_add_valid_runner_registrars.rb new file mode 100644 index 00000000000..61663836d39 --- /dev/null +++ b/db/migrate/20210317210338_add_valid_runner_registrars.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddValidRunnerRegistrars < ActiveRecord::Migration[6.0] + def change + add_column :application_settings, :valid_runner_registrars, :string, array: true, default: %w(project group) + end +end diff --git a/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb b/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb index b9cefe456b8..51f234166de 100644 --- a/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb +++ b/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb @@ -6,10 +6,10 @@ class RenameSyncSecurityReportApprovalRulesSidekiqQueue < ActiveRecord::Migratio DOWNTIME = false def up - sidekiq_queue_migrate 'sync_security_reports_to_report_approval_rules', to: 'ci_sync_reports_to_report_approval_rules' + sidekiq_queue_migrate 'sync_security_reports_to_report_approval_rules', to: 'ci_sync_reports_to_report_approval_rules' # rubocop:disable Migration/SidekiqQueueMigrate end def down - sidekiq_queue_migrate 'ci_sync_reports_to_report_approval_rules', to: 'sync_security_reports_to_report_approval_rules' + sidekiq_queue_migrate 'ci_sync_reports_to_report_approval_rules', to: 'sync_security_reports_to_report_approval_rules' # rubocop:disable Migration/SidekiqQueueMigrate end end diff --git a/db/migrate/20210601132134_remove_partial_index_for_hashed_storage_migration.rb b/db/migrate/20210601132134_remove_partial_index_for_hashed_storage_migration.rb new file mode 100644 index 00000000000..d9793832d8c --- /dev/null +++ b/db/migrate/20210601132134_remove_partial_index_for_hashed_storage_migration.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RemovePartialIndexForHashedStorageMigration < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + remove_concurrent_index :projects, :id, name: 'index_on_id_partial_with_legacy_storage' + end + + def down + add_concurrent_index :projects, :id, where: 'storage_version < 2 or storage_version IS NULL', name: 'index_on_id_partial_with_legacy_storage' + end +end diff --git a/db/migrate/20210602155056_add_merge_request_diff_commit_users.rb b/db/migrate/20210602155056_add_merge_request_diff_commit_users.rb new file mode 100644 index 00000000000..f99790e0eca --- /dev/null +++ b/db/migrate/20210602155056_add_merge_request_diff_commit_users.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class AddMergeRequestDiffCommitUsers < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + create_table_with_constraints :merge_request_diff_commit_users, id: :bigint do |t| + t.text :name + t.text :email + + t.text_limit :name, 512 + t.text_limit :email, 512 + + t.index [:name, :email], unique: true + end + + # Names or Emails can be optional, so in some cases one of these may be + # null. But if both are NULL/empty, no row should exist in this table. + add_check_constraint( + :merge_request_diff_commit_users, + "(COALESCE(name, '') != '') OR (COALESCE(email, '') != '')", + :merge_request_diff_commit_users_name_or_email_existence + ) + end + + def down + drop_table :merge_request_diff_commit_users + end +end diff --git a/db/migrate/20210602155110_add_merge_request_diff_commit_user_columns.rb b/db/migrate/20210602155110_add_merge_request_diff_commit_user_columns.rb new file mode 100644 index 00000000000..8cc86c7e73c --- /dev/null +++ b/db/migrate/20210602155110_add_merge_request_diff_commit_user_columns.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddMergeRequestDiffCommitUserColumns < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + # NOTE: these columns are _not_ indexed, nor do they use foreign keys. + # + # This is deliberate, as creating these indexes on GitLab.com takes a _very_ + # long time. In addition, there's no real need for them either based on how + # this data is used. + # + # For more information, refer to the following: + # + # - https://gitlab.com/gitlab-com/gl-infra/production/-/issues/5038#note_614592881 + # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63669 + add_column(:merge_request_diff_commits, :commit_author_id, :bigint) + add_column(:merge_request_diff_commits, :committer_id, :bigint) + end + + def down + remove_column(:merge_request_diff_commits, :commit_author_id) + remove_column(:merge_request_diff_commits, :committer_id) + end +end diff --git a/db/migrate/20210604032738_create_dast_site_profiles_builds.rb b/db/migrate/20210604032738_create_dast_site_profiles_builds.rb new file mode 100644 index 00000000000..2e9eb2c7cb7 --- /dev/null +++ b/db/migrate/20210604032738_create_dast_site_profiles_builds.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateDastSiteProfilesBuilds < ActiveRecord::Migration[6.1] + def up + table_comment = { owner: 'group::dynamic analysis', description: 'Join table between DAST Site Profiles and CI Builds' } + + create_table :dast_site_profiles_builds, primary_key: [:dast_site_profile_id, :ci_build_id], comment: table_comment.to_json do |t| + t.bigint :dast_site_profile_id, null: false + t.bigint :ci_build_id, null: false + + t.index :ci_build_id, unique: true, name: :dast_site_profiles_builds_on_ci_build_id + end + end + + def down + drop_table :dast_site_profiles_builds + end +end diff --git a/db/migrate/20210604034158_add_ci_build_id_fk_to_dast_site_profiles_builds.rb b/db/migrate/20210604034158_add_ci_build_id_fk_to_dast_site_profiles_builds.rb new file mode 100644 index 00000000000..6908da69e08 --- /dev/null +++ b/db/migrate/20210604034158_add_ci_build_id_fk_to_dast_site_profiles_builds.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddCiBuildIdFkToDastSiteProfilesBuilds < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_site_profiles_builds, :ci_builds, column: :ci_build_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_site_profiles_builds, column: :ci_build_id + end + end +end diff --git a/db/migrate/20210604034354_add_dast_site_profile_id_fk_to_dast_site_profiles_builds.rb b/db/migrate/20210604034354_add_dast_site_profile_id_fk_to_dast_site_profiles_builds.rb new file mode 100644 index 00000000000..58fe3090a4f --- /dev/null +++ b/db/migrate/20210604034354_add_dast_site_profile_id_fk_to_dast_site_profiles_builds.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDastSiteProfileIdFkToDastSiteProfilesBuilds < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_site_profiles_builds, :dast_site_profiles, column: :dast_site_profile_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_site_profiles_builds, column: :dast_site_profile_id + end + end +end diff --git a/db/migrate/20210604051330_create_dast_scanner_profiles_builds.rb b/db/migrate/20210604051330_create_dast_scanner_profiles_builds.rb new file mode 100644 index 00000000000..f8a5f735f0d --- /dev/null +++ b/db/migrate/20210604051330_create_dast_scanner_profiles_builds.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateDastScannerProfilesBuilds < ActiveRecord::Migration[6.1] + def up + table_comment = { owner: 'group::dynamic analysis', description: 'Join table between DAST Scanner Profiles and CI Builds' } + + create_table :dast_scanner_profiles_builds, primary_key: [:dast_scanner_profile_id, :ci_build_id], comment: table_comment.to_json do |t| + t.bigint :dast_scanner_profile_id, null: false + t.bigint :ci_build_id, null: false + + t.index :ci_build_id, unique: true, name: :dast_scanner_profiles_builds_on_ci_build_id + end + end + + def down + drop_table :dast_scanner_profiles_builds + end +end diff --git a/db/migrate/20210604051742_add_ci_build_id_fk_to_dast_scanner_profiles_builds.rb b/db/migrate/20210604051742_add_ci_build_id_fk_to_dast_scanner_profiles_builds.rb new file mode 100644 index 00000000000..cc495c749c5 --- /dev/null +++ b/db/migrate/20210604051742_add_ci_build_id_fk_to_dast_scanner_profiles_builds.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddCiBuildIdFkToDastScannerProfilesBuilds < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_scanner_profiles_builds, :ci_builds, column: :ci_build_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_scanner_profiles_builds, column: :ci_build_id + end + end +end diff --git a/db/migrate/20210604051917_add_dast_scanner_profile_id_fk_to_dast_scanner_profiles_builds.rb b/db/migrate/20210604051917_add_dast_scanner_profile_id_fk_to_dast_scanner_profiles_builds.rb new file mode 100644 index 00000000000..0c14c798da4 --- /dev/null +++ b/db/migrate/20210604051917_add_dast_scanner_profile_id_fk_to_dast_scanner_profiles_builds.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDastScannerProfileIdFkToDastScannerProfilesBuilds < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_scanner_profiles_builds, :dast_scanner_profiles, column: :dast_scanner_profile_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_scanner_profiles_builds, column: :dast_scanner_profile_id + end + end +end diff --git a/db/migrate/20210610153556_delete_legacy_operations_feature_flags.rb b/db/migrate/20210610153556_delete_legacy_operations_feature_flags.rb new file mode 100644 index 00000000000..f0bcbe5e472 --- /dev/null +++ b/db/migrate/20210610153556_delete_legacy_operations_feature_flags.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class DeleteLegacyOperationsFeatureFlags < ActiveRecord::Migration[6.1] + LEGACY_FEATURE_FLAG_VERSION = 1 + + def up + execute("DELETE FROM operations_feature_flags WHERE version = #{LEGACY_FEATURE_FLAG_VERSION}") + end + + def down + # no-op + end +end diff --git a/db/migrate/20210611101034_add_devops_adoption_sast_dast.rb b/db/migrate/20210611101034_add_devops_adoption_sast_dast.rb new file mode 100644 index 00000000000..0a9eb64a5fc --- /dev/null +++ b/db/migrate/20210611101034_add_devops_adoption_sast_dast.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionSastDast < ActiveRecord::Migration[6.1] + def change + add_column :analytics_devops_adoption_snapshots, :sast_enabled_count, :integer + add_column :analytics_devops_adoption_snapshots, :dast_enabled_count, :integer + end +end diff --git a/db/migrate/20210614142311_add_running_container_scanning_max_size_to_plan_limits.rb b/db/migrate/20210614142311_add_running_container_scanning_max_size_to_plan_limits.rb new file mode 100644 index 00000000000..248fff6c42f --- /dev/null +++ b/db/migrate/20210614142311_add_running_container_scanning_max_size_to_plan_limits.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddRunningContainerScanningMaxSizeToPlanLimits < ActiveRecord::Migration[6.0] + def change + add_column :plan_limits, :ci_max_artifact_size_running_container_scanning, :integer, null: false, default: 0 + end +end diff --git a/db/migrate/20210615064342_add_issue_id_to_requirement.rb b/db/migrate/20210615064342_add_issue_id_to_requirement.rb new file mode 100644 index 00000000000..a6d85bd9d6e --- /dev/null +++ b/db/migrate/20210615064342_add_issue_id_to_requirement.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIssueIdToRequirement < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :requirements, :issue_id, :bigint, null: true + end + end + + def down + with_lock_retries do + remove_column :requirements, :issue_id + end + end +end diff --git a/db/migrate/20210616110748_add_issue_index_to_requirement.rb b/db/migrate/20210616110748_add_issue_index_to_requirement.rb new file mode 100644 index 00000000000..747ee3875dc --- /dev/null +++ b/db/migrate/20210616110748_add_issue_index_to_requirement.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIssueIndexToRequirement < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_requirements_on_issue_id' + + def up + add_concurrent_index :requirements, :issue_id, name: INDEX_NAME, unique: true + end + + def down + remove_concurrent_index_by_name :requirements, INDEX_NAME + end +end diff --git a/db/migrate/20210616111311_add_issue_requirement_foreign_key.rb b/db/migrate/20210616111311_add_issue_requirement_foreign_key.rb new file mode 100644 index 00000000000..ed851da9f31 --- /dev/null +++ b/db/migrate/20210616111311_add_issue_requirement_foreign_key.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIssueRequirementForeignKey < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + TARGET_TABLE = :requirements + + def up + add_concurrent_foreign_key TARGET_TABLE, :issues, column: :issue_id + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(TARGET_TABLE, column: :issue_id) + end + end +end diff --git a/db/migrate/20210616134905_add_timestamp_to_schema_migration.rb b/db/migrate/20210616134905_add_timestamp_to_schema_migration.rb new file mode 100644 index 00000000000..7086b20c48f --- /dev/null +++ b/db/migrate/20210616134905_add_timestamp_to_schema_migration.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTimestampToSchemaMigration < ActiveRecord::Migration[6.1] + def up + # Add a nullable column with default null first + add_column :schema_migrations, :finished_at, :timestamptz + + # Change default to NOW() for new records + change_column_default :schema_migrations, :finished_at, -> { 'NOW()' } + end + + def down + remove_column :schema_migrations, :finished_at + end +end diff --git a/db/migrate/20210616154808_remove_ci_build_protected_index.rb b/db/migrate/20210616154808_remove_ci_build_protected_index.rb new file mode 100644 index 00000000000..25a8d159c1e --- /dev/null +++ b/db/migrate/20210616154808_remove_ci_build_protected_index.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveCiBuildProtectedIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_NAME = 'index_ci_builds_on_protected' + + disable_ddl_transaction! + + def up + remove_concurrent_index :ci_builds, :protected, name: INDEX_NAME + end + + def down + add_concurrent_index :ci_builds, :protected, name: INDEX_NAME + end +end diff --git a/db/migrate/20210616185947_add_mailgun_settings_to_application_setting.rb b/db/migrate/20210616185947_add_mailgun_settings_to_application_setting.rb new file mode 100644 index 00000000000..8447ff79d12 --- /dev/null +++ b/db/migrate/20210616185947_add_mailgun_settings_to_application_setting.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddMailgunSettingsToApplicationSetting < ActiveRecord::Migration[6.1] + def change + add_column :application_settings, :encrypted_mailgun_signing_key, :binary + add_column :application_settings, :encrypted_mailgun_signing_key_iv, :binary + + add_column :application_settings, :mailgun_events_enabled, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb b/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb new file mode 100644 index 00000000000..32249c9ed56 --- /dev/null +++ b/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class CreateIncidentManagementPendingAlertEscalations < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + execute(<<~SQL) + + CREATE TABLE incident_management_pending_alert_escalations ( + id bigserial NOT NULL, + rule_id bigint, + alert_id bigint NOT NULL, + schedule_id bigint NOT NULL, + process_at timestamp with time zone NOT NULL, + created_at timestamp with time zone NOT NULL, + updated_at timestamp with time zone NOT NULL, + status smallint NOT NULL, + PRIMARY KEY (id, process_at) + ) PARTITION BY RANGE (process_at); + + CREATE INDEX index_incident_management_pending_alert_escalations_on_alert_id + ON incident_management_pending_alert_escalations USING btree (alert_id); + + CREATE INDEX index_incident_management_pending_alert_escalations_on_rule_id + ON incident_management_pending_alert_escalations USING btree (rule_id); + + CREATE INDEX index_incident_management_pending_alert_escalations_on_schedule_id + ON incident_management_pending_alert_escalations USING btree (schedule_id); + + ALTER TABLE incident_management_pending_alert_escalations ADD CONSTRAINT fk_rails_fcbfd9338b + FOREIGN KEY (schedule_id) REFERENCES incident_management_oncall_schedules(id) ON DELETE CASCADE; + + ALTER TABLE incident_management_pending_alert_escalations ADD CONSTRAINT fk_rails_057c1e3d87 + FOREIGN KEY (rule_id) REFERENCES incident_management_escalation_rules(id) ON DELETE SET NULL; + + ALTER TABLE incident_management_pending_alert_escalations ADD CONSTRAINT fk_rails_8d8de95da9 + FOREIGN KEY (alert_id) REFERENCES alert_management_alerts(id) ON DELETE CASCADE; + SQL + end + end + + def down + with_lock_retries do + drop_table :incident_management_pending_alert_escalations + end + end +end diff --git a/db/migrate/20210617161348_cascade_delete_freeze_periods.rb b/db/migrate/20210617161348_cascade_delete_freeze_periods.rb new file mode 100644 index 00000000000..90623b27920 --- /dev/null +++ b/db/migrate/20210617161348_cascade_delete_freeze_periods.rb @@ -0,0 +1,23 @@ +# 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 CascadeDeleteFreezePeriods < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + OLD_PROJECT_FK = 'fk_rails_2e02bbd1a6' + NEW_PROJECT_FK = 'fk_2e02bbd1a6' + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :ci_freeze_periods, :projects, column: :project_id, on_delete: :cascade, name: NEW_PROJECT_FK + remove_foreign_key_if_exists :ci_freeze_periods, :projects, column: :project_id, name: OLD_PROJECT_FK + end + + def down + add_concurrent_foreign_key :ci_freeze_periods, :projects, column: :project_id, on_delete: nil, name: OLD_PROJECT_FK + remove_foreign_key_if_exists :ci_freeze_periods, :projects, column: :project_id, name: NEW_PROJECT_FK + end +end diff --git a/db/migrate/20210617180131_migrate_usage_ping_sidekiq_queue.rb b/db/migrate/20210617180131_migrate_usage_ping_sidekiq_queue.rb new file mode 100644 index 00000000000..9eebc6feb14 --- /dev/null +++ b/db/migrate/20210617180131_migrate_usage_ping_sidekiq_queue.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class MigrateUsagePingSidekiqQueue < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + # rubocop:disable Migration/SidekiqQueueMigrate + def up + sidekiq_queue_migrate 'cronjob:gitlab_usage_ping', to: 'cronjob:gitlab_service_ping' + end + + def down + sidekiq_queue_migrate 'cronjob:gitlab_service_ping', to: 'cronjob:gitlab_usage_ping' + end + # rubocop:enable Migration/SidekiqQueueMigrate +end diff --git a/db/migrate/20210621043337_rename_services_to_integrations.rb b/db/migrate/20210621043337_rename_services_to_integrations.rb new file mode 100644 index 00000000000..17f4b6a2d4d --- /dev/null +++ b/db/migrate/20210621043337_rename_services_to_integrations.rb @@ -0,0 +1,150 @@ +# frozen_string_literal: true + +class RenameServicesToIntegrations < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + include Gitlab::Database::SchemaHelpers + + # Function and trigger names match those migrated in: + # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49916 + # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51852 + + WIKI_FUNCTION_NAME = 'set_has_external_wiki' + TRACKER_FUNCTION_NAME = 'set_has_external_issue_tracker' + + WIKI_TRIGGER_ON_INSERT_NAME = 'trigger_has_external_wiki_on_insert' + WIKI_TRIGGER_ON_UPDATE_NAME = 'trigger_has_external_wiki_on_update' + WIKI_TRIGGER_ON_DELETE_NAME = 'trigger_has_external_wiki_on_delete' + + TRACKER_TRIGGER_ON_INSERT_NAME = 'trigger_has_external_issue_tracker_on_insert' + TRACKER_TRIGGER_ON_UPDATE_NAME = 'trigger_has_external_issue_tracker_on_update' + TRACKER_TRIGGER_ON_DELETE_NAME = 'trigger_has_external_issue_tracker_on_delete' + + ALL_TRIGGERS = [ + WIKI_TRIGGER_ON_INSERT_NAME, + WIKI_TRIGGER_ON_UPDATE_NAME, + WIKI_TRIGGER_ON_DELETE_NAME, + TRACKER_TRIGGER_ON_INSERT_NAME, + TRACKER_TRIGGER_ON_UPDATE_NAME, + TRACKER_TRIGGER_ON_DELETE_NAME + ].freeze + + def up + execute('LOCK services IN ACCESS EXCLUSIVE MODE') + + drop_all_triggers(:services) + + rename_table_safely(:services, :integrations) + + recreate_all_triggers(:integrations) + end + + def down + execute('LOCK integrations IN ACCESS EXCLUSIVE MODE') + + drop_all_triggers(:integrations) + + undo_rename_table_safely(:services, :integrations) + + recreate_all_triggers(:services) + end + + private + + def drop_all_triggers(table_name) + ALL_TRIGGERS.each do |trigger_name| + drop_trigger(table_name, trigger_name) + end + end + + def recreate_all_triggers(table_name) + wiki_create_insert_trigger(table_name) + wiki_create_update_trigger(table_name) + wiki_create_delete_trigger(table_name) + + tracker_replace_trigger_function(table_name) + + tracker_create_insert_trigger(table_name) + tracker_create_update_trigger(table_name) + tracker_create_delete_trigger(table_name) + end + + def wiki_create_insert_trigger(table_name) + execute(<<~SQL) + CREATE TRIGGER #{WIKI_TRIGGER_ON_INSERT_NAME} + AFTER INSERT ON #{table_name} + FOR EACH ROW + WHEN (NEW.active = TRUE AND NEW.type = 'ExternalWikiService' AND NEW.project_id IS NOT NULL) + EXECUTE FUNCTION #{WIKI_FUNCTION_NAME}(); + SQL + end + + def wiki_create_update_trigger(table_name) + execute(<<~SQL) + CREATE TRIGGER #{WIKI_TRIGGER_ON_UPDATE_NAME} + AFTER UPDATE ON #{table_name} + FOR EACH ROW + WHEN (NEW.type = 'ExternalWikiService' AND OLD.active != NEW.active AND NEW.project_id IS NOT NULL) + EXECUTE FUNCTION #{WIKI_FUNCTION_NAME}(); + SQL + end + + def wiki_create_delete_trigger(table_name) + execute(<<~SQL) + CREATE TRIGGER #{WIKI_TRIGGER_ON_DELETE_NAME} + AFTER DELETE ON #{table_name} + FOR EACH ROW + WHEN (OLD.type = 'ExternalWikiService' AND OLD.project_id IS NOT NULL) + EXECUTE FUNCTION #{WIKI_FUNCTION_NAME}(); + SQL + end + + # Using `replace: true` to rewrite the existing function + def tracker_replace_trigger_function(table_name) + create_trigger_function(TRACKER_FUNCTION_NAME, replace: true) do + <<~SQL + UPDATE projects SET has_external_issue_tracker = ( + EXISTS + ( + SELECT 1 + FROM #{table_name} + WHERE project_id = COALESCE(NEW.project_id, OLD.project_id) + AND active = TRUE + AND category = 'issue_tracker' + ) + ) + WHERE projects.id = COALESCE(NEW.project_id, OLD.project_id); + RETURN NULL; + SQL + end + end + + def tracker_create_insert_trigger(table_name) + execute(<<~SQL) + CREATE TRIGGER #{TRACKER_TRIGGER_ON_INSERT_NAME} + AFTER INSERT ON #{table_name} + FOR EACH ROW + WHEN (NEW.category = 'issue_tracker' AND NEW.active = TRUE AND NEW.project_id IS NOT NULL) + EXECUTE FUNCTION #{TRACKER_FUNCTION_NAME}(); + SQL + end + + def tracker_create_update_trigger(table_name) + execute(<<~SQL) + CREATE TRIGGER #{TRACKER_TRIGGER_ON_UPDATE_NAME} + AFTER UPDATE ON #{table_name} + FOR EACH ROW + WHEN (NEW.category = 'issue_tracker' AND OLD.active != NEW.active AND NEW.project_id IS NOT NULL) + EXECUTE FUNCTION #{TRACKER_FUNCTION_NAME}(); + SQL + end + + def tracker_create_delete_trigger(table_name) + execute(<<~SQL) + CREATE TRIGGER #{TRACKER_TRIGGER_ON_DELETE_NAME} + AFTER DELETE ON #{table_name} + FOR EACH ROW + WHEN (OLD.category = 'issue_tracker' AND OLD.active = TRUE AND OLD.project_id IS NOT NULL) + EXECUTE FUNCTION #{TRACKER_FUNCTION_NAME}(); + SQL + end +end diff --git a/db/migrate/20210621044000_rename_services_indexes_to_integrations.rb b/db/migrate/20210621044000_rename_services_indexes_to_integrations.rb new file mode 100644 index 00000000000..9dba663f6a7 --- /dev/null +++ b/db/migrate/20210621044000_rename_services_indexes_to_integrations.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RenameServicesIndexesToIntegrations < ActiveRecord::Migration[6.1] + INDEXES = %w( + project_and_type_where_inherit_null + project_id_and_type_unique + template + type + type_and_instance_partial + type_and_template_partial + type_id_when_active_and_project_id_not_null + unique_group_id_and_type + ).freeze + + def up + INDEXES.each do |index| + execute(<<~SQL) + ALTER INDEX IF EXISTS "index_services_on_#{index}" RENAME TO "index_integrations_on_#{index}" + SQL + end + end + + def down + INDEXES.each do |index| + execute(<<~SQL) + ALTER INDEX IF EXISTS "index_integrations_on_#{index}" RENAME TO "index_services_on_#{index}" + SQL + end + end +end diff --git a/db/migrate/20210621084632_add_summary_to_timelogs.rb b/db/migrate/20210621084632_add_summary_to_timelogs.rb new file mode 100644 index 00000000000..45fd7f1e0bc --- /dev/null +++ b/db/migrate/20210621084632_add_summary_to_timelogs.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddSummaryToTimelogs < ActiveRecord::Migration[6.1] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210621090030_add_text_limit_to_timelogs_summary + def change + add_column :timelogs, :summary, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210621090030_add_text_limit_to_timelogs_summary.rb b/db/migrate/20210621090030_add_text_limit_to_timelogs_summary.rb new file mode 100644 index 00000000000..ac872afd3fa --- /dev/null +++ b/db/migrate/20210621090030_add_text_limit_to_timelogs_summary.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToTimelogsSummary < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :timelogs, :summary, 255 + end + + def down + remove_text_limit :timelogs, :summary + end +end diff --git a/db/migrate/20210621091830_add_devops_adoption_snapshot_dependency_scanning.rb b/db/migrate/20210621091830_add_devops_adoption_snapshot_dependency_scanning.rb new file mode 100644 index 00000000000..ae19a46b66f --- /dev/null +++ b/db/migrate/20210621091830_add_devops_adoption_snapshot_dependency_scanning.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionSnapshotDependencyScanning < ActiveRecord::Migration[6.1] + def change + add_column :analytics_devops_adoption_snapshots, :dependency_scanning_enabled_count, :integer + end +end diff --git a/db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb b/db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb new file mode 100644 index 00000000000..03991cea41c --- /dev/null +++ b/db/migrate/20210622135221_add_foreign_key_for_environment_id_to_environments.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddForeignKeyForEnvironmentIdToEnvironments < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + # `validate: false` option is passed here, because validating the existing rows fails by the orphaned deployments, + # which will be cleaned up in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64588. + # The validation runs for only new records or updates, so that we can at least + # stop creating orphaned rows. + add_concurrent_foreign_key :deployments, :environments, column: :environment_id, on_delete: :cascade, validate: false + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :deployments, :environments + end + end +end diff --git a/db/migrate/20210623074226_add_usage_ping_features_enabled_to_application_settings.rb b/db/migrate/20210623074226_add_usage_ping_features_enabled_to_application_settings.rb new file mode 100644 index 00000000000..7a70f695039 --- /dev/null +++ b/db/migrate/20210623074226_add_usage_ping_features_enabled_to_application_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddUsagePingFeaturesEnabledToApplicationSettings < ActiveRecord::Migration[6.1] + def up + add_column :application_settings, :usage_ping_features_enabled, :boolean, default: false, null: false + end + + def down + remove_column :application_settings, :usage_ping_features_enabled + end +end diff --git a/db/migrate/20210623123722_add_present_on_default_branch_to_vulnerabilities.rb b/db/migrate/20210623123722_add_present_on_default_branch_to_vulnerabilities.rb new file mode 100644 index 00000000000..d528c4c6967 --- /dev/null +++ b/db/migrate/20210623123722_add_present_on_default_branch_to_vulnerabilities.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddPresentOnDefaultBranchToVulnerabilities < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :vulnerabilities, :present_on_default_branch, :boolean, default: true, null: false + end + end + + def down + with_lock_retries do + remove_column :vulnerabilities, :present_on_default_branch + end + end +end diff --git a/db/migrate/20210623133635_create_error_tracking_errors.rb b/db/migrate/20210623133635_create_error_tracking_errors.rb new file mode 100644 index 00000000000..e26fbe8df86 --- /dev/null +++ b/db/migrate/20210623133635_create_error_tracking_errors.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class CreateErrorTrackingErrors < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + create_table_with_constraints :error_tracking_errors do |t| + t.references :project, index: true, null: false, foreign_key: { on_delete: :cascade } + t.text :name, null: false + t.text :description, null: false + t.text :actor, null: false + t.datetime_with_timezone :first_seen_at, null: false, default: -> { 'NOW()' } + t.datetime_with_timezone :last_seen_at, null: false, default: -> { 'NOW()' } + t.text :platform + + t.text_limit :name, 255 + t.text_limit :description, 1024 + t.text_limit :actor, 255 + t.text_limit :platform, 255 + + t.timestamps_with_timezone + end + end + + def down + drop_table :error_tracking_errors + end +end diff --git a/db/migrate/20210623163342_add_index_to_compliance_management_frameworks_pipeline_configuration.rb b/db/migrate/20210623163342_add_index_to_compliance_management_frameworks_pipeline_configuration.rb new file mode 100644 index 00000000000..81903230f43 --- /dev/null +++ b/db/migrate/20210623163342_add_index_to_compliance_management_frameworks_pipeline_configuration.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToComplianceManagementFrameworksPipelineConfiguration < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_compliance_frameworks_id_where_frameworks_not_null' + + def up + add_concurrent_index :compliance_management_frameworks, :id, name: INDEX_NAME, where: 'pipeline_configuration_full_path IS NOT NULL' + end + + def down + remove_concurrent_index_by_name :compliance_management_frameworks, INDEX_NAME + end +end diff --git a/db/migrate/20210624112821_add_devops_adoption_coverage_fuzzing.rb b/db/migrate/20210624112821_add_devops_adoption_coverage_fuzzing.rb new file mode 100644 index 00000000000..6ca040dbfbc --- /dev/null +++ b/db/migrate/20210624112821_add_devops_adoption_coverage_fuzzing.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionCoverageFuzzing < ActiveRecord::Migration[6.1] + def change + add_column :analytics_devops_adoption_snapshots, :coverage_fuzzing_enabled_count, :integer + end +end diff --git a/db/migrate/20210624180613_add_last_synced_at_to_licenses.rb b/db/migrate/20210624180613_add_last_synced_at_to_licenses.rb new file mode 100644 index 00000000000..085fccdc20f --- /dev/null +++ b/db/migrate/20210624180613_add_last_synced_at_to_licenses.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddLastSyncedAtToLicenses < ActiveRecord::Migration[6.1] + def change + add_column :licenses, :last_synced_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20210625094554_create_error_tracking_error_events.rb b/db/migrate/20210625094554_create_error_tracking_error_events.rb new file mode 100644 index 00000000000..c1ed6d6ce6e --- /dev/null +++ b/db/migrate/20210625094554_create_error_tracking_error_events.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class CreateErrorTrackingErrorEvents < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + create_table_with_constraints :error_tracking_error_events do |t| + t.references :error, + index: true, + null: false, + foreign_key: { on_delete: :cascade, to_table: :error_tracking_errors } + + t.text :description, null: false + t.text :environment + t.text :level + t.datetime_with_timezone :occurred_at, null: false + t.jsonb :payload, null: false, default: {} + + t.text_limit :description, 255 + t.text_limit :environment, 255 + t.text_limit :level, 255 + + t.timestamps_with_timezone + end + end + + def down + drop_table :error_tracking_error_events + end +end diff --git a/db/migrate/20210627204936_add_plan_limits_max_size_cluster_image_scanning_column.rb b/db/migrate/20210627204936_add_plan_limits_max_size_cluster_image_scanning_column.rb new file mode 100644 index 00000000000..322e6991d0b --- /dev/null +++ b/db/migrate/20210627204936_add_plan_limits_max_size_cluster_image_scanning_column.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPlanLimitsMaxSizeClusterImageScanningColumn < ActiveRecord::Migration[6.0] + def change + add_column :plan_limits, :ci_max_artifact_size_cluster_image_scanning, :integer, null: false, default: 0 + end +end diff --git a/db/migrate/20210629153519_add_index_to_bulk_import_entities_on_bulk_import_id_and_status.rb b/db/migrate/20210629153519_add_index_to_bulk_import_entities_on_bulk_import_id_and_status.rb new file mode 100644 index 00000000000..c84a42cbea4 --- /dev/null +++ b/db/migrate/20210629153519_add_index_to_bulk_import_entities_on_bulk_import_id_and_status.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddIndexToBulkImportEntitiesOnBulkImportIdAndStatus < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + NEW_INDEX_NAME = 'index_bulk_import_entities_on_bulk_import_id_and_status' + OLD_INDEX_NAME = 'index_bulk_import_entities_on_bulk_import_id' + + def up + add_concurrent_index :bulk_import_entities, [:bulk_import_id, :status], name: NEW_INDEX_NAME + remove_concurrent_index_by_name :bulk_import_entities, name: OLD_INDEX_NAME + end + + def down + add_concurrent_index :bulk_import_entities, :bulk_import_id, name: OLD_INDEX_NAME + remove_concurrent_index_by_name :bulk_import_entities, name: NEW_INDEX_NAME + end +end diff --git a/db/migrate/20210630144339_add_invite_email_success_to_members.rb b/db/migrate/20210630144339_add_invite_email_success_to_members.rb new file mode 100644 index 00000000000..6c341ecb3f3 --- /dev/null +++ b/db/migrate/20210630144339_add_invite_email_success_to_members.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddInviteEmailSuccessToMembers < ActiveRecord::Migration[6.1] + def up + # no-op + end + + def down + # no-op + end +end diff --git a/db/migrate/20210701111627_add_upvotes_count_to_issues.rb b/db/migrate/20210701111627_add_upvotes_count_to_issues.rb new file mode 100644 index 00000000000..beefb186f37 --- /dev/null +++ b/db/migrate/20210701111627_add_upvotes_count_to_issues.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUpvotesCountToIssues < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :issues, :upvotes_count, :integer, default: 0, null: false + end + end + + def down + remove_column :issues, :upvotes_count + end +end diff --git a/db/migrate/20210702124842_add_ci_job_trace_size_to_plan_limits.rb b/db/migrate/20210702124842_add_ci_job_trace_size_to_plan_limits.rb new file mode 100644 index 00000000000..561c98c449c --- /dev/null +++ b/db/migrate/20210702124842_add_ci_job_trace_size_to_plan_limits.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddCiJobTraceSizeToPlanLimits < ActiveRecord::Migration[6.1] + def change + add_column(:plan_limits, :ci_jobs_trace_size_limit, :integer, default: 100, null: false) + end +end diff --git a/db/migrate/20210705124128_add_project_settings_previous_default_branch.rb b/db/migrate/20210705124128_add_project_settings_previous_default_branch.rb new file mode 100644 index 00000000000..e54d762fa75 --- /dev/null +++ b/db/migrate/20210705124128_add_project_settings_previous_default_branch.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddProjectSettingsPreviousDefaultBranch < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210707173645_add_project_settings_previous_default_branch_text_limit + def up + with_lock_retries do + add_column :project_settings, :previous_default_branch, :text + end + end + # rubocop:enable Migration/AddLimitToTextColumns + + def down + with_lock_retries do + remove_column :project_settings, :previous_default_branch + end + end +end diff --git a/db/migrate/20210705130919_create_container_repos_on_exp_cleanup_status_project_id_start_date_index.rb b/db/migrate/20210705130919_create_container_repos_on_exp_cleanup_status_project_id_start_date_index.rb new file mode 100644 index 00000000000..a6983c2d599 --- /dev/null +++ b/db/migrate/20210705130919_create_container_repos_on_exp_cleanup_status_project_id_start_date_index.rb @@ -0,0 +1,24 @@ +# 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 CreateContainerReposOnExpCleanupStatusProjectIdStartDateIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + OLD_INDEX_NAME = 'idx_container_repositories_on_exp_cleanup_status_and_start_date' + NEW_INDEX_NAME = 'idx_container_repos_on_exp_cleanup_status_project_id_start_date' + + disable_ddl_transaction! + + def up + add_concurrent_index(:container_repositories, [:expiration_policy_cleanup_status, :project_id, :expiration_policy_started_at], name: NEW_INDEX_NAME) + remove_concurrent_index(:container_repositories, [:expiration_policy_cleanup_status, :expiration_policy_started_at], name: OLD_INDEX_NAME) + end + + def down + add_concurrent_index(:container_repositories, [:expiration_policy_cleanup_status, :expiration_policy_started_at], name: OLD_INDEX_NAME) + remove_concurrent_index(:container_repositories, [:expiration_policy_cleanup_status, :project_id, :expiration_policy_started_at], name: NEW_INDEX_NAME) + end +end diff --git a/db/migrate/20210705132928_add_new_user_signups_cap_to_namespace_settings.rb b/db/migrate/20210705132928_add_new_user_signups_cap_to_namespace_settings.rb new file mode 100644 index 00000000000..7f736bf2b87 --- /dev/null +++ b/db/migrate/20210705132928_add_new_user_signups_cap_to_namespace_settings.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddNewUserSignupsCapToNamespaceSettings < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :namespace_settings, :new_user_signups_cap, :integer, null: true + end + end + + def down + with_lock_retries do + remove_column :namespace_settings, :new_user_signups_cap + end + end +end diff --git a/db/migrate/20210705144657_add_instance_runners_enabled_to_ci_pending_build.rb b/db/migrate/20210705144657_add_instance_runners_enabled_to_ci_pending_build.rb new file mode 100644 index 00000000000..b362fd930a3 --- /dev/null +++ b/db/migrate/20210705144657_add_instance_runners_enabled_to_ci_pending_build.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddInstanceRunnersEnabledToCiPendingBuild < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + with_lock_retries do + add_column :ci_pending_builds, :instance_runners_enabled, :boolean, null: false, default: false + end + end + + def down + with_lock_retries do + remove_column :ci_pending_builds, :instance_runners_enabled + end + end +end diff --git a/db/migrate/20210706084713_add_devops_adoption_snapshots_index.rb b/db/migrate/20210706084713_add_devops_adoption_snapshots_index.rb new file mode 100644 index 00000000000..26727b7ad7d --- /dev/null +++ b/db/migrate/20210706084713_add_devops_adoption_snapshots_index.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionSnapshotsIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'idx_analytics_devops_adoption_snapshots_finalized' + + def up + add_concurrent_index :analytics_devops_adoption_snapshots, [:namespace_id, :end_time], where: "recorded_at >= end_time", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :analytics_devops_adoption_snapshots, INDEX_NAME + end +end diff --git a/db/migrate/20210706152139_add_index_type_to_postgres_indexes_view.rb b/db/migrate/20210706152139_add_index_type_to_postgres_indexes_view.rb new file mode 100644 index 00000000000..a2a3d74cd49 --- /dev/null +++ b/db/migrate/20210706152139_add_index_type_to_postgres_indexes_view.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +class AddIndexTypeToPostgresIndexesView < ActiveRecord::Migration[6.1] + def up + execute(<<~SQL) + DROP VIEW IF EXISTS postgres_indexes; + + CREATE VIEW postgres_indexes AS + SELECT (pg_namespace.nspname::text || '.'::text) || i.relname::text AS identifier, + pg_index.indexrelid, + pg_namespace.nspname AS schema, + i.relname AS name, + pg_indexes.tablename, + a.amname AS type, + pg_index.indisunique AS "unique", + pg_index.indisvalid AS valid_index, + i.relispartition AS partitioned, + pg_index.indisexclusion AS exclusion, + pg_index.indexprs IS NOT NULL AS expression, + pg_index.indpred IS NOT NULL AS partial, + pg_indexes.indexdef AS definition, + pg_relation_size(i.oid::regclass) AS ondisk_size_bytes + FROM pg_index + JOIN pg_class i ON i.oid = pg_index.indexrelid + JOIN pg_namespace ON i.relnamespace = pg_namespace.oid + JOIN pg_indexes ON i.relname = pg_indexes.indexname + JOIN pg_am a ON i.relam = a.oid + WHERE pg_namespace.nspname <> 'pg_catalog'::name AND (pg_namespace.nspname = ANY (ARRAY["current_schema"(), 'gitlab_partitions_dynamic'::name, 'gitlab_partitions_static'::name])); + SQL + end + + def down + execute(<<~SQL) + DROP VIEW IF EXISTS postgres_indexes; + + CREATE VIEW postgres_indexes AS + SELECT (((pg_namespace.nspname)::text || '.'::text) || (pg_class.relname)::text) AS identifier, + pg_index.indexrelid, + pg_namespace.nspname AS schema, + pg_class.relname AS name, + pg_indexes.tablename, + pg_index.indisunique AS "unique", + pg_index.indisvalid AS valid_index, + pg_class.relispartition AS partitioned, + pg_index.indisexclusion AS exclusion, + (pg_index.indexprs IS NOT NULL) AS expression, + (pg_index.indpred IS NOT NULL) AS partial, + pg_indexes.indexdef AS definition, + pg_relation_size((pg_class.oid)::regclass) AS ondisk_size_bytes + FROM (((pg_index + JOIN pg_class ON ((pg_class.oid = pg_index.indexrelid))) + JOIN pg_namespace ON ((pg_class.relnamespace = pg_namespace.oid))) + JOIN pg_indexes ON ((pg_class.relname = pg_indexes.indexname))) + WHERE ((pg_namespace.nspname <> 'pg_catalog'::name) AND (pg_namespace.nspname = ANY (ARRAY["current_schema"(), 'gitlab_partitions_dynamic'::name, 'gitlab_partitions_static'::name]))); + SQL + end +end diff --git a/db/migrate/20210706213537_add_premium_and_ultimate_plan_limits.rb b/db/migrate/20210706213537_add_premium_and_ultimate_plan_limits.rb new file mode 100644 index 00000000000..f78e37d645a --- /dev/null +++ b/db/migrate/20210706213537_add_premium_and_ultimate_plan_limits.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class AddPremiumAndUltimatePlanLimits < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + class Plan < ActiveRecord::Base + self.inheritance_column = :_type_disabled + + has_one :limits, class_name: 'PlanLimits' + end + + class PlanLimits < ActiveRecord::Base + self.inheritance_column = :_type_disabled + + belongs_to :plan + end + + def copy_plan_limits(from_plan_name:, to_plan_name:) + source_plan = Plan.find_by(name: from_plan_name) + target_plan = Plan.find_by(name: to_plan_name) + return unless source_plan && target_plan + return unless source_plan.limits.present? + return if target_plan.limits.present? + + limits = source_plan.limits.dup + limits.plan = target_plan + limits.save! + end + + def up + return unless Gitlab.com? + + copy_plan_limits(from_plan_name: 'gold', to_plan_name: 'ultimate') + copy_plan_limits(from_plan_name: 'silver', to_plan_name: 'premium') + end + + def down + # no-op + end +end diff --git a/db/migrate/20210707095545_add_status_to_merge_request_cleanup_schedules.rb b/db/migrate/20210707095545_add_status_to_merge_request_cleanup_schedules.rb new file mode 100644 index 00000000000..597e274cda2 --- /dev/null +++ b/db/migrate/20210707095545_add_status_to_merge_request_cleanup_schedules.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddStatusToMergeRequestCleanupSchedules < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_merge_request_cleanup_schedules_on_status' + + disable_ddl_transaction! + + def up + unless column_exists?(:merge_request_cleanup_schedules, :status) + add_column(:merge_request_cleanup_schedules, :status, :integer, limit: 2, default: 0, null: false) + end + + add_concurrent_index(:merge_request_cleanup_schedules, :status, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:merge_request_cleanup_schedules, INDEX_NAME) + + if column_exists?(:merge_request_cleanup_schedules, :status) + remove_column(:merge_request_cleanup_schedules, :status) + end + end +end diff --git a/db/migrate/20210707151536_create_vulnerability_finding_evidence_sources.rb b/db/migrate/20210707151536_create_vulnerability_finding_evidence_sources.rb new file mode 100644 index 00000000000..90bc6fb82bd --- /dev/null +++ b/db/migrate/20210707151536_create_vulnerability_finding_evidence_sources.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingEvidenceSources < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_finding_evidence_sources do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_sources_on_finding_evidence_id' }, null: false, foreign_key: { on_delete: :cascade } + t.text :name + t.text :url + + t.text_limit :name, 2048 + t.text_limit :url, 2048 + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_evidence_sources + end + end +end diff --git a/db/migrate/20210707171536_create_vulnerability_finding_evidence_assets.rb b/db/migrate/20210707171536_create_vulnerability_finding_evidence_assets.rb new file mode 100644 index 00000000000..57c71e6bc17 --- /dev/null +++ b/db/migrate/20210707171536_create_vulnerability_finding_evidence_assets.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingEvidenceAssets < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_finding_evidence_assets do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_assets_on_finding_evidence_id' }, null: false, foreign_key: { on_delete: :cascade } + t.text :type + t.text :name + t.text :url + + t.text_limit :type, 2048 + t.text_limit :name, 2048 + t.text_limit :url, 2048 + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_evidence_assets + end + end +end diff --git a/db/migrate/20210707171554_create_vulnerability_flags.rb b/db/migrate/20210707171554_create_vulnerability_flags.rb new file mode 100644 index 00000000000..bf33963b08f --- /dev/null +++ b/db/migrate/20210707171554_create_vulnerability_flags.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFlags < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + FALSE_POSITIVE_ENUM_VALUE = 0 + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_flags do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_occurrence, null: false, foreign_key: { on_delete: :cascade } + + t.integer :flag_type, limit: 2, null: false, default: FALSE_POSITIVE_ENUM_VALUE + + t.text :origin, null: false + t.text :description, null: false + + t.text_limit :origin, 255 + t.text_limit :description, 1024 + end + end + + def down + drop_table :vulnerability_flags + end +end diff --git a/db/migrate/20210707173645_add_project_settings_previous_default_branch_text_limit.rb b/db/migrate/20210707173645_add_project_settings_previous_default_branch_text_limit.rb new file mode 100644 index 00000000000..a6a83b00234 --- /dev/null +++ b/db/migrate/20210707173645_add_project_settings_previous_default_branch_text_limit.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddProjectSettingsPreviousDefaultBranchTextLimit < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :project_settings, :previous_default_branch, 4096 + end + + def down + remove_text_limit :project_settings, :previous_default_branch + end +end diff --git a/db/migrate/20210707181536_create_vulnerability_finding_evidence_supporting_messages.rb b/db/migrate/20210707181536_create_vulnerability_finding_evidence_supporting_messages.rb new file mode 100644 index 00000000000..b9fc822a5a3 --- /dev/null +++ b/db/migrate/20210707181536_create_vulnerability_finding_evidence_supporting_messages.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingEvidenceSupportingMessages < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_finding_evidence_supporting_messages do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_supporting_messages_on_finding_evidence_id' }, null: false, foreign_key: { on_delete: :cascade } + t.text :name + + t.text_limit :name, 2048 + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_evidence_supporting_messages + end + end +end diff --git a/db/migrate/20210708063032_add_failed_count_to_merge_request_cleanup_schedules.rb b/db/migrate/20210708063032_add_failed_count_to_merge_request_cleanup_schedules.rb new file mode 100644 index 00000000000..f613856a18c --- /dev/null +++ b/db/migrate/20210708063032_add_failed_count_to_merge_request_cleanup_schedules.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddFailedCountToMergeRequestCleanupSchedules < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def change + add_column :merge_request_cleanup_schedules, :failed_count, :integer, default: 0, null: false + end +end diff --git a/db/migrate/20210708124229_add_security_scans_created_at_index.rb b/db/migrate/20210708124229_add_security_scans_created_at_index.rb new file mode 100644 index 00000000000..d2d1958f5b9 --- /dev/null +++ b/db/migrate/20210708124229_add_security_scans_created_at_index.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddSecurityScansCreatedAtIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_security_scans_on_created_at' + + def up + add_concurrent_index(:security_scans, :created_at, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:security_scans, INDEX_NAME) + end +end diff --git a/db/migrate/20210708131048_add_error_tracking_counter_cache.rb b/db/migrate/20210708131048_add_error_tracking_counter_cache.rb new file mode 100644 index 00000000000..3bf7e1e3688 --- /dev/null +++ b/db/migrate/20210708131048_add_error_tracking_counter_cache.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddErrorTrackingCounterCache < ActiveRecord::Migration[6.1] + def up + add_column :error_tracking_errors, :events_count, :bigint, null: false, default: 0 + end + + def down + remove_column :error_tracking_errors, :events_count + end +end diff --git a/db/migrate/20210708134446_remove_not_null_constraint_from_terms.rb b/db/migrate/20210708134446_remove_not_null_constraint_from_terms.rb new file mode 100644 index 00000000000..82abfeb57f9 --- /dev/null +++ b/db/migrate/20210708134446_remove_not_null_constraint_from_terms.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveNotNullConstraintFromTerms < ActiveRecord::Migration[6.1] + def up + change_column_null :application_setting_terms, :terms, true + end + + def down + change_column_null :application_setting_terms, :terms, false + end +end diff --git a/db/migrate/20210709085759_index_batched_migration_jobs_by_max_value.rb b/db/migrate/20210709085759_index_batched_migration_jobs_by_max_value.rb new file mode 100644 index 00000000000..8240e968e7a --- /dev/null +++ b/db/migrate/20210709085759_index_batched_migration_jobs_by_max_value.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class IndexBatchedMigrationJobsByMaxValue < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_migration_jobs_on_migration_id_and_max_value' + + def up + add_concurrent_index :batched_background_migration_jobs, %i(batched_background_migration_id max_value), name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :batched_background_migration_jobs, INDEX_NAME + end +end diff --git a/db/migrate/20210709132707_change_default_job_token_scope_enabled.rb b/db/migrate/20210709132707_change_default_job_token_scope_enabled.rb new file mode 100644 index 00000000000..fbd9f7baa61 --- /dev/null +++ b/db/migrate/20210709132707_change_default_job_token_scope_enabled.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ChangeDefaultJobTokenScopeEnabled < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + change_column_default :project_ci_cd_settings, :job_token_scope_enabled, from: false, to: true + end + end + + def down + with_lock_retries do + change_column_default :project_ci_cd_settings, :job_token_scope_enabled, from: true, to: false + end + end +end diff --git a/db/migrate/20210713070842_update_merge_request_cleanup_schedules_scheduled_at_index.rb b/db/migrate/20210713070842_update_merge_request_cleanup_schedules_scheduled_at_index.rb new file mode 100644 index 00000000000..a19d15d80a0 --- /dev/null +++ b/db/migrate/20210713070842_update_merge_request_cleanup_schedules_scheduled_at_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class UpdateMergeRequestCleanupSchedulesScheduledAtIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_mr_cleanup_schedules_timestamps_status' + OLD_INDEX_NAME = 'index_mr_cleanup_schedules_timestamps' + + disable_ddl_transaction! + + def up + add_concurrent_index(:merge_request_cleanup_schedules, :scheduled_at, where: 'completed_at IS NULL AND status = 0', name: INDEX_NAME) + remove_concurrent_index_by_name(:merge_request_cleanup_schedules, OLD_INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:merge_request_cleanup_schedules, INDEX_NAME) + add_concurrent_index(:merge_request_cleanup_schedules, :scheduled_at, where: 'completed_at IS NULL', name: OLD_INDEX_NAME) + end +end diff --git a/db/migrate/20210713135152_add_devops_adoption_vulnerability_management_used_count.rb b/db/migrate/20210713135152_add_devops_adoption_vulnerability_management_used_count.rb new file mode 100644 index 00000000000..74f24364177 --- /dev/null +++ b/db/migrate/20210713135152_add_devops_adoption_vulnerability_management_used_count.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionVulnerabilityManagementUsedCount < ActiveRecord::Migration[6.1] + def change + add_column :analytics_devops_adoption_snapshots, :vulnerability_management_used_count, :integer + end +end diff --git a/db/migrate/20210713144637_add_vulnerabilities_created_at_index.rb b/db/migrate/20210713144637_add_vulnerabilities_created_at_index.rb new file mode 100644 index 00000000000..27eb2691754 --- /dev/null +++ b/db/migrate/20210713144637_add_vulnerabilities_created_at_index.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddVulnerabilitiesCreatedAtIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'idx_vulnerabilities_partial_devops_adoption' + + def up + add_concurrent_index :vulnerabilities, [:project_id, :created_at], where: 'state != 1', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME + end +end diff --git a/db/migrate/20210714120600_add_detected_at_to_vulnerabilities.rb b/db/migrate/20210714120600_add_detected_at_to_vulnerabilities.rb new file mode 100644 index 00000000000..fb18ac4e174 --- /dev/null +++ b/db/migrate/20210714120600_add_detected_at_to_vulnerabilities.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddDetectedAtToVulnerabilities < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :vulnerabilities, :detected_at, :datetime_with_timezone + change_column_default :vulnerabilities, :detected_at, -> { 'NOW()' } + end + end + + def down + with_lock_retries do + remove_column :vulnerabilities, :detected_at + end + end +end diff --git a/db/migrate/20210716074555_revert_default_job_token_scope.rb b/db/migrate/20210716074555_revert_default_job_token_scope.rb new file mode 100644 index 00000000000..d28f75605e4 --- /dev/null +++ b/db/migrate/20210716074555_revert_default_job_token_scope.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RevertDefaultJobTokenScope < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + change_column_default :project_ci_cd_settings, :job_token_scope_enabled, from: true, to: false + end + end + + def down + with_lock_retries do + change_column_default :project_ci_cd_settings, :job_token_scope_enabled, from: false, to: true + end + end +end |