summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /db/migrate
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb8
-rw-r--r--db/migrate/20210611082822_add_pages_file_entries_to_plan_limits.rb7
-rw-r--r--db/migrate/20210628154900_create_detached_partitions_table.rb17
-rw-r--r--db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb77
-rw-r--r--db/migrate/20210630222522_add_customers_dot_jwt_signing_key_to_application_settings.rb10
-rw-r--r--db/migrate/20210630224625_generate_customers_dot_jwt_signing_key.rb32
-rw-r--r--db/migrate/20210706151154_add_remaining_ci_minutes_to_ci_pending_build.rb21
-rw-r--r--db/migrate/20210706151446_add_namespace_foreign_key_to_ci_pending_build.rb18
-rw-r--r--db/migrate/20210708202548_add_scanners_column_to_approval_project_rules.rb11
-rw-r--r--db/migrate/20210709221051_create_work_item_types.rb34
-rw-r--r--db/migrate/20210709221659_add_work_item_type_id_to_issue.rb31
-rw-r--r--db/migrate/20210712052519_add_label_applied_issuable_closed_to_issuable_sla.rb8
-rw-r--r--db/migrate/20210713123345_create_dast_profile_schedule.rb36
-rw-r--r--db/migrate/20210713211008_create_banned_users.rb20
-rw-r--r--db/migrate/20210713223941_remove_null_constraint_from_security_findings.rb11
-rw-r--r--db/migrate/20210714043818_add_index_for_label_applied_to_issuable_sla.rb17
-rw-r--r--db/migrate/20210715074359_add_foreign_key_to_dast_profile_schedules_on_dast_profile.rb17
-rw-r--r--db/migrate/20210715074933_add_foreign_key_to_dast_profile_schedules_on_user.rb17
-rw-r--r--db/migrate/20210715075203_add_foreign_key_to_dast_profile_schedules_on_project.rb17
-rw-r--r--db/migrate/20210719145532_add_foreign_keys_view.rb26
-rw-r--r--db/migrate/20210719182944_add_request_response_to_supporing_message.rb20
-rw-r--r--db/migrate/20210719192928_add_invite_email_success_to_member.rb11
-rw-r--r--db/migrate/20210720130006_create_error_tracking_client_keys.rb24
-rw-r--r--db/migrate/20210720140841_create_postgres_async_indexes_table.rb21
-rw-r--r--db/migrate/20210721125525_add_signed_file_to_packages_debian_project_distributions.rb13
-rw-r--r--db/migrate/20210721125545_add_signed_file_to_packages_debian_group_distributions.rb13
-rw-r--r--db/migrate/20210721125620_add_text_limit_to_packages_debian_project_distributions_signed_files.rb14
-rw-r--r--db/migrate/20210721125637_add_text_limit_to_packages_debian_group_distributions_signed_files.rb14
-rw-r--r--db/migrate/20210721134706_add_type_new_to_integrations.rb10
-rw-r--r--db/migrate/20210721134707_add_text_limit_to_integrations_type_new.rb15
-rw-r--r--db/migrate/20210721135638_add_triggers_to_integrations_type_new.rb79
-rw-r--r--db/migrate/20210721145029_add_state_to_members.rb13
-rw-r--r--db/migrate/20210721174411_add_is_removed_to_escalation_rules.rb7
-rw-r--r--db/migrate/20210721174441_update_escalation_rule_fk_for_pending_alert_escalations.rb29
-rw-r--r--db/migrate/20210721174453_remove_schedule_and_status_null_constraints_from_pending_escalations_alert.rb34
-rw-r--r--db/migrate/20210721211602_add_vulnerability_amount_column_into_approval_project_rules.rb11
-rw-r--r--db/migrate/20210722074220_remove_null_constraint_on_schedule_from_escalation_rules.rb13
-rw-r--r--db/migrate/20210722074242_add_user_to_escalation_rules.rb17
-rw-r--r--db/migrate/20210722074256_add_user_index_to_escalation_rules.rb33
-rw-r--r--db/migrate/20210722074309_add_user_fk_to_escalation_rules.rb17
-rw-r--r--db/migrate/20210722074339_add_xor_check_constraint_for_escalation_rules.rb17
-rw-r--r--db/migrate/20210722132844_devops_adoption_drop_redundant_indexes.rb20
-rw-r--r--db/migrate/20210722150102_operations_feature_flags_correct_flexible_rollout_values.rb29
-rw-r--r--db/migrate/20210722151951_add_columns_to_security_scans.rb21
-rw-r--r--db/migrate/20210722210041_add_overridden_uuid_to_security_findings.rb17
-rw-r--r--db/migrate/20210723173132_create_index_on_environments_auto_delete_at.rb20
-rw-r--r--db/migrate/20210726134950_add_integrated_to_error_tracking_setting.rb11
-rw-r--r--db/migrate/20210726202748_add_vulnerability_severities_into_approval_project_rules.rb11
-rw-r--r--db/migrate/20210728110654_add_status_to_error_tracking_error.rb11
-rw-r--r--db/migrate/20210728174349_add_fk_to_security_scans_columns.rb21
-rw-r--r--db/migrate/20210729061526_add_pronunciation_to_user_details.rb20
-rw-r--r--db/migrate/20210729061556_add_text_limit_to_user_details_pronunciation.rb15
-rw-r--r--db/migrate/20210729123101_confirm_security_bot.rb18
-rw-r--r--db/migrate/20210729161242_remove_foreign_keys_from_ci_test_case_failures.rb24
-rw-r--r--db/migrate/20210729192148_remove_foreign_keys_from_ci_test_cases.rb19
-rw-r--r--db/migrate/20210729202143_create_incident_management_issuable_escalation_statuses.rb20
-rw-r--r--db/migrate/20210730101609_create_analytics_cycle_analytics_stage_event_hashes.rb10
-rw-r--r--db/migrate/20210730102952_add_stage_hash_fk_to_project_stages.rb20
-rw-r--r--db/migrate/20210730103808_add_stage_hash_fk_to_group_stages.rb20
-rw-r--r--db/migrate/20210803110920_add_unique_index_to_vulnerability_flags_table.rb17
-rw-r--r--db/migrate/20210804150320_create_base_work_item_types.rb35
-rw-r--r--db/migrate/20210804200114_create_customer_relations_organizations.rb27
-rw-r--r--db/migrate/20210804202057_add_tmp_index_approval_project_rules_scanners.rb20
-rw-r--r--db/migrate/20210805085706_add_rule_index_to_security_orchestration_policy_rule_schedules.rb7
-rw-r--r--db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb17
-rw-r--r--db/migrate/20210809194250_rename_tables_ci_build_trace_section.rb11
-rw-r--r--db/migrate/20210812171704_create_project_ci_feature_usages.rb12
-rw-r--r--db/migrate/20210813101742_create_zentao_tracker_data.rb18
-rw-r--r--db/migrate/20210813111909_create_ci_build_trace_metadata.rb32
-rw-r--r--db/migrate/20210816161107_remove_index_containing_faulty_regex.rb18
-rw-r--r--db/migrate/20210817084338_add_foreign_key_from_ci_build_metadata_to_ci_job_artifacts.rb20
-rw-r--r--db/migrate/20210818034001_index_historical_data_on_recorded_at.rb17
-rw-r--r--db/migrate/20210818055357_add_unique_commit_design_user_mention_indexes.rb29
73 files changed, 1461 insertions, 6 deletions
diff --git a/db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb b/db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb
index efca683d748..fb2f7366955 100644
--- a/db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb
+++ b/db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb
@@ -6,14 +6,10 @@ class AddAllowToEditCommitToProjectSettings < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
- with_lock_retries do
- add_column :project_settings, :allow_editing_commit_messages, :boolean, default: false, null: false
- end
+ # no-op
end
def down
- with_lock_retries do
- remove_column :project_settings, :allow_editing_commit_messages
- end
+ # no-op
end
end
diff --git a/db/migrate/20210611082822_add_pages_file_entries_to_plan_limits.rb b/db/migrate/20210611082822_add_pages_file_entries_to_plan_limits.rb
new file mode 100644
index 00000000000..ef2177fa9ce
--- /dev/null
+++ b/db/migrate/20210611082822_add_pages_file_entries_to_plan_limits.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddPagesFileEntriesToPlanLimits < ActiveRecord::Migration[6.1]
+ def change
+ add_column(:plan_limits, :pages_file_entries, :integer, default: 200_000, null: false)
+ end
+end
diff --git a/db/migrate/20210628154900_create_detached_partitions_table.rb b/db/migrate/20210628154900_create_detached_partitions_table.rb
new file mode 100644
index 00000000000..05290f4dfb9
--- /dev/null
+++ b/db/migrate/20210628154900_create_detached_partitions_table.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class CreateDetachedPartitionsTable < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ create_table_with_constraints :detached_partitions do |t|
+ t.timestamps_with_timezone null: false
+ t.datetime_with_timezone :drop_after, null: false
+ t.text :table_name, null: false
+
+ # Postgres identifier names can be up to 63 bytes
+ # See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
+ t.text_limit :table_name, 63
+ end
+ end
+end
diff --git a/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb b/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb
new file mode 100644
index 00000000000..5db39334550
--- /dev/null
+++ b/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+class AssociateExistingDastBuildsWithVariables < ActiveRecord::Migration[6.1]
+ disable_ddl_transaction!
+
+ class Profile < ApplicationRecord
+ self.table_name = 'dast_profiles'
+ self.inheritance_column = :_type_disabled
+ end
+
+ class ProfilesPipeline < ApplicationRecord
+ include EachBatch
+
+ self.table_name = 'dast_profiles_pipelines'
+ self.inheritance_column = :_type_disabled
+
+ belongs_to :profile, foreign_key: :dast_profile_id
+ end
+
+ class Build < ApplicationRecord
+ self.table_name = 'ci_builds'
+ self.inheritance_column = :_type_disabled
+
+ default_scope { where(name: :dast, stage: :dast) } # rubocop:disable Cop/DefaultScope
+ end
+
+ class SiteProfilesBuild < ApplicationRecord
+ self.table_name = 'dast_site_profiles_builds'
+ self.inheritance_column = :_type_disabled
+ end
+
+ BATCH_SIZE = 300
+
+ def up
+ process_batch do |batch|
+ bulk_inserts = []
+
+ grouped_builds = fetch_builds(batch).group_by(&:commit_id)
+
+ batch.includes(:profile).each do |profile_pipeline|
+ builds = grouped_builds[profile_pipeline.ci_pipeline_id]
+
+ next if builds.blank?
+
+ builds.each do |build|
+ bulk_inserts.push(dast_site_profile_id: profile_pipeline.profile.dast_site_profile_id, ci_build_id: build.id)
+ end
+ end
+
+ SiteProfilesBuild.insert_all(bulk_inserts, unique_by: :ci_build_id)
+ end
+ end
+
+ def down
+ process_batch do |batch|
+ builds = fetch_builds(batch)
+
+ SiteProfilesBuild
+ .where(ci_build_id: builds)
+ .delete_all
+ end
+ end
+
+ private
+
+ def fetch_builds(batch)
+ # pluck necessary to support ci table decomposition
+ # https://gitlab.com/groups/gitlab-org/-/epics/6289
+ Build.where(commit_id: batch.pluck(:ci_pipeline_id))
+ end
+
+ def process_batch
+ ProfilesPipeline.each_batch(of: BATCH_SIZE, column: :ci_pipeline_id) do |batch|
+ yield(batch)
+ end
+ end
+end
diff --git a/db/migrate/20210630222522_add_customers_dot_jwt_signing_key_to_application_settings.rb b/db/migrate/20210630222522_add_customers_dot_jwt_signing_key_to_application_settings.rb
new file mode 100644
index 00000000000..5df0f84ab78
--- /dev/null
+++ b/db/migrate/20210630222522_add_customers_dot_jwt_signing_key_to_application_settings.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddCustomersDotJwtSigningKeyToApplicationSettings < ActiveRecord::Migration[6.1]
+ DOWNTIME = false
+
+ def change
+ add_column :application_settings, :encrypted_customers_dot_jwt_signing_key, :binary
+ add_column :application_settings, :encrypted_customers_dot_jwt_signing_key_iv, :binary
+ end
+end
diff --git a/db/migrate/20210630224625_generate_customers_dot_jwt_signing_key.rb b/db/migrate/20210630224625_generate_customers_dot_jwt_signing_key.rb
new file mode 100644
index 00000000000..703b2c7d0b8
--- /dev/null
+++ b/db/migrate/20210630224625_generate_customers_dot_jwt_signing_key.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class GenerateCustomersDotJwtSigningKey < ActiveRecord::Migration[6.1]
+ DOWNTIME = false
+
+ class ApplicationSetting < ActiveRecord::Base
+ self.table_name = 'application_settings'
+
+ attr_encrypted :customers_dot_jwt_signing_key, {
+ mode: :per_attribute_iv,
+ key: Gitlab::Utils.ensure_utf8_size(Rails.application.secrets.db_key_base, bytes: 32.bytes),
+ algorithm: 'aes-256-gcm',
+ encode: true
+ }
+ end
+
+ def up
+ ApplicationSetting.reset_column_information
+
+ ApplicationSetting.find_each do |application_setting|
+ application_setting.update(customers_dot_jwt_signing_key: OpenSSL::PKey::RSA.new(2048).to_pem)
+ end
+ end
+
+ def down
+ ApplicationSetting.reset_column_information
+
+ ApplicationSetting.find_each do |application_setting|
+ application_setting.update_columns(encrypted_customers_dot_jwt_signing_key: nil, encrypted_customers_dot_jwt_signing_key_iv: nil)
+ end
+ end
+end
diff --git a/db/migrate/20210706151154_add_remaining_ci_minutes_to_ci_pending_build.rb b/db/migrate/20210706151154_add_remaining_ci_minutes_to_ci_pending_build.rb
new file mode 100644
index 00000000000..866b16a6bb9
--- /dev/null
+++ b/db/migrate/20210706151154_add_remaining_ci_minutes_to_ci_pending_build.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddRemainingCiMinutesToCiPendingBuild < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column(:ci_pending_builds, :namespace_id, :bigint)
+ add_column(:ci_pending_builds, :minutes_exceeded, :boolean, null: false, default: false)
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column(:ci_pending_builds, :minutes_exceeded)
+ remove_column(:ci_pending_builds, :namespace_id)
+ end
+ end
+end
diff --git a/db/migrate/20210706151446_add_namespace_foreign_key_to_ci_pending_build.rb b/db/migrate/20210706151446_add_namespace_foreign_key_to_ci_pending_build.rb
new file mode 100644
index 00000000000..2a04850d905
--- /dev/null
+++ b/db/migrate/20210706151446_add_namespace_foreign_key_to_ci_pending_build.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddNamespaceForeignKeyToCiPendingBuild < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+ INDEX_NAME = 'index_ci_pending_builds_on_namespace_id'
+
+ def up
+ add_concurrent_index(:ci_pending_builds, :namespace_id, name: INDEX_NAME)
+ add_concurrent_foreign_key(:ci_pending_builds, :namespaces, column: :namespace_id, on_delete: :cascade)
+ end
+
+ def down
+ remove_foreign_key_if_exists(:ci_pending_builds, column: :namespace_id)
+ remove_concurrent_index_by_name(:ci_pending_builds, INDEX_NAME)
+ end
+end
diff --git a/db/migrate/20210708202548_add_scanners_column_to_approval_project_rules.rb b/db/migrate/20210708202548_add_scanners_column_to_approval_project_rules.rb
new file mode 100644
index 00000000000..a9175833dd7
--- /dev/null
+++ b/db/migrate/20210708202548_add_scanners_column_to_approval_project_rules.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddScannersColumnToApprovalProjectRules < ActiveRecord::Migration[6.1]
+ def up
+ add_column :approval_project_rules, :scanners, :text, array: true
+ end
+
+ def down
+ remove_column :approval_project_rules, :scanners
+ end
+end
diff --git a/db/migrate/20210709221051_create_work_item_types.rb b/db/migrate/20210709221051_create_work_item_types.rb
new file mode 100644
index 00000000000..749689811e0
--- /dev/null
+++ b/db/migrate/20210709221051_create_work_item_types.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class CreateWorkItemTypes < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ create_table_with_constraints :work_item_types do |t|
+ t.integer :base_type, limit: 2, default: 0, null: false
+ t.integer :cached_markdown_version
+ t.text :name, null: false
+ t.text :description # rubocop:disable Migration/AddLimitToTextColumns
+ t.text :description_html # rubocop:disable Migration/AddLimitToTextColumns
+ t.text :icon_name, null: true
+ t.references :namespace, foreign_key: { on_delete: :cascade }, index: false, null: true
+ t.timestamps_with_timezone null: false
+
+ t.text_limit :name, 255
+ t.text_limit :icon_name, 255
+ end
+
+ add_concurrent_index :work_item_types,
+ 'namespace_id, TRIM(BOTH FROM LOWER(name))',
+ unique: true,
+ name: :work_item_types_namespace_id_and_name_unique
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :work_item_types
+ end
+ end
+end
diff --git a/db/migrate/20210709221659_add_work_item_type_id_to_issue.rb b/db/migrate/20210709221659_add_work_item_type_id_to_issue.rb
new file mode 100644
index 00000000000..38292cd37c5
--- /dev/null
+++ b/db/migrate/20210709221659_add_work_item_type_id_to_issue.rb
@@ -0,0 +1,31 @@
+# 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 AddWorkItemTypeIdToIssue < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ unless column_exists?(:issues, :work_item_type_id)
+ with_lock_retries do
+ add_column :issues, :work_item_type_id, :bigint
+ end
+ end
+
+ add_concurrent_index :issues, :work_item_type_id
+ add_concurrent_foreign_key :issues, :work_item_types, column: :work_item_type_id, on_delete: nil
+ end
+
+ def down
+ if foreign_key_exists?(:issues, :work_item_types)
+ remove_foreign_key :issues, column: :work_item_type_id
+ end
+
+ with_lock_retries do
+ remove_column :issues, :work_item_type_id
+ end
+ end
+end
diff --git a/db/migrate/20210712052519_add_label_applied_issuable_closed_to_issuable_sla.rb b/db/migrate/20210712052519_add_label_applied_issuable_closed_to_issuable_sla.rb
new file mode 100644
index 00000000000..216d43dd62d
--- /dev/null
+++ b/db/migrate/20210712052519_add_label_applied_issuable_closed_to_issuable_sla.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class AddLabelAppliedIssuableClosedToIssuableSla < ActiveRecord::Migration[6.1]
+ def change
+ add_column :issuable_slas, :label_applied, :boolean, default: false, null: false
+ add_column :issuable_slas, :issuable_closed, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20210713123345_create_dast_profile_schedule.rb b/db/migrate/20210713123345_create_dast_profile_schedule.rb
new file mode 100644
index 00000000000..951aab63579
--- /dev/null
+++ b/db/migrate/20210713123345_create_dast_profile_schedule.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class CreateDastProfileSchedule < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_dast_profile_schedules_active_next_run_at'
+
+ def up
+ table_comment = {
+ owner: 'group::dynamic analysis', description: 'Scheduling for scans using DAST Profiles'
+ }
+
+ create_table_with_constraints :dast_profile_schedules, comment: table_comment.to_json do |t|
+ t.bigint :project_id, null: false
+ t.bigint :dast_profile_id, null: false
+ t.bigint :user_id
+
+ t.datetime_with_timezone :next_run_at, null: false
+ t.timestamps_with_timezone null: false
+ t.boolean :active, default: true, null: false
+ t.text :cron, null: false
+ t.text_limit :cron, 255
+
+ t.index %i[active next_run_at], name: INDEX_NAME
+ t.index %i[project_id dast_profile_id], unique: true
+ t.index :dast_profile_id
+ t.index :user_id
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :dast_profile_schedules
+ end
+ end
+end
diff --git a/db/migrate/20210713211008_create_banned_users.rb b/db/migrate/20210713211008_create_banned_users.rb
new file mode 100644
index 00000000000..7e5eb7f95b8
--- /dev/null
+++ b/db/migrate/20210713211008_create_banned_users.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class CreateBannedUsers < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ create_table :banned_users, id: false do |t|
+ t.timestamps_with_timezone null: false
+ t.references :user, primary_key: true, default: nil, foreign_key: { on_delete: :cascade }, type: :bigint, index: false, null: false
+ end
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :banned_users
+ end
+ end
+end
diff --git a/db/migrate/20210713223941_remove_null_constraint_from_security_findings.rb b/db/migrate/20210713223941_remove_null_constraint_from_security_findings.rb
new file mode 100644
index 00000000000..f0b9addb5f2
--- /dev/null
+++ b/db/migrate/20210713223941_remove_null_constraint_from_security_findings.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class RemoveNullConstraintFromSecurityFindings < ActiveRecord::Migration[6.1]
+ def up
+ change_column_null :security_findings, :project_fingerprint, true
+ end
+
+ def down
+ # no-op, it can not be reverted due to existing records that might not be valid
+ end
+end
diff --git a/db/migrate/20210714043818_add_index_for_label_applied_to_issuable_sla.rb b/db/migrate/20210714043818_add_index_for_label_applied_to_issuable_sla.rb
new file mode 100644
index 00000000000..5931941a95e
--- /dev/null
+++ b/db/migrate/20210714043818_add_index_for_label_applied_to_issuable_sla.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexForLabelAppliedToIssuableSla < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_issuable_slas_on_due_at_id_label_applied_issuable_closed'
+
+ def up
+ add_concurrent_index :issuable_slas, [:due_at, :id], name: INDEX_NAME, where: 'label_applied = FALSE AND issuable_closed = FALSE'
+ end
+
+ def down
+ remove_concurrent_index_by_name :issuable_slas, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210715074359_add_foreign_key_to_dast_profile_schedules_on_dast_profile.rb b/db/migrate/20210715074359_add_foreign_key_to_dast_profile_schedules_on_dast_profile.rb
new file mode 100644
index 00000000000..c042a875f57
--- /dev/null
+++ b/db/migrate/20210715074359_add_foreign_key_to_dast_profile_schedules_on_dast_profile.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToDastProfileSchedulesOnDastProfile < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :dast_profile_schedules, :dast_profiles, column: :dast_profile_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :dast_profile_schedules, column: :dast_profile_id
+ end
+ end
+end
diff --git a/db/migrate/20210715074933_add_foreign_key_to_dast_profile_schedules_on_user.rb b/db/migrate/20210715074933_add_foreign_key_to_dast_profile_schedules_on_user.rb
new file mode 100644
index 00000000000..576cee090ff
--- /dev/null
+++ b/db/migrate/20210715074933_add_foreign_key_to_dast_profile_schedules_on_user.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToDastProfileSchedulesOnUser < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :dast_profile_schedules, :users, column: :user_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :dast_profile_schedules, column: :user_id
+ end
+ end
+end
diff --git a/db/migrate/20210715075203_add_foreign_key_to_dast_profile_schedules_on_project.rb b/db/migrate/20210715075203_add_foreign_key_to_dast_profile_schedules_on_project.rb
new file mode 100644
index 00000000000..cfc76c4a12c
--- /dev/null
+++ b/db/migrate/20210715075203_add_foreign_key_to_dast_profile_schedules_on_project.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToDastProfileSchedulesOnProject < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :dast_profile_schedules, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :dast_profile_schedules, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20210719145532_add_foreign_keys_view.rb b/db/migrate/20210719145532_add_foreign_keys_view.rb
new file mode 100644
index 00000000000..2d31371e782
--- /dev/null
+++ b/db/migrate/20210719145532_add_foreign_keys_view.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class AddForeignKeysView < ActiveRecord::Migration[6.1]
+ def up
+ execute(<<~SQL)
+ CREATE OR REPLACE VIEW postgres_foreign_keys AS
+ SELECT
+ pg_constraint.oid AS oid,
+ pg_constraint.conname AS name,
+ constrained_namespace.nspname::text || '.'::text || constrained_table.relname::text AS constrained_table_identifier,
+ referenced_namespace.nspname::text || '.'::text || referenced_table.relname::text AS referenced_table_identifier
+ FROM pg_constraint
+ INNER JOIN pg_class constrained_table ON constrained_table.oid = pg_constraint.conrelid
+ INNER JOIN pg_class referenced_table ON referenced_table.oid = pg_constraint.confrelid
+ INNER JOIN pg_namespace constrained_namespace ON constrained_table.relnamespace = constrained_namespace.oid
+ INNER JOIN pg_namespace referenced_namespace ON referenced_table.relnamespace = referenced_namespace.oid
+ WHERE contype = 'f';
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ DROP VIEW IF EXISTS postgres_foreign_keys
+ SQL
+ end
+end
diff --git a/db/migrate/20210719182944_add_request_response_to_supporing_message.rb b/db/migrate/20210719182944_add_request_response_to_supporing_message.rb
new file mode 100644
index 00000000000..a374361e88d
--- /dev/null
+++ b/db/migrate/20210719182944_add_request_response_to_supporing_message.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddRequestResponseToSupporingMessage < ActiveRecord::Migration[6.1]
+ def change
+ change_column_null(:vulnerability_finding_evidence_requests, :vulnerability_finding_evidence_id, true)
+ change_column_null(:vulnerability_finding_evidence_responses, :vulnerability_finding_evidence_id, true)
+
+ # rubocop: disable Migration/AddReference
+ # Table is empty, so no need to use add_concurrent_foreign_key and add_concurrent_index
+ add_reference(:vulnerability_finding_evidence_requests,
+ :vulnerability_finding_evidence_supporting_message,
+ index: { name: 'finding_evidence_requests_on_supporting_evidence_id' },
+ foreign_key: { on_delete: :cascade })
+ add_reference(:vulnerability_finding_evidence_responses,
+ :vulnerability_finding_evidence_supporting_message,
+ index: { name: 'finding_evidence_responses_on_supporting_evidence_id' },
+ foreign_key: { on_delete: :cascade })
+ # rubocop:enable Migration/AddReference
+ end
+end
diff --git a/db/migrate/20210719192928_add_invite_email_success_to_member.rb b/db/migrate/20210719192928_add_invite_email_success_to_member.rb
new file mode 100644
index 00000000000..ad629483a82
--- /dev/null
+++ b/db/migrate/20210719192928_add_invite_email_success_to_member.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddInviteEmailSuccessToMember < ActiveRecord::Migration[6.1]
+ def up
+ # no-op
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20210720130006_create_error_tracking_client_keys.rb b/db/migrate/20210720130006_create_error_tracking_client_keys.rb
new file mode 100644
index 00000000000..caea4a3d65b
--- /dev/null
+++ b/db/migrate/20210720130006_create_error_tracking_client_keys.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class CreateErrorTrackingClientKeys < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ create_table_with_constraints :error_tracking_client_keys do |t|
+ t.references :project,
+ index: true,
+ null: false,
+ foreign_key: { on_delete: :cascade }
+
+ t.boolean :active, default: true, null: false
+ t.text :public_key, null: false
+ t.text_limit :public_key, 255
+
+ t.timestamps_with_timezone
+ end
+ end
+
+ def down
+ drop_table :error_tracking_client_keys
+ end
+end
diff --git a/db/migrate/20210720140841_create_postgres_async_indexes_table.rb b/db/migrate/20210720140841_create_postgres_async_indexes_table.rb
new file mode 100644
index 00000000000..707367e5f6c
--- /dev/null
+++ b/db/migrate/20210720140841_create_postgres_async_indexes_table.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class CreatePostgresAsyncIndexesTable < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ create_table_with_constraints :postgres_async_indexes do |t|
+ t.timestamps_with_timezone null: false
+
+ t.text :name, null: false
+ t.text :definition, null: false
+ t.text :table_name, null: false
+
+ t.text_limit :name, 63
+ t.text_limit :definition, 2048
+ t.text_limit :table_name, 63
+
+ t.index :name, unique: true
+ end
+ end
+end
diff --git a/db/migrate/20210721125525_add_signed_file_to_packages_debian_project_distributions.rb b/db/migrate/20210721125525_add_signed_file_to_packages_debian_project_distributions.rb
new file mode 100644
index 00000000000..7e4a785cb54
--- /dev/null
+++ b/db/migrate/20210721125525_add_signed_file_to_packages_debian_project_distributions.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddSignedFileToPackagesDebianProjectDistributions < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20210721125620_add_text_limit_to_packages_debian_project_distributions_signed_files
+ def change
+ add_column :packages_debian_project_distributions, :signed_file, :text
+ add_column :packages_debian_project_distributions, :signed_file_store, :integer, limit: 2, default: 1, null: false
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+end
diff --git a/db/migrate/20210721125545_add_signed_file_to_packages_debian_group_distributions.rb b/db/migrate/20210721125545_add_signed_file_to_packages_debian_group_distributions.rb
new file mode 100644
index 00000000000..f27c158bed2
--- /dev/null
+++ b/db/migrate/20210721125545_add_signed_file_to_packages_debian_group_distributions.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddSignedFileToPackagesDebianGroupDistributions < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20210721125637_add_text_limit_to_packages_debian_group_distributions_signed_files
+ def change
+ add_column :packages_debian_group_distributions, :signed_file, :text
+ add_column :packages_debian_group_distributions, :signed_file_store, :integer, limit: 2, default: 1, null: false
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+end
diff --git a/db/migrate/20210721125620_add_text_limit_to_packages_debian_project_distributions_signed_files.rb b/db/migrate/20210721125620_add_text_limit_to_packages_debian_project_distributions_signed_files.rb
new file mode 100644
index 00000000000..77524a5b068
--- /dev/null
+++ b/db/migrate/20210721125620_add_text_limit_to_packages_debian_project_distributions_signed_files.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddTextLimitToPackagesDebianProjectDistributionsSignedFiles < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :packages_debian_project_distributions, :signed_file, 255
+ end
+
+ def down
+ remove_text_limit :packages_debian_project_distributions, :signed_file
+ end
+end
diff --git a/db/migrate/20210721125637_add_text_limit_to_packages_debian_group_distributions_signed_files.rb b/db/migrate/20210721125637_add_text_limit_to_packages_debian_group_distributions_signed_files.rb
new file mode 100644
index 00000000000..ef203cb2ff7
--- /dev/null
+++ b/db/migrate/20210721125637_add_text_limit_to_packages_debian_group_distributions_signed_files.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddTextLimitToPackagesDebianGroupDistributionsSignedFiles < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :packages_debian_group_distributions, :signed_file, 255
+ end
+
+ def down
+ remove_text_limit :packages_debian_group_distributions, :signed_file
+ end
+end
diff --git a/db/migrate/20210721134706_add_type_new_to_integrations.rb b/db/migrate/20210721134706_add_type_new_to_integrations.rb
new file mode 100644
index 00000000000..b43fb73436c
--- /dev/null
+++ b/db/migrate/20210721134706_add_type_new_to_integrations.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddTypeNewToIntegrations < ActiveRecord::Migration[6.1]
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20210721134707_add_text_limit_to_integrations_type_new
+ def change
+ add_column :integrations, :type_new, :text
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+end
diff --git a/db/migrate/20210721134707_add_text_limit_to_integrations_type_new.rb b/db/migrate/20210721134707_add_text_limit_to_integrations_type_new.rb
new file mode 100644
index 00000000000..8fb98abad8c
--- /dev/null
+++ b/db/migrate/20210721134707_add_text_limit_to_integrations_type_new.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddTextLimitToIntegrationsTypeNew < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :integrations, :type_new, 255
+ end
+
+ def down
+ remove_text_limit :integrations, :type_new
+ end
+end
diff --git a/db/migrate/20210721135638_add_triggers_to_integrations_type_new.rb b/db/migrate/20210721135638_add_triggers_to_integrations_type_new.rb
new file mode 100644
index 00000000000..6b1f2aeba18
--- /dev/null
+++ b/db/migrate/20210721135638_add_triggers_to_integrations_type_new.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+class AddTriggersToIntegrationsTypeNew < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::SchemaHelpers
+
+ FUNCTION_NAME = 'integrations_set_type_new'
+ TRIGGER_ON_INSERT_NAME = 'trigger_type_new_on_insert'
+
+ def up
+ create_trigger_function(FUNCTION_NAME, replace: true) do
+ # This list matches `Gitlab::Integrations::StiType::NAMESPACED_INTEGRATIONS`.
+ #
+ # If we add new integrations after this migration we can directly use the
+ # correct class name in `type`, and don't need to add it to `NAMESPACED_INTEGRATIONS`.
+ <<~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'),
+ ('YoutrackService', 'Integrations::Youtrack'),
+ ('WebexTeamsService', 'Integrations::WebexTeams'),
+
+ -- EE-only integrations
+ ('GithubService', 'Integrations::Github'),
+ ('GitlabSlackApplicationService', 'Integrations::GitlabSlackApplication')
+ )
+
+ UPDATE integrations SET type_new = mapping.new_type
+ FROM mapping
+ WHERE integrations.id = NEW.id
+ AND mapping.old_type = NEW.type;
+ RETURN NULL;
+ SQL
+ end
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{TRIGGER_ON_INSERT_NAME}
+ AFTER INSERT ON integrations
+ FOR EACH ROW
+ EXECUTE FUNCTION #{FUNCTION_NAME}();
+ SQL
+ end
+
+ def down
+ drop_trigger(:integrations, TRIGGER_ON_INSERT_NAME)
+ drop_function(FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20210721145029_add_state_to_members.rb b/db/migrate/20210721145029_add_state_to_members.rb
new file mode 100644
index 00000000000..d727c858374
--- /dev/null
+++ b/db/migrate/20210721145029_add_state_to_members.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddStateToMembers < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ # no-op
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20210721174411_add_is_removed_to_escalation_rules.rb b/db/migrate/20210721174411_add_is_removed_to_escalation_rules.rb
new file mode 100644
index 00000000000..00af9414ab7
--- /dev/null
+++ b/db/migrate/20210721174411_add_is_removed_to_escalation_rules.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddIsRemovedToEscalationRules < ActiveRecord::Migration[6.1]
+ def change
+ add_column :incident_management_escalation_rules, :is_removed, :boolean, null: false, default: false
+ end
+end
diff --git a/db/migrate/20210721174441_update_escalation_rule_fk_for_pending_alert_escalations.rb b/db/migrate/20210721174441_update_escalation_rule_fk_for_pending_alert_escalations.rb
new file mode 100644
index 00000000000..cf52a43435f
--- /dev/null
+++ b/db/migrate/20210721174441_update_escalation_rule_fk_for_pending_alert_escalations.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class UpdateEscalationRuleFkForPendingAlertEscalations < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+
+ OLD_FOREIGN_KEY_CONSTRAINT = 'fk_rails_057c1e3d87'
+
+ # Swap foreign key contrainst from ON DELETE SET NULL to ON DELETE CASCADE
+ def up
+ remove_foreign_key_if_exists :incident_management_pending_alert_escalations, :incident_management_escalation_rules, name: OLD_FOREIGN_KEY_CONSTRAINT
+
+ add_concurrent_partitioned_foreign_key :incident_management_pending_alert_escalations,
+ :incident_management_escalation_rules,
+ column: :rule_id
+ end
+
+ def down
+ remove_foreign_key_if_exists :incident_management_pending_alert_escalations, :incident_management_escalation_rules, column: :rule_id
+
+ add_concurrent_partitioned_foreign_key :incident_management_pending_alert_escalations,
+ :incident_management_escalation_rules,
+ column: :rule_id,
+ on_delete: :nullify,
+ name: OLD_FOREIGN_KEY_CONSTRAINT
+ end
+end
diff --git a/db/migrate/20210721174453_remove_schedule_and_status_null_constraints_from_pending_escalations_alert.rb b/db/migrate/20210721174453_remove_schedule_and_status_null_constraints_from_pending_escalations_alert.rb
new file mode 100644
index 00000000000..89adaf89693
--- /dev/null
+++ b/db/migrate/20210721174453_remove_schedule_and_status_null_constraints_from_pending_escalations_alert.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class RemoveScheduleAndStatusNullConstraintsFromPendingEscalationsAlert < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ # In preparation of removal of these columns in 14.3.
+ def up
+ with_lock_retries do
+ change_column_null :incident_management_pending_alert_escalations, :status, true
+ change_column_null :incident_management_pending_alert_escalations, :schedule_id, true
+ end
+ end
+
+ def down
+ backfill_from_rules_and_disallow_column_null :status, value: :status
+ backfill_from_rules_and_disallow_column_null :schedule_id, value: :oncall_schedule_id
+ end
+
+ private
+
+ def backfill_from_rules_and_disallow_column_null(column, value:)
+ with_lock_retries do
+ execute <<~SQL
+ UPDATE incident_management_pending_alert_escalations AS escalations
+ SET #{column} = rules.#{value}
+ FROM incident_management_escalation_rules AS rules
+ WHERE rule_id = rules.id
+ AND escalations.#{column} IS NULL
+ SQL
+
+ change_column_null :incident_management_pending_alert_escalations, column, false
+ end
+ end
+end
diff --git a/db/migrate/20210721211602_add_vulnerability_amount_column_into_approval_project_rules.rb b/db/migrate/20210721211602_add_vulnerability_amount_column_into_approval_project_rules.rb
new file mode 100644
index 00000000000..3c0fa35d9c3
--- /dev/null
+++ b/db/migrate/20210721211602_add_vulnerability_amount_column_into_approval_project_rules.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddVulnerabilityAmountColumnIntoApprovalProjectRules < ActiveRecord::Migration[6.1]
+ def up
+ add_column :approval_project_rules, :vulnerabilities_allowed, :integer, limit: 2
+ end
+
+ def down
+ remove_column :approval_project_rules, :vulnerabilities_allowed
+ end
+end
diff --git a/db/migrate/20210722074220_remove_null_constraint_on_schedule_from_escalation_rules.rb b/db/migrate/20210722074220_remove_null_constraint_on_schedule_from_escalation_rules.rb
new file mode 100644
index 00000000000..7146c6c9537
--- /dev/null
+++ b/db/migrate/20210722074220_remove_null_constraint_on_schedule_from_escalation_rules.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemoveNullConstraintOnScheduleFromEscalationRules < ActiveRecord::Migration[6.1]
+ def up
+ change_column_null :incident_management_escalation_rules, :oncall_schedule_id, true
+ end
+
+ def down
+ exec_query 'DELETE FROM incident_management_escalation_rules WHERE oncall_schedule_id IS NULL'
+
+ change_column_null :incident_management_escalation_rules, :oncall_schedule_id, false
+ end
+end
diff --git a/db/migrate/20210722074242_add_user_to_escalation_rules.rb b/db/migrate/20210722074242_add_user_to_escalation_rules.rb
new file mode 100644
index 00000000000..061dd6194f7
--- /dev/null
+++ b/db/migrate/20210722074242_add_user_to_escalation_rules.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddUserToEscalationRules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ add_column :incident_management_escalation_rules, :user_id, :bigint, null: true
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :incident_management_escalation_rules, :user_id
+ end
+ end
+end
diff --git a/db/migrate/20210722074256_add_user_index_to_escalation_rules.rb b/db/migrate/20210722074256_add_user_index_to_escalation_rules.rb
new file mode 100644
index 00000000000..047149d6e7c
--- /dev/null
+++ b/db/migrate/20210722074256_add_user_index_to_escalation_rules.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class AddUserIndexToEscalationRules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ USER_INDEX_NAME = 'index_escalation_rules_on_user'
+ OLD_UNIQUE_INDEX_NAME = 'index_on_policy_schedule_status_elapsed_time_escalation_rules'
+ NEW_UNIQUE_INDEX_NAME = 'index_escalation_rules_on_all_attributes'
+
+ def up
+ remove_concurrent_index_by_name :incident_management_escalation_rules, OLD_UNIQUE_INDEX_NAME
+
+ add_concurrent_index :incident_management_escalation_rules, :user_id, name: USER_INDEX_NAME
+ add_concurrent_index :incident_management_escalation_rules,
+ [:policy_id, :oncall_schedule_id, :status, :elapsed_time_seconds, :user_id],
+ unique: true,
+ name: NEW_UNIQUE_INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :incident_management_escalation_rules, USER_INDEX_NAME
+ remove_concurrent_index_by_name :incident_management_escalation_rules, NEW_UNIQUE_INDEX_NAME
+
+ exec_query 'DELETE FROM incident_management_escalation_rules WHERE oncall_schedule_id IS NULL'
+
+ add_concurrent_index :incident_management_escalation_rules,
+ [:policy_id, :oncall_schedule_id, :status, :elapsed_time_seconds],
+ unique: true,
+ name: OLD_UNIQUE_INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210722074309_add_user_fk_to_escalation_rules.rb b/db/migrate/20210722074309_add_user_fk_to_escalation_rules.rb
new file mode 100644
index 00000000000..acdfc1ed835
--- /dev/null
+++ b/db/migrate/20210722074309_add_user_fk_to_escalation_rules.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddUserFkToEscalationRules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :incident_management_escalation_rules, :users, column: :user_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :incident_management_escalation_rules, column: :user_id
+ end
+ end
+end
diff --git a/db/migrate/20210722074339_add_xor_check_constraint_for_escalation_rules.rb b/db/migrate/20210722074339_add_xor_check_constraint_for_escalation_rules.rb
new file mode 100644
index 00000000000..bd140e1da56
--- /dev/null
+++ b/db/migrate/20210722074339_add_xor_check_constraint_for_escalation_rules.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddXorCheckConstraintForEscalationRules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'escalation_rules_one_of_oncall_schedule_or_user'
+
+ def up
+ add_check_constraint :incident_management_escalation_rules, 'num_nonnulls(oncall_schedule_id, user_id) = 1', CONSTRAINT_NAME
+ end
+
+ def down
+ remove_check_constraint :incident_management_escalation_rules, CONSTRAINT_NAME
+ end
+end
diff --git a/db/migrate/20210722132844_devops_adoption_drop_redundant_indexes.rb b/db/migrate/20210722132844_devops_adoption_drop_redundant_indexes.rb
new file mode 100644
index 00000000000..3f74f72454d
--- /dev/null
+++ b/db/migrate/20210722132844_devops_adoption_drop_redundant_indexes.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class DevopsAdoptionDropRedundantIndexes < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_SAST = 'index_ci_job_artifacts_sast_for_devops_adoption'
+ INDEX_DAST = 'index_ci_job_artifacts_dast_for_devops_adoption'
+
+ def up
+ remove_concurrent_index_by_name :ci_job_artifacts, INDEX_SAST
+ remove_concurrent_index_by_name :ci_job_artifacts, INDEX_DAST
+ end
+
+ def down
+ add_concurrent_index :ci_job_artifacts, [:project_id, :created_at], where: "file_type = 5", name: INDEX_SAST
+ add_concurrent_index :ci_job_artifacts, [:project_id, :created_at], where: "file_type = 8", name: INDEX_DAST
+ end
+end
diff --git a/db/migrate/20210722150102_operations_feature_flags_correct_flexible_rollout_values.rb b/db/migrate/20210722150102_operations_feature_flags_correct_flexible_rollout_values.rb
new file mode 100644
index 00000000000..974559239d7
--- /dev/null
+++ b/db/migrate/20210722150102_operations_feature_flags_correct_flexible_rollout_values.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class OperationsFeatureFlagsCorrectFlexibleRolloutValues < ActiveRecord::Migration[6.1]
+ STICKINESS = { "USERID" => "userId", "RANDOM" => "random", "SESSIONID" => "sessionId", "DEFAULT" => "default" }.freeze
+
+ def up
+ STICKINESS.each do |before, after|
+ update_statement = <<-SQL
+ UPDATE operations_strategies
+ SET parameters = parameters || jsonb_build_object('stickiness', '#{quote_string(after)}')
+ WHERE name = 'flexibleRollout' AND parameters->>'stickiness' = '#{quote_string(before)}'
+ SQL
+
+ execute(update_statement)
+ end
+ end
+
+ def down
+ STICKINESS.each do |before, after|
+ update_statement = <<-SQL
+ UPDATE operations_strategies
+ SET parameters = parameters || jsonb_build_object('stickiness', '#{quote_string(before)}')
+ WHERE name = 'flexibleRollout' AND parameters->>'stickiness' = '#{quote_string(after)}'
+ SQL
+
+ execute(update_statement)
+ end
+ end
+end
diff --git a/db/migrate/20210722151951_add_columns_to_security_scans.rb b/db/migrate/20210722151951_add_columns_to_security_scans.rb
new file mode 100644
index 00000000000..341cef057ce
--- /dev/null
+++ b/db/migrate/20210722151951_add_columns_to_security_scans.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddColumnsToSecurityScans < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column :security_scans, :project_id, :bigint
+ add_column :security_scans, :pipeline_id, :bigint
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :security_scans, :project_id, :bigint
+ remove_column :security_scans, :pipeline_id, :bigint
+ end
+ end
+end
diff --git a/db/migrate/20210722210041_add_overridden_uuid_to_security_findings.rb b/db/migrate/20210722210041_add_overridden_uuid_to_security_findings.rb
new file mode 100644
index 00000000000..4678aba2cff
--- /dev/null
+++ b/db/migrate/20210722210041_add_overridden_uuid_to_security_findings.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddOverriddenUuidToSecurityFindings < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ add_column :security_findings, :overridden_uuid, :uuid, null: true
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :security_findings, :overridden_uuid
+ end
+ end
+end
diff --git a/db/migrate/20210723173132_create_index_on_environments_auto_delete_at.rb b/db/migrate/20210723173132_create_index_on_environments_auto_delete_at.rb
new file mode 100644
index 00000000000..cfaff4d0304
--- /dev/null
+++ b/db/migrate/20210723173132_create_index_on_environments_auto_delete_at.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class CreateIndexOnEnvironmentsAutoDeleteAt < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_environments_on_state_and_auto_delete_at'
+
+ def up
+ add_concurrent_index :environments,
+ %i[auto_delete_at],
+ where: "auto_delete_at IS NOT NULL AND state = 'stopped'",
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :environments, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210726134950_add_integrated_to_error_tracking_setting.rb b/db/migrate/20210726134950_add_integrated_to_error_tracking_setting.rb
new file mode 100644
index 00000000000..5fd558e0c1b
--- /dev/null
+++ b/db/migrate/20210726134950_add_integrated_to_error_tracking_setting.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddIntegratedToErrorTrackingSetting < ActiveRecord::Migration[6.1]
+ def up
+ add_column :project_error_tracking_settings, :integrated, :boolean, null: false, default: false
+ end
+
+ def down
+ remove_column :project_error_tracking_settings, :integrated
+ end
+end
diff --git a/db/migrate/20210726202748_add_vulnerability_severities_into_approval_project_rules.rb b/db/migrate/20210726202748_add_vulnerability_severities_into_approval_project_rules.rb
new file mode 100644
index 00000000000..bd17a9df5df
--- /dev/null
+++ b/db/migrate/20210726202748_add_vulnerability_severities_into_approval_project_rules.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddVulnerabilitySeveritiesIntoApprovalProjectRules < ActiveRecord::Migration[6.1]
+ def up
+ add_column :approval_project_rules, :severity_levels, :text, array: true, null: false, default: []
+ end
+
+ def down
+ remove_column :approval_project_rules, :severity_levels
+ end
+end
diff --git a/db/migrate/20210728110654_add_status_to_error_tracking_error.rb b/db/migrate/20210728110654_add_status_to_error_tracking_error.rb
new file mode 100644
index 00000000000..035f97dc963
--- /dev/null
+++ b/db/migrate/20210728110654_add_status_to_error_tracking_error.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddStatusToErrorTrackingError < ActiveRecord::Migration[6.1]
+ def up
+ add_column :error_tracking_errors, :status, :integer, null: false, default: 0, limit: 2
+ end
+
+ def down
+ remove_column :error_tracking_errors, :status
+ end
+end
diff --git a/db/migrate/20210728174349_add_fk_to_security_scans_columns.rb b/db/migrate/20210728174349_add_fk_to_security_scans_columns.rb
new file mode 100644
index 00000000000..418097b92e5
--- /dev/null
+++ b/db/migrate/20210728174349_add_fk_to_security_scans_columns.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddFkToSecurityScansColumns < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :security_scans, :project_id
+ add_concurrent_foreign_key :security_scans, :projects, column: :project_id, on_delete: :cascade
+
+ add_concurrent_index :security_scans, :pipeline_id
+ end
+
+ def down
+ remove_foreign_key :security_scans, column: :project_id
+ remove_concurrent_index_by_name :security_scans, name: 'index_security_scans_on_project_id'
+
+ remove_concurrent_index_by_name :security_scans, name: 'index_security_scans_on_pipeline_id'
+ end
+end
diff --git a/db/migrate/20210729061526_add_pronunciation_to_user_details.rb b/db/migrate/20210729061526_add_pronunciation_to_user_details.rb
new file mode 100644
index 00000000000..6e0c8f1e808
--- /dev/null
+++ b/db/migrate/20210729061526_add_pronunciation_to_user_details.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddPronunciationToUserDetails < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20210729061556_add_text_limit_to_user_details_pronunciation.rb
+ with_lock_retries do
+ add_column :user_details, :pronunciation, :text, null: true
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :user_details, :pronunciation
+ end
+ end
+end
diff --git a/db/migrate/20210729061556_add_text_limit_to_user_details_pronunciation.rb b/db/migrate/20210729061556_add_text_limit_to_user_details_pronunciation.rb
new file mode 100644
index 00000000000..5466ee7bafa
--- /dev/null
+++ b/db/migrate/20210729061556_add_text_limit_to_user_details_pronunciation.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddTextLimitToUserDetailsPronunciation < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :user_details, :pronunciation, 255
+ end
+
+ def down
+ remove_text_limit :user_details, :pronunciation
+ end
+end
diff --git a/db/migrate/20210729123101_confirm_security_bot.rb b/db/migrate/20210729123101_confirm_security_bot.rb
new file mode 100644
index 00000000000..2184cc4e193
--- /dev/null
+++ b/db/migrate/20210729123101_confirm_security_bot.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class ConfirmSecurityBot < ActiveRecord::Migration[6.0]
+ class User < ActiveRecord::Base
+ self.table_name = 'users'
+ SECURITY_BOT_TYPE = 8
+ end
+
+ def up
+ User.where(user_type: User::SECURITY_BOT_TYPE, confirmed_at: nil)
+ .update_all(confirmed_at: Time.current)
+ end
+
+ # no-op
+ # Security Bot should be always confirmed
+ def down
+ end
+end
diff --git a/db/migrate/20210729161242_remove_foreign_keys_from_ci_test_case_failures.rb b/db/migrate/20210729161242_remove_foreign_keys_from_ci_test_case_failures.rb
new file mode 100644
index 00000000000..2193a698272
--- /dev/null
+++ b/db/migrate/20210729161242_remove_foreign_keys_from_ci_test_case_failures.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeysFromCiTestCaseFailures < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ TABLE_NAME = :ci_test_case_failures
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(TABLE_NAME, column: :build_id)
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(TABLE_NAME, column: :test_case_id)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(TABLE_NAME, :ci_builds, column: :build_id, on_delete: :cascade)
+ add_concurrent_foreign_key(TABLE_NAME, :ci_test_cases, column: :test_case_id, on_delete: :cascade)
+ end
+end
diff --git a/db/migrate/20210729192148_remove_foreign_keys_from_ci_test_cases.rb b/db/migrate/20210729192148_remove_foreign_keys_from_ci_test_cases.rb
new file mode 100644
index 00000000000..1d0a5f4fd64
--- /dev/null
+++ b/db/migrate/20210729192148_remove_foreign_keys_from_ci_test_cases.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeysFromCiTestCases < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ TABLE_NAME = :ci_test_cases
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(TABLE_NAME, column: :project_id)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(TABLE_NAME, :projects, column: :project_id, on_delete: :cascade)
+ end
+end
diff --git a/db/migrate/20210729202143_create_incident_management_issuable_escalation_statuses.rb b/db/migrate/20210729202143_create_incident_management_issuable_escalation_statuses.rb
new file mode 100644
index 00000000000..b16904a3b47
--- /dev/null
+++ b/db/migrate/20210729202143_create_incident_management_issuable_escalation_statuses.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class CreateIncidentManagementIssuableEscalationStatuses < ActiveRecord::Migration[6.1]
+ ISSUE_IDX = 'index_uniq_im_issuable_escalation_statuses_on_issue_id'
+ POLICY_IDX = 'index_im_issuable_escalation_statuses_on_policy_id'
+
+ def change
+ create_table :incident_management_issuable_escalation_statuses do |t|
+ t.timestamps_with_timezone
+
+ t.references :issue, foreign_key: { on_delete: :cascade }, index: { unique: true, name: ISSUE_IDX }, null: false
+ t.references :policy, foreign_key: { to_table: :incident_management_escalation_policies, on_delete: :nullify }, index: { name: POLICY_IDX }
+
+ t.datetime_with_timezone :escalations_started_at
+ t.datetime_with_timezone :resolved_at
+
+ t.integer :status, default: 0, null: false, limit: 2
+ end
+ end
+end
diff --git a/db/migrate/20210730101609_create_analytics_cycle_analytics_stage_event_hashes.rb b/db/migrate/20210730101609_create_analytics_cycle_analytics_stage_event_hashes.rb
new file mode 100644
index 00000000000..ad517fbbff0
--- /dev/null
+++ b/db/migrate/20210730101609_create_analytics_cycle_analytics_stage_event_hashes.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class CreateAnalyticsCycleAnalyticsStageEventHashes < ActiveRecord::Migration[6.1]
+ def change
+ create_table :analytics_cycle_analytics_stage_event_hashes do |t|
+ t.binary :hash_sha256
+ t.index :hash_sha256, unique: true, name: 'index_cycle_analytics_stage_event_hashes_on_hash_sha_256'
+ end
+ end
+end
diff --git a/db/migrate/20210730102952_add_stage_hash_fk_to_project_stages.rb b/db/migrate/20210730102952_add_stage_hash_fk_to_project_stages.rb
new file mode 100644
index 00000000000..2909df78a6a
--- /dev/null
+++ b/db/migrate/20210730102952_add_stage_hash_fk_to_project_stages.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddStageHashFkToProjectStages < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ unless column_exists?(:analytics_cycle_analytics_project_stages, :stage_event_hash_id)
+ add_column :analytics_cycle_analytics_project_stages, :stage_event_hash_id, :bigint
+ end
+
+ add_concurrent_index :analytics_cycle_analytics_project_stages, :stage_event_hash_id, name: 'index_project_stages_on_stage_event_hash_id'
+ add_concurrent_foreign_key :analytics_cycle_analytics_project_stages, :analytics_cycle_analytics_stage_event_hashes, column: :stage_event_hash_id, on_delete: :cascade
+ end
+
+ def down
+ remove_column :analytics_cycle_analytics_project_stages, :stage_event_hash_id
+ end
+end
diff --git a/db/migrate/20210730103808_add_stage_hash_fk_to_group_stages.rb b/db/migrate/20210730103808_add_stage_hash_fk_to_group_stages.rb
new file mode 100644
index 00000000000..3cd53f2bb50
--- /dev/null
+++ b/db/migrate/20210730103808_add_stage_hash_fk_to_group_stages.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddStageHashFkToGroupStages < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ unless column_exists?(:analytics_cycle_analytics_group_stages, :stage_event_hash_id)
+ add_column :analytics_cycle_analytics_group_stages, :stage_event_hash_id, :bigint
+ end
+
+ add_concurrent_index :analytics_cycle_analytics_group_stages, :stage_event_hash_id, name: 'index_group_stages_on_stage_event_hash_id'
+ add_concurrent_foreign_key :analytics_cycle_analytics_group_stages, :analytics_cycle_analytics_stage_event_hashes, column: :stage_event_hash_id, on_delete: :cascade
+ end
+
+ def down
+ remove_column :analytics_cycle_analytics_group_stages, :stage_event_hash_id
+ end
+end
diff --git a/db/migrate/20210803110920_add_unique_index_to_vulnerability_flags_table.rb b/db/migrate/20210803110920_add_unique_index_to_vulnerability_flags_table.rb
new file mode 100644
index 00000000000..38d72496484
--- /dev/null
+++ b/db/migrate/20210803110920_add_unique_index_to_vulnerability_flags_table.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexToVulnerabilityFlagsTable < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_vulnerability_flags_on_unique_columns'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerability_flags, [:vulnerability_occurrence_id, :flag_type, :origin], name: INDEX_NAME, unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_flags, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210804150320_create_base_work_item_types.rb b/db/migrate/20210804150320_create_base_work_item_types.rb
new file mode 100644
index 00000000000..b7a44eaabe0
--- /dev/null
+++ b/db/migrate/20210804150320_create_base_work_item_types.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class CreateBaseWorkItemTypes < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ module WorkItem
+ class Type < ActiveRecord::Base
+ self.table_name = 'work_item_types'
+
+ enum base_type: {
+ issue: 0,
+ incident: 1,
+ test_case: 2,
+ requirement: 3
+ }
+
+ validates :name, uniqueness: { case_sensitive: false, scope: [:namespace_id] }
+ end
+ end
+
+ def up
+ # create default types
+ WorkItem::Type.create(name: 'Issue', namespace_id: nil, base_type: :issue, icon_name: 'issue-type-issue')
+ WorkItem::Type.create(name: 'Incident', namespace_id: nil, base_type: :incident, icon_name: 'issue-type-incident')
+ WorkItem::Type.create(name: 'Test Case', namespace_id: nil, base_type: :test_case, icon_name: 'issue-type-test-case')
+ WorkItem::Type.create(name: 'Requirement', namespace_id: nil, base_type: :requirement, icon_name: 'issue-type-requirements')
+ end
+
+ def down
+ # We expect this table to be empty at the point of the up migration,
+ # however there is a remote possibility that issues could already be
+ # using one of these types, with a tight foreign constraint.
+ # Therefore we will not attempt to remove any data.
+ end
+end
diff --git a/db/migrate/20210804200114_create_customer_relations_organizations.rb b/db/migrate/20210804200114_create_customer_relations_organizations.rb
new file mode 100644
index 00000000000..9936e97b9bf
--- /dev/null
+++ b/db/migrate/20210804200114_create_customer_relations_organizations.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class CreateCustomerRelationsOrganizations < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ create_table_with_constraints :customer_relations_organizations do |t|
+ t.references :group, index: false, null: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }
+ t.timestamps_with_timezone null: false
+ t.integer :state, limit: 1, default: 1, null: false
+ t.decimal :default_rate, precision: 18, scale: 2
+ t.text :name, null: false
+ t.text :description
+
+ t.text_limit :name, 255
+ t.text_limit :description, 1024
+
+ t.index 'group_id, LOWER(name)', unique: true, name: :index_customer_relations_organizations_on_unique_name_per_group
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :customer_relations_organizations
+ end
+ end
+end
diff --git a/db/migrate/20210804202057_add_tmp_index_approval_project_rules_scanners.rb b/db/migrate/20210804202057_add_tmp_index_approval_project_rules_scanners.rb
new file mode 100644
index 00000000000..66fcf485b2f
--- /dev/null
+++ b/db/migrate/20210804202057_add_tmp_index_approval_project_rules_scanners.rb
@@ -0,0 +1,20 @@
+# 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 AddTmpIndexApprovalProjectRulesScanners < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'tmp_index_approval_project_rules_scanners'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :approval_project_rules, :scanners, name: INDEX_NAME, using: :gin, where: "scanners @> '{cluster_image_scanning}'"
+ end
+
+ def down
+ remove_concurrent_index_by_name :approval_project_rules, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210805085706_add_rule_index_to_security_orchestration_policy_rule_schedules.rb b/db/migrate/20210805085706_add_rule_index_to_security_orchestration_policy_rule_schedules.rb
new file mode 100644
index 00000000000..ea77e29d365
--- /dev/null
+++ b/db/migrate/20210805085706_add_rule_index_to_security_orchestration_policy_rule_schedules.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddRuleIndexToSecurityOrchestrationPolicyRuleSchedules < ActiveRecord::Migration[6.1]
+ def change
+ add_column :security_orchestration_policy_rule_schedules, :rule_index, :integer, null: false, default: 0
+ end
+end
diff --git a/db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb b/db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb
new file mode 100644
index 00000000000..34f8ec43a8f
--- /dev/null
+++ b/db/migrate/20210806152104_add_pypi_package_requests_forwarding_to_application_settings.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddPypiPackageRequestsForwardingToApplicationSettings < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ add_column(:application_settings, :pypi_package_requests_forwarding, :boolean, default: true, null: false)
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column(:application_settings, :pypi_package_requests_forwarding)
+ end
+ end
+end
diff --git a/db/migrate/20210809194250_rename_tables_ci_build_trace_section.rb b/db/migrate/20210809194250_rename_tables_ci_build_trace_section.rb
new file mode 100644
index 00000000000..76308e2ea8e
--- /dev/null
+++ b/db/migrate/20210809194250_rename_tables_ci_build_trace_section.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class RenameTablesCiBuildTraceSection < ActiveRecord::Migration[6.1]
+ DOWNTIME = false
+
+ def change
+ # Shorten deprecated to dep to avoid 'Index name..too long'
+ rename_table(:ci_build_trace_sections, :dep_ci_build_trace_sections)
+ rename_table(:ci_build_trace_section_names, :dep_ci_build_trace_section_names)
+ end
+end
diff --git a/db/migrate/20210812171704_create_project_ci_feature_usages.rb b/db/migrate/20210812171704_create_project_ci_feature_usages.rb
new file mode 100644
index 00000000000..376512bcb44
--- /dev/null
+++ b/db/migrate/20210812171704_create_project_ci_feature_usages.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class CreateProjectCiFeatureUsages < ActiveRecord::Migration[6.1]
+ def change
+ create_table :project_ci_feature_usages do |t|
+ t.references :project, index: false, foreign_key: { on_delete: :cascade }, null: false
+ t.integer :feature, null: false, limit: 2
+ t.boolean :default_branch, default: false, null: false
+ t.index [:project_id, :feature, :default_branch], unique: true, name: 'index_project_ci_feature_usages_unique_columns'
+ end
+ end
+end
diff --git a/db/migrate/20210813101742_create_zentao_tracker_data.rb b/db/migrate/20210813101742_create_zentao_tracker_data.rb
new file mode 100644
index 00000000000..93d9cde3371
--- /dev/null
+++ b/db/migrate/20210813101742_create_zentao_tracker_data.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class CreateZentaoTrackerData < ActiveRecord::Migration[6.1]
+ def change
+ create_table :zentao_tracker_data do |t|
+ t.references :integration, foreign_key: { on_delete: :cascade }, type: :bigint, index: true, null: false
+ t.timestamps_with_timezone
+ t.binary :encrypted_url
+ t.binary :encrypted_url_iv
+ t.binary :encrypted_api_url
+ t.binary :encrypted_api_url_iv
+ t.binary :encrypted_zentao_product_xid
+ t.binary :encrypted_zentao_product_xid_iv
+ t.binary :encrypted_api_token
+ t.binary :encrypted_api_token_iv
+ end
+ end
+end
diff --git a/db/migrate/20210813111909_create_ci_build_trace_metadata.rb b/db/migrate/20210813111909_create_ci_build_trace_metadata.rb
new file mode 100644
index 00000000000..d8b7fd656e0
--- /dev/null
+++ b/db/migrate/20210813111909_create_ci_build_trace_metadata.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class CreateCiBuildTraceMetadata < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ create_table :ci_build_trace_metadata, id: false, if_not_exists: true do |t|
+ t.references :build,
+ index: false,
+ primary_key: true,
+ default: nil,
+ foreign_key: { to_table: :ci_builds, on_delete: :cascade },
+ type: :bigint,
+ null: false
+
+ t.bigint :trace_artifact_id
+ t.integer :archival_attempts, default: 0, null: false, limit: 2
+ t.binary :checksum
+ t.binary :remote_checksum
+
+ t.index :trace_artifact_id
+ end
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :ci_build_trace_metadata, if_exists: true
+ end
+ end
+end
diff --git a/db/migrate/20210816161107_remove_index_containing_faulty_regex.rb b/db/migrate/20210816161107_remove_index_containing_faulty_regex.rb
new file mode 100644
index 00000000000..d625ae6d13d
--- /dev/null
+++ b/db/migrate/20210816161107_remove_index_containing_faulty_regex.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveIndexContainingFaultyRegex < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = "tmp_index_merge_requests_draft_and_status"
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :merge_requests, INDEX_NAME
+ end
+
+ def down
+ # noop
+ #
+ end
+end
diff --git a/db/migrate/20210817084338_add_foreign_key_from_ci_build_metadata_to_ci_job_artifacts.rb b/db/migrate/20210817084338_add_foreign_key_from_ci_build_metadata_to_ci_job_artifacts.rb
new file mode 100644
index 00000000000..032b15234d8
--- /dev/null
+++ b/db/migrate/20210817084338_add_foreign_key_from_ci_build_metadata_to_ci_job_artifacts.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddForeignKeyFromCiBuildMetadataToCiJobArtifacts < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_build_trace_metadata,
+ :ci_job_artifacts,
+ column: :trace_artifact_id,
+ on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :ci_build_trace_metadata, column: :trace_artifact_id
+ end
+ end
+end
diff --git a/db/migrate/20210818034001_index_historical_data_on_recorded_at.rb b/db/migrate/20210818034001_index_historical_data_on_recorded_at.rb
new file mode 100644
index 00000000000..791c5b60e54
--- /dev/null
+++ b/db/migrate/20210818034001_index_historical_data_on_recorded_at.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class IndexHistoricalDataOnRecordedAt < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_historical_data_on_recorded_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :historical_data, :recorded_at, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :historical_data, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210818055357_add_unique_commit_design_user_mention_indexes.rb b/db/migrate/20210818055357_add_unique_commit_design_user_mention_indexes.rb
new file mode 100644
index 00000000000..d9d05f2b737
--- /dev/null
+++ b/db/migrate/20210818055357_add_unique_commit_design_user_mention_indexes.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class AddUniqueCommitDesignUserMentionIndexes < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ COMMIT_INDEX_NAME = 'commit_id_and_note_id_index'
+ DESIGN_INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_index'
+
+ COMMIT_UNIQUE_INDEX_NAME = 'commit_user_mentions_on_commit_id_and_note_id_unique_index'
+ DESIGN_UNIQUE_INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_unique_index'
+
+ def up
+ add_concurrent_index :commit_user_mentions, [:commit_id, :note_id], unique: true, name: COMMIT_UNIQUE_INDEX_NAME
+ add_concurrent_index :design_user_mentions, [:design_id, :note_id], unique: true, name: DESIGN_UNIQUE_INDEX_NAME
+
+ remove_concurrent_index_by_name :commit_user_mentions, COMMIT_INDEX_NAME
+ remove_concurrent_index_by_name :design_user_mentions, DESIGN_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :design_user_mentions, [:design_id, :note_id], name: DESIGN_INDEX_NAME
+ add_concurrent_index :commit_user_mentions, [:commit_id, :note_id], name: COMMIT_INDEX_NAME
+
+ remove_concurrent_index_by_name :design_user_mentions, DESIGN_UNIQUE_INDEX_NAME
+ remove_concurrent_index_by_name :commit_user_mentions, COMMIT_UNIQUE_INDEX_NAME
+ end
+end