summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20201029144444_create_vulnerability_finding_links.rb4
-rw-r--r--db/migrate/20210531053916_rename_instance_statistics_measurements.rb4
-rw-r--r--db/migrate/20210621043337_rename_services_to_integrations.rb5
-rw-r--r--db/migrate/20210707113056_add_tags_array_to_ci_pending_builds.rb17
-rw-r--r--db/migrate/20210707163659_add_vulnerability_events_to_integrations.rb9
-rw-r--r--db/migrate/20210708011425_rename_ci_builds_metadata_foreign_key.rb28
-rw-r--r--db/migrate/20210729081351_create_topics.rb16
-rw-r--r--db/migrate/20210729081739_create_project_topics.rb16
-rw-r--r--db/migrate/20210729125641_add_foreign_key_to_project_on_project_topic.rb17
-rw-r--r--db/migrate/20210729125659_add_foreign_key_to_topic_on_project_topic.rb17
-rw-r--r--db/migrate/20210730194555_create_incident_management_pending_issue_escalations.rb33
-rw-r--r--db/migrate/20210807101446_add_cadence_to_dast_profile_schedules.rb7
-rw-r--r--db/migrate/20210807101621_add_timezone_to_dast_profile_schedules.rb26
-rw-r--r--db/migrate/20210807102004_add_starts_at_to_dast_profile_schedules.rb7
-rw-r--r--db/migrate/20210809014850_create_agent_group_authorizations.rb16
-rw-r--r--db/migrate/20210809014918_add_agent_group_authorizations_foreign_keys.rb22
-rw-r--r--db/migrate/20210811120204_create_customer_relations_contacts.rb31
-rw-r--r--db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb22
-rw-r--r--db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb38
-rw-r--r--db/migrate/20210816192041_add_invites_email_success_to_member.rb13
-rw-r--r--db/migrate/20210817130415_add_project_id_name_version_id_to_npm_packages.rb17
-rw-r--r--db/migrate/20210817172214_add_yaml_limits_application_setting.rb10
-rw-r--r--db/migrate/20210818061156_remove_project_profile_compound_index_from_dast_profile_schedules.rb30
-rw-r--r--db/migrate/20210818115613_add_index_project_id_on_dast_profile_schedule.rb13
-rw-r--r--db/migrate/20210818175949_update_integrations_trigger_type_new_on_insert.rb79
-rw-r--r--db/migrate/20210818185548_add_tag_ids_index_to_ci_pending_build.rb17
-rw-r--r--db/migrate/20210818193008_add_file_template_project_to_service_desk_settings.rb9
-rw-r--r--db/migrate/20210818200455_add_file_template_project_foreign_key_to_service_desk_settings.rb22
-rw-r--r--db/migrate/20210818220234_add_default_project_approval_rules_vuln_allowed.rb24
-rw-r--r--db/migrate/20210819120243_add_throttle_files_api_columns.rb13
-rw-r--r--db/migrate/20210819152723_remove_tmp_index_approval_project_rules_scanners.rb17
-rw-r--r--db/migrate/20210819153805_set_default_job_token_scope_true.rb17
-rw-r--r--db/migrate/20210819162047_add_columns_to_namespace_settings.rb21
-rw-r--r--db/migrate/20210820171834_add_foreign_keys_for_pending_issue_escalations.rb22
-rw-r--r--db/migrate/20210823172643_create_user_group_callout.rb19
-rw-r--r--db/migrate/20210823213417_create_dependency_proxy_image_ttl_group_policies.rb22
-rw-r--r--db/migrate/20210824055322_add_project_namespace_id_to_project.rb21
-rw-r--r--db/migrate/20210824105038_add_timestamp_columns_to_ci_build_trace_metadata.rb8
-rw-r--r--db/migrate/20210824160459_add_notification_level_to_ci_namespace_monthly_usages.rb7
-rw-r--r--db/migrate/20210825104558_change_description_limit_error_tracking_event.rb17
-rw-r--r--db/migrate/20210825104656_create_analytics_cycle_analytics_merge_request_stage_events.rb28
-rw-r--r--db/migrate/20210825110016_create_analytics_cycle_analytics_issue_stage_events.rb28
-rw-r--r--db/migrate/20210825190458_add_user_deactivation_email_option_to_application_settings.rb10
-rw-r--r--db/migrate/20210825193448_add_iteration_cadence_id_to_issue_boards.rb9
-rw-r--r--db/migrate/20210826120834_add_locked_to_ci_job_artifacts.rb22
-rw-r--r--db/migrate/20210826122748_create_loose_foreign_keys_deleted_records.rb26
-rw-r--r--db/migrate/20210826124311_add_index_to_error_tracking_error.rb23
-rw-r--r--db/migrate/20210826145509_add_function_for_inserting_deleted_records.rb27
-rw-r--r--db/migrate/20210826170902_add_throttle_unauthenticated_api_columns.rb10
-rw-r--r--db/migrate/20210830085837_add_throttle_authenticated_git_lfs_columns.rb23
-rw-r--r--db/migrate/20210830140524_add_state_to_member.rb21
-rw-r--r--db/migrate/20210830154358_add_yaml_limit_constraints.rb25
-rw-r--r--db/migrate/20210831134840_add_package_file_id_channel_idx_to_packages_helm_file_metadata.rb17
-rw-r--r--db/migrate/20210831135249_add_installable_helm_pkgs_idx_to_packages.rb17
-rw-r--r--db/migrate/20210831203408_upsert_base_work_item_types.rb31
-rw-r--r--db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb17
-rw-r--r--db/migrate/20210902171406_add_latest_column_into_the_security_scans_table.rb13
-rw-r--r--db/migrate/20210902171808_set_default_job_token_scope_false.rb17
-rw-r--r--db/migrate/20210902184334_add_expire_access_tokens_to_doorkeeper_application.rb7
-rw-r--r--db/migrate/20210903054158_recreate_stage_issue_events_table_with_bigints.rb45
-rw-r--r--db/migrate/20210906100021_delete_project_namespace_trigger.rb31
-rw-r--r--db/migrate/20210907182337_add_group_id_fkey_for_user_group_callout.rb15
-rw-r--r--db/migrate/20210907182359_add_user_id_fkey_for_user_group_callout.rb15
-rw-r--r--db/migrate/20210908060951_add_dast_schedules_to_plan_limits.rb7
-rw-r--r--db/migrate/20210908061132_insert_dast_profile_schedules_plan_limits.rb27
-rw-r--r--db/migrate/20210908100810_add_jobs_per_stage_page_size_to_application_settings.rb7
-rw-r--r--db/migrate/20210908140437_add_sidekiq_limits_to_application_settings.rb21
-rw-r--r--db/migrate/20210908185736_add_status_to_dependency_proxy_manifests.rb7
-rw-r--r--db/migrate/20210908185754_add_status_to_dependency_proxy_blobs.rb7
-rw-r--r--db/migrate/20210909184349_add_index_package_id_id_on_package_files.rb17
-rw-r--r--db/migrate/20210910141043_change_ci_minutes_additional_pack_text_limit.rb15
-rw-r--r--db/migrate/20210913010411_create_agent_project_authorizations.rb14
-rw-r--r--db/migrate/20210913010432_add_agent_project_authorizations_foreign_keys.rb20
-rw-r--r--db/migrate/20210913122457_add_namespace_traversal_ids_to_ci_pending_builds.rb9
74 files changed, 1375 insertions, 6 deletions
diff --git a/db/migrate/20201029144444_create_vulnerability_finding_links.rb b/db/migrate/20201029144444_create_vulnerability_finding_links.rb
index 80f93b9a0af..225a2de6e19 100644
--- a/db/migrate/20201029144444_create_vulnerability_finding_links.rb
+++ b/db/migrate/20201029144444_create_vulnerability_finding_links.rb
@@ -11,8 +11,8 @@ class CreateVulnerabilityFindingLinks < ActiveRecord::Migration[6.0]
create_table :vulnerability_finding_links, if_not_exists: true do |t|
t.timestamps_with_timezone null: false
t.references :vulnerability_occurrence, index: { name: 'finding_links_on_vulnerability_occurrence_id' }, null: false, foreign_key: { on_delete: :cascade }
- t.text :name, limit: 255
- t.text :url, limit: 2048, null: false
+ t.text :name
+ t.text :url, null: false
end
add_text_limit :vulnerability_finding_links, :name, 255
diff --git a/db/migrate/20210531053916_rename_instance_statistics_measurements.rb b/db/migrate/20210531053916_rename_instance_statistics_measurements.rb
index 9fd459b1275..733ca296952 100644
--- a/db/migrate/20210531053916_rename_instance_statistics_measurements.rb
+++ b/db/migrate/20210531053916_rename_instance_statistics_measurements.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-class RenameInstanceStatisticsMeasurements < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
+class RenameInstanceStatisticsMeasurements < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
def up
rename_table_safely(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements)
diff --git a/db/migrate/20210621043337_rename_services_to_integrations.rb b/db/migrate/20210621043337_rename_services_to_integrations.rb
index 17f4b6a2d4d..845c3c01a2a 100644
--- a/db/migrate/20210621043337_rename_services_to_integrations.rb
+++ b/db/migrate/20210621043337_rename_services_to_integrations.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
-class RenameServicesToIntegrations < ActiveRecord::Migration[6.1]
- include Gitlab::Database::MigrationHelpers
+class RenameServicesToIntegrations < Gitlab::Database::Migration[1.0]
include Gitlab::Database::SchemaHelpers
+ enable_lock_retries!
+
# 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
diff --git a/db/migrate/20210707113056_add_tags_array_to_ci_pending_builds.rb b/db/migrate/20210707113056_add_tags_array_to_ci_pending_builds.rb
new file mode 100644
index 00000000000..229dc01fb87
--- /dev/null
+++ b/db/migrate/20210707113056_add_tags_array_to_ci_pending_builds.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddTagsArrayToCiPendingBuilds < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ add_column :ci_pending_builds, :tag_ids, :integer, array: true, default: []
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :ci_pending_builds, :tag_ids
+ end
+ end
+end
diff --git a/db/migrate/20210707163659_add_vulnerability_events_to_integrations.rb b/db/migrate/20210707163659_add_vulnerability_events_to_integrations.rb
new file mode 100644
index 00000000000..c138af486c1
--- /dev/null
+++ b/db/migrate/20210707163659_add_vulnerability_events_to_integrations.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddVulnerabilityEventsToIntegrations < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ add_column :integrations, :vulnerability_events, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20210708011425_rename_ci_builds_metadata_foreign_key.rb b/db/migrate/20210708011425_rename_ci_builds_metadata_foreign_key.rb
new file mode 100644
index 00000000000..70141f4844e
--- /dev/null
+++ b/db/migrate/20210708011425_rename_ci_builds_metadata_foreign_key.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class RenameCiBuildsMetadataForeignKey < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'ci_builds_metadata'
+ OLD_PREFIX = 'fk_rails_'
+
+ def up
+ with_lock_retries(raise_on_exhaustion: true) do
+ rename_constraint(
+ TABLE_NAME,
+ concurrent_foreign_key_name(TABLE_NAME, :build_id, prefix: 'fk_rails_'),
+ concurrent_foreign_key_name(TABLE_NAME, :build_id)
+ )
+ end
+ end
+
+ def down
+ with_lock_retries(raise_on_exhaustion: true) do
+ rename_constraint(
+ TABLE_NAME,
+ concurrent_foreign_key_name(TABLE_NAME, :build_id),
+ concurrent_foreign_key_name(TABLE_NAME, :build_id, prefix: 'fk_rails_')
+ )
+ end
+ end
+end
diff --git a/db/migrate/20210729081351_create_topics.rb b/db/migrate/20210729081351_create_topics.rb
new file mode 100644
index 00000000000..c6fdc6bb98a
--- /dev/null
+++ b/db/migrate/20210729081351_create_topics.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateTopics < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ create_table_with_constraints :topics do |t|
+ t.text :name, null: false
+ t.text_limit :name, 255
+
+ t.index :name, unique: true
+
+ t.timestamps_with_timezone
+ end
+ end
+end
diff --git a/db/migrate/20210729081739_create_project_topics.rb b/db/migrate/20210729081739_create_project_topics.rb
new file mode 100644
index 00000000000..cbb8842f653
--- /dev/null
+++ b/db/migrate/20210729081739_create_project_topics.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateProjectTopics < ActiveRecord::Migration[6.1]
+ def change
+ create_table :project_topics do |t|
+ t.bigint :project_id, null: false
+ t.bigint :topic_id, null: false
+
+ t.index :project_id
+ t.index :topic_id
+ t.index [:project_id, :topic_id], unique: true
+
+ t.timestamps_with_timezone
+ end
+ end
+end
diff --git a/db/migrate/20210729125641_add_foreign_key_to_project_on_project_topic.rb b/db/migrate/20210729125641_add_foreign_key_to_project_on_project_topic.rb
new file mode 100644
index 00000000000..27cf5c60cf0
--- /dev/null
+++ b/db/migrate/20210729125641_add_foreign_key_to_project_on_project_topic.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToProjectOnProjectTopic < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :project_topics, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :project_topics, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20210729125659_add_foreign_key_to_topic_on_project_topic.rb b/db/migrate/20210729125659_add_foreign_key_to_topic_on_project_topic.rb
new file mode 100644
index 00000000000..1ada08dca1a
--- /dev/null
+++ b/db/migrate/20210729125659_add_foreign_key_to_topic_on_project_topic.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToTopicOnProjectTopic < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :project_topics, :topics, column: :topic_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :project_topics, column: :topic_id
+ end
+ end
+end
diff --git a/db/migrate/20210730194555_create_incident_management_pending_issue_escalations.rb b/db/migrate/20210730194555_create_incident_management_pending_issue_escalations.rb
new file mode 100644
index 00000000000..20a6fde96ff
--- /dev/null
+++ b/db/migrate/20210730194555_create_incident_management_pending_issue_escalations.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class CreateIncidentManagementPendingIssueEscalations < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ execute(<<~SQL)
+ CREATE TABLE incident_management_pending_issue_escalations (
+ id bigserial NOT NULL,
+ rule_id bigint NOT NULL,
+ issue_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,
+ PRIMARY KEY (id, process_at)
+ ) PARTITION BY RANGE (process_at);
+
+ CREATE INDEX index_incident_management_pending_issue_escalations_on_issue_id
+ ON incident_management_pending_issue_escalations USING btree (issue_id);
+
+ CREATE INDEX index_incident_management_pending_issue_escalations_on_rule_id
+ ON incident_management_pending_issue_escalations USING btree (rule_id);
+ SQL
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :incident_management_pending_issue_escalations
+ end
+ end
+end
diff --git a/db/migrate/20210807101446_add_cadence_to_dast_profile_schedules.rb b/db/migrate/20210807101446_add_cadence_to_dast_profile_schedules.rb
new file mode 100644
index 00000000000..c9b17e3d5c5
--- /dev/null
+++ b/db/migrate/20210807101446_add_cadence_to_dast_profile_schedules.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddCadenceToDastProfileSchedules < ActiveRecord::Migration[6.1]
+ def change
+ add_column :dast_profile_schedules, :cadence, :jsonb, null: false, default: {}
+ end
+end
diff --git a/db/migrate/20210807101621_add_timezone_to_dast_profile_schedules.rb b/db/migrate/20210807101621_add_timezone_to_dast_profile_schedules.rb
new file mode 100644
index 00000000000..3c3eb507432
--- /dev/null
+++ b/db/migrate/20210807101621_add_timezone_to_dast_profile_schedules.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class AddTimezoneToDastProfileSchedules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ # We disable these cops here because adding the column is safe. The table does not
+ # have any data in it as it's behind a feature flag.
+ # rubocop: disable Rails/NotNullColumn
+ def up
+ execute('DELETE FROM dast_profile_schedules')
+
+ unless column_exists?(:dast_profile_schedules, :timezone)
+ add_column :dast_profile_schedules, :timezone, :text, null: false
+ end
+
+ add_text_limit :dast_profile_schedules, :timezone, 255
+ end
+
+ def down
+ return unless column_exists?(:dast_profile_schedules, :timezone)
+
+ remove_column :dast_profile_schedules, :timezone
+ end
+end
diff --git a/db/migrate/20210807102004_add_starts_at_to_dast_profile_schedules.rb b/db/migrate/20210807102004_add_starts_at_to_dast_profile_schedules.rb
new file mode 100644
index 00000000000..4eea5fd7e8c
--- /dev/null
+++ b/db/migrate/20210807102004_add_starts_at_to_dast_profile_schedules.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddStartsAtToDastProfileSchedules < ActiveRecord::Migration[6.1]
+ def change
+ add_column :dast_profile_schedules, :starts_at, :datetime_with_timezone, null: false, default: -> { 'NOW()' }
+ end
+end
diff --git a/db/migrate/20210809014850_create_agent_group_authorizations.rb b/db/migrate/20210809014850_create_agent_group_authorizations.rb
new file mode 100644
index 00000000000..43d7e63e0a2
--- /dev/null
+++ b/db/migrate/20210809014850_create_agent_group_authorizations.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateAgentGroupAuthorizations < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ create_table :agent_group_authorizations do |t|
+ t.bigint :group_id, null: false
+ t.bigint :agent_id, null: false
+ t.jsonb :config, null: false
+
+ t.index :group_id
+ t.index [:agent_id, :group_id], unique: true
+ end
+ end
+end
diff --git a/db/migrate/20210809014918_add_agent_group_authorizations_foreign_keys.rb b/db/migrate/20210809014918_add_agent_group_authorizations_foreign_keys.rb
new file mode 100644
index 00000000000..2a3a51d0ca9
--- /dev/null
+++ b/db/migrate/20210809014918_add_agent_group_authorizations_foreign_keys.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddAgentGroupAuthorizationsForeignKeys < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :agent_group_authorizations, :namespaces, column: :group_id
+ add_concurrent_foreign_key :agent_group_authorizations, :cluster_agents, column: :agent_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_group_authorizations, column: :group_id
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_group_authorizations, column: :agent_id
+ end
+ end
+end
diff --git a/db/migrate/20210811120204_create_customer_relations_contacts.rb b/db/migrate/20210811120204_create_customer_relations_contacts.rb
new file mode 100644
index 00000000000..0c26ee0ef59
--- /dev/null
+++ b/db/migrate/20210811120204_create_customer_relations_contacts.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class CreateCustomerRelationsContacts < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ create_table_with_constraints :customer_relations_contacts do |t|
+ t.bigint :group_id, null: false
+ t.references :organization, index: true, null: true, foreign_key: { to_table: :customer_relations_organizations, on_delete: :cascade }
+ t.timestamps_with_timezone null: false
+ t.integer :state, limit: 1, default: 1, null: false
+ t.text :phone
+ t.text :first_name, null: false
+ t.text :last_name, null: false
+ t.text :email
+ t.text :description
+
+ t.text_limit :phone, 32
+ t.text_limit :first_name, 255
+ t.text_limit :last_name, 255
+ t.text_limit :email, 255
+ t.text_limit :description, 1024
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :customer_relations_contacts
+ end
+ end
+end
diff --git a/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb b/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb
new file mode 100644
index 00000000000..58b2471a96a
--- /dev/null
+++ b/db/migrate/20210813131313_create_foreign_key_on_contacts_group_id.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class CreateForeignKeyOnContactsGroupId < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_customer_relations_contacts_on_group_id'
+
+ def up
+ add_concurrent_index :customer_relations_contacts, :group_id, name: INDEX_NAME
+ add_concurrent_foreign_key :customer_relations_contacts, :namespaces, column: :group_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :customer_relations_contacts, column: :group_id
+ end
+
+ remove_concurrent_index_by_name :customer_relations_contacts, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb b/db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb
new file mode 100644
index 00000000000..b7ea8545df1
--- /dev/null
+++ b/db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddUniqueIndexOnDastProfileToDastProfileSchedules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_dast_profile_schedules_on_dast_profile_id'
+ TABLE = :dast_profile_schedules
+ # We disable these cops here because changing this index is safe. The table does not
+ # have any data in it as it's behind a feature flag.
+ # rubocop: disable Migration/AddIndex
+ # rubocop: disable Migration/RemoveIndex
+ def up
+ execute('DELETE FROM dast_profile_schedules')
+
+ if index_exists_by_name?(TABLE, INDEX_NAME)
+ remove_index TABLE, :dast_profile_id, name: INDEX_NAME
+ end
+
+ unless index_exists_by_name?(TABLE, INDEX_NAME)
+ add_index TABLE, :dast_profile_id, unique: true, name: INDEX_NAME
+ end
+ end
+
+ def down
+ execute('DELETE FROM dast_profile_schedules')
+
+ if index_exists_by_name?(TABLE, INDEX_NAME)
+ remove_index TABLE, :dast_profile_id, name: INDEX_NAME
+ end
+
+ unless index_exists_by_name?(TABLE, INDEX_NAME)
+ add_index TABLE, :dast_profile_id
+ end
+ end
+end
diff --git a/db/migrate/20210816192041_add_invites_email_success_to_member.rb b/db/migrate/20210816192041_add_invites_email_success_to_member.rb
new file mode 100644
index 00000000000..89f475b056c
--- /dev/null
+++ b/db/migrate/20210816192041_add_invites_email_success_to_member.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddInvitesEmailSuccessToMember < ActiveRecord::Migration[6.1]
+ def up
+ unless column_exists?(:members, :invite_email_success)
+ add_column :members, :invite_email_success, :boolean, null: false, default: true
+ end
+ end
+
+ def down
+ remove_column :members, :invite_email_success
+ end
+end
diff --git a/db/migrate/20210817130415_add_project_id_name_version_id_to_npm_packages.rb b/db/migrate/20210817130415_add_project_id_name_version_id_to_npm_packages.rb
new file mode 100644
index 00000000000..e4b681d66fb
--- /dev/null
+++ b/db/migrate/20210817130415_add_project_id_name_version_id_to_npm_packages.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddProjectIdNameVersionIdToNpmPackages < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'idx_installable_npm_pkgs_on_project_id_name_version_id'
+
+ def up
+ add_concurrent_index :packages_packages, [:project_id, :name, :version, :id], where: 'package_type = 2 AND status = 0', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :packages_packages, [:project_id, :name, :version, :id], where: 'package_type = 2 AND status = 0', name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210817172214_add_yaml_limits_application_setting.rb b/db/migrate/20210817172214_add_yaml_limits_application_setting.rb
new file mode 100644
index 00000000000..f502ef9825b
--- /dev/null
+++ b/db/migrate/20210817172214_add_yaml_limits_application_setting.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddYamlLimitsApplicationSetting < ActiveRecord::Migration[6.1]
+ DOWNTIME = false
+
+ def change
+ add_column :application_settings, :max_yaml_size_bytes, :bigint, default: 1.megabyte, null: false
+ add_column :application_settings, :max_yaml_depth, :integer, default: 100, null: false
+ end
+end
diff --git a/db/migrate/20210818061156_remove_project_profile_compound_index_from_dast_profile_schedules.rb b/db/migrate/20210818061156_remove_project_profile_compound_index_from_dast_profile_schedules.rb
new file mode 100644
index 00000000000..b50947a0a99
--- /dev/null
+++ b/db/migrate/20210818061156_remove_project_profile_compound_index_from_dast_profile_schedules.rb
@@ -0,0 +1,30 @@
+# 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 RemoveProjectProfileCompoundIndexFromDastProfileSchedules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ TABLE = :dast_profile_schedules
+ INDEX_NAME = 'index_dast_profile_schedules_on_project_id_and_dast_profile_id'
+ # We disable these cops here because changing this index is safe. The table does not
+ # have any data in it as it's behind a feature flag.
+ # rubocop: disable Migration/AddIndex
+ # rubocop: disable Migration/RemoveIndex
+ def up
+ execute('DELETE FROM dast_profile_schedules')
+
+ if index_exists_by_name?(TABLE, INDEX_NAME)
+ remove_index TABLE, %i[project_id dast_profile_id], name: INDEX_NAME
+ end
+ end
+
+ def down
+ execute('DELETE FROM dast_profile_schedules')
+
+ unless index_exists_by_name?(TABLE, INDEX_NAME)
+ add_index TABLE, %i[project_id dast_profile_id], unique: true, name: INDEX_NAME
+ end
+ end
+end
diff --git a/db/migrate/20210818115613_add_index_project_id_on_dast_profile_schedule.rb b/db/migrate/20210818115613_add_index_project_id_on_dast_profile_schedule.rb
new file mode 100644
index 00000000000..392b335ab45
--- /dev/null
+++ b/db/migrate/20210818115613_add_index_project_id_on_dast_profile_schedule.rb
@@ -0,0 +1,13 @@
+# 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 AddIndexProjectIdOnDastProfileSchedule < ActiveRecord::Migration[6.1]
+ # We disable these cops here because changing this index is safe. The table does not
+ # have any data in it as it's behind a feature flag.
+ # rubocop: disable Migration/AddIndex
+ def change
+ add_index :dast_profile_schedules, :project_id
+ end
+end
diff --git a/db/migrate/20210818175949_update_integrations_trigger_type_new_on_insert.rb b/db/migrate/20210818175949_update_integrations_trigger_type_new_on_insert.rb
new file mode 100644
index 00000000000..2999a6fd4f6
--- /dev/null
+++ b/db/migrate/20210818175949_update_integrations_trigger_type_new_on_insert.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+class UpdateIntegrationsTriggerTypeNewOnInsert < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::SchemaHelpers
+
+ FUNCTION_NAME = 'integrations_set_type_new'
+
+ def up
+ # Update `type_new` dynamically based on `type`.
+ #
+ # The old class names are in the format `AbcService`, and the new ones `Integrations::Abc`.
+ create_trigger_function(FUNCTION_NAME, replace: true) do
+ <<~SQL
+ UPDATE integrations SET type_new = regexp_replace(NEW.type, '\\A(.+)Service\\Z', 'Integrations::\\1')
+ WHERE integrations.id = NEW.id;
+ RETURN NULL;
+ SQL
+ end
+ end
+
+ def down
+ # We initially went with this static mapping since we assumed that new integrations could
+ # just use the correct class name directly in `type`, but this will complicate the data migration
+ # since we plan to drop `type` at some point and replace it with `type_new`, so we still need
+ # to keep this column filled for all records.
+ create_trigger_function(FUNCTION_NAME, replace: true) do
+ <<~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
+ end
+end
diff --git a/db/migrate/20210818185548_add_tag_ids_index_to_ci_pending_build.rb b/db/migrate/20210818185548_add_tag_ids_index_to_ci_pending_build.rb
new file mode 100644
index 00000000000..b8e00ed9db0
--- /dev/null
+++ b/db/migrate/20210818185548_add_tag_ids_index_to_ci_pending_build.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddTagIdsIndexToCiPendingBuild < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_pending_builds_on_tag_ids'
+
+ def up
+ add_concurrent_index(:ci_pending_builds, :tag_ids, name: INDEX_NAME, where: 'cardinality(tag_ids) > 0')
+ end
+
+ def down
+ remove_concurrent_index_by_name(:ci_pending_builds, name: INDEX_NAME)
+ end
+end
diff --git a/db/migrate/20210818193008_add_file_template_project_to_service_desk_settings.rb b/db/migrate/20210818193008_add_file_template_project_to_service_desk_settings.rb
new file mode 100644
index 00000000000..4cfd54ac348
--- /dev/null
+++ b/db/migrate/20210818193008_add_file_template_project_to_service_desk_settings.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddFileTemplateProjectToServiceDeskSettings < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ add_column :service_desk_settings, :file_template_project_id, :bigint, null: true
+ end
+end
diff --git a/db/migrate/20210818200455_add_file_template_project_foreign_key_to_service_desk_settings.rb b/db/migrate/20210818200455_add_file_template_project_foreign_key_to_service_desk_settings.rb
new file mode 100644
index 00000000000..cc8aeecd2b5
--- /dev/null
+++ b/db/migrate/20210818200455_add_file_template_project_foreign_key_to_service_desk_settings.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddFileTemplateProjectForeignKeyToServiceDeskSettings < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_service_desk_settings_on_file_template_project_id'
+
+ def up
+ add_concurrent_index :service_desk_settings, :file_template_project_id, name: INDEX_NAME
+ add_concurrent_foreign_key :service_desk_settings, :projects, column: :file_template_project_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :service_desk_settings, column: :file_template_project_id
+ end
+
+ remove_concurrent_index_by_name :service_desk_settings, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210818220234_add_default_project_approval_rules_vuln_allowed.rb b/db/migrate/20210818220234_add_default_project_approval_rules_vuln_allowed.rb
new file mode 100644
index 00000000000..72d2755effa
--- /dev/null
+++ b/db/migrate/20210818220234_add_default_project_approval_rules_vuln_allowed.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AddDefaultProjectApprovalRulesVulnAllowed < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ DEFAULT_VALUE = 0
+
+ def up
+ change_column_default :approval_project_rules, :vulnerabilities_allowed, DEFAULT_VALUE
+
+ update_column_in_batches(:approval_project_rules, :vulnerabilities_allowed, DEFAULT_VALUE) do |table, query|
+ query.where(table[:vulnerabilities_allowed].eq(nil))
+ end
+
+ change_column_null :approval_project_rules, :vulnerabilities_allowed, false
+ end
+
+ def down
+ change_column_default :approval_project_rules, :vulnerabilities_allowed, nil
+ change_column_null :approval_project_rules, :vulnerabilities_allowed, true
+ end
+end
diff --git a/db/migrate/20210819120243_add_throttle_files_api_columns.rb b/db/migrate/20210819120243_add_throttle_files_api_columns.rb
new file mode 100644
index 00000000000..ace093c7b0c
--- /dev/null
+++ b/db/migrate/20210819120243_add_throttle_files_api_columns.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddThrottleFilesApiColumns < ActiveRecord::Migration[6.1]
+ def change
+ add_column :application_settings, :throttle_unauthenticated_files_api_requests_per_period, :integer, default: 125, null: false
+ add_column :application_settings, :throttle_unauthenticated_files_api_period_in_seconds, :integer, default: 15, null: false
+ add_column :application_settings, :throttle_authenticated_files_api_requests_per_period, :integer, default: 500, null: false
+ add_column :application_settings, :throttle_authenticated_files_api_period_in_seconds, :integer, default: 15, null: false
+
+ add_column :application_settings, :throttle_unauthenticated_files_api_enabled, :boolean, default: false, null: false
+ add_column :application_settings, :throttle_authenticated_files_api_enabled, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20210819152723_remove_tmp_index_approval_project_rules_scanners.rb b/db/migrate/20210819152723_remove_tmp_index_approval_project_rules_scanners.rb
new file mode 100644
index 00000000000..a60141991a6
--- /dev/null
+++ b/db/migrate/20210819152723_remove_tmp_index_approval_project_rules_scanners.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveTmpIndexApprovalProjectRulesScanners < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'tmp_index_approval_project_rules_scanners'
+
+ def up
+ remove_concurrent_index_by_name :approval_project_rules, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :approval_project_rules, :scanners, name: INDEX_NAME, using: :gin, where: "scanners @> '{cluster_image_scanning}'"
+ end
+end
diff --git a/db/migrate/20210819153805_set_default_job_token_scope_true.rb b/db/migrate/20210819153805_set_default_job_token_scope_true.rb
new file mode 100644
index 00000000000..4536f664950
--- /dev/null
+++ b/db/migrate/20210819153805_set_default_job_token_scope_true.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class SetDefaultJobTokenScopeTrue < 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/20210819162047_add_columns_to_namespace_settings.rb b/db/migrate/20210819162047_add_columns_to_namespace_settings.rb
new file mode 100644
index 00000000000..f617990582a
--- /dev/null
+++ b/db/migrate/20210819162047_add_columns_to_namespace_settings.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddColumnsToNamespaceSettings < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column :namespace_settings, :setup_for_company, :boolean
+ add_column :namespace_settings, :jobs_to_be_done, :smallint
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :namespace_settings, :setup_for_company
+ remove_column :namespace_settings, :jobs_to_be_done
+ end
+ end
+end
diff --git a/db/migrate/20210820171834_add_foreign_keys_for_pending_issue_escalations.rb b/db/migrate/20210820171834_add_foreign_keys_for_pending_issue_escalations.rb
new file mode 100644
index 00000000000..9d5322de498
--- /dev/null
+++ b/db/migrate/20210820171834_add_foreign_keys_for_pending_issue_escalations.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddForeignKeysForPendingIssueEscalations < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_partitioned_foreign_key :incident_management_pending_issue_escalations,
+ :incident_management_escalation_rules,
+ column: :rule_id
+
+ add_concurrent_partitioned_foreign_key :incident_management_pending_issue_escalations,
+ :issues,
+ column: :issue_id
+ end
+
+ def down
+ remove_foreign_key_if_exists :incident_management_pending_issue_escalations, :incident_management_escalation_rules, column: :rule_id
+ remove_foreign_key_if_exists :incident_management_pending_issue_escalations, :issues, column: :issue_id
+ end
+end
diff --git a/db/migrate/20210823172643_create_user_group_callout.rb b/db/migrate/20210823172643_create_user_group_callout.rb
new file mode 100644
index 00000000000..72341c0b275
--- /dev/null
+++ b/db/migrate/20210823172643_create_user_group_callout.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class CreateUserGroupCallout < ActiveRecord::Migration[6.1]
+ def up
+ create_table :user_group_callouts do |t|
+ t.bigint :user_id, null: false
+ t.bigint :group_id, null: false
+ t.integer :feature_name, limit: 2, null: false
+ t.datetime_with_timezone :dismissed_at
+
+ t.index :group_id
+ t.index [:user_id, :feature_name, :group_id], unique: true, name: 'index_group_user_callouts_feature'
+ end
+ end
+
+ def down
+ drop_table :user_group_callouts
+ end
+end
diff --git a/db/migrate/20210823213417_create_dependency_proxy_image_ttl_group_policies.rb b/db/migrate/20210823213417_create_dependency_proxy_image_ttl_group_policies.rb
new file mode 100644
index 00000000000..3bbd9c1259e
--- /dev/null
+++ b/db/migrate/20210823213417_create_dependency_proxy_image_ttl_group_policies.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class CreateDependencyProxyImageTtlGroupPolicies < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ with_lock_retries do
+ create_table :dependency_proxy_image_ttl_group_policies, id: false do |t|
+ t.timestamps_with_timezone null: false
+ t.references :group, primary_key: true, default: nil, index: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }
+ t.integer :ttl, default: 90
+ t.boolean :enabled, null: false, default: false
+ end
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :dependency_proxy_image_ttl_group_policies
+ end
+ end
+end
diff --git a/db/migrate/20210824055322_add_project_namespace_id_to_project.rb b/db/migrate/20210824055322_add_project_namespace_id_to_project.rb
new file mode 100644
index 00000000000..9397ad4aab2
--- /dev/null
+++ b/db/migrate/20210824055322_add_project_namespace_id_to_project.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddProjectNamespaceIdToProject < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ # This is being added to Projects as a replacement for Namespace
+ # See https://gitlab.com/gitlab-org/gitlab/-/issues/337099
+ add_column :projects, :project_namespace_id, :bigint # rubocop: disable Migration/AddColumnsToWideTables
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :projects, :project_namespace_id
+ end
+ end
+end
diff --git a/db/migrate/20210824105038_add_timestamp_columns_to_ci_build_trace_metadata.rb b/db/migrate/20210824105038_add_timestamp_columns_to_ci_build_trace_metadata.rb
new file mode 100644
index 00000000000..5c2391f68ed
--- /dev/null
+++ b/db/migrate/20210824105038_add_timestamp_columns_to_ci_build_trace_metadata.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class AddTimestampColumnsToCiBuildTraceMetadata < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :ci_build_trace_metadata, :last_archival_attempt_at, :datetime_with_timezone
+ add_column :ci_build_trace_metadata, :archived_at, :datetime_with_timezone
+ end
+end
diff --git a/db/migrate/20210824160459_add_notification_level_to_ci_namespace_monthly_usages.rb b/db/migrate/20210824160459_add_notification_level_to_ci_namespace_monthly_usages.rb
new file mode 100644
index 00000000000..15b580af737
--- /dev/null
+++ b/db/migrate/20210824160459_add_notification_level_to_ci_namespace_monthly_usages.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddNotificationLevelToCiNamespaceMonthlyUsages < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :ci_namespace_monthly_usages, :notification_level, :integer, limit: 2, default: 100, null: false
+ end
+end
diff --git a/db/migrate/20210825104558_change_description_limit_error_tracking_event.rb b/db/migrate/20210825104558_change_description_limit_error_tracking_event.rb
new file mode 100644
index 00000000000..4663cc513da
--- /dev/null
+++ b/db/migrate/20210825104558_change_description_limit_error_tracking_event.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class ChangeDescriptionLimitErrorTrackingEvent < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ remove_text_limit :error_tracking_error_events, :description
+ add_text_limit :error_tracking_error_events, :description, 1024
+ end
+
+ def down
+ remove_text_limit :error_tracking_error_events, :description
+ add_text_limit :error_tracking_error_events, :description, 255
+ end
+end
diff --git a/db/migrate/20210825104656_create_analytics_cycle_analytics_merge_request_stage_events.rb b/db/migrate/20210825104656_create_analytics_cycle_analytics_merge_request_stage_events.rb
new file mode 100644
index 00000000000..2e89dfeacbf
--- /dev/null
+++ b/db/migrate/20210825104656_create_analytics_cycle_analytics_merge_request_stage_events.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CreateAnalyticsCycleAnalyticsMergeRequestStageEvents < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ execute <<~SQL
+ CREATE TABLE analytics_cycle_analytics_merge_request_stage_events (
+ stage_event_hash_id bigint NOT NULL,
+ merge_request_id bigint NOT NULL,
+ group_id bigint NOT NULL,
+ project_id bigint NOT NULL,
+ milestone_id bigint,
+ author_id bigint,
+ start_event_timestamp timestamp with time zone NOT NULL,
+ end_event_timestamp timestamp with time zone,
+ PRIMARY KEY (stage_event_hash_id, merge_request_id)
+ ) PARTITION BY HASH (stage_event_hash_id)
+ SQL
+
+ create_hash_partitions :analytics_cycle_analytics_merge_request_stage_events, 32
+ end
+
+ def down
+ drop_table :analytics_cycle_analytics_merge_request_stage_events
+ end
+end
diff --git a/db/migrate/20210825110016_create_analytics_cycle_analytics_issue_stage_events.rb b/db/migrate/20210825110016_create_analytics_cycle_analytics_issue_stage_events.rb
new file mode 100644
index 00000000000..acc1d96bd23
--- /dev/null
+++ b/db/migrate/20210825110016_create_analytics_cycle_analytics_issue_stage_events.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CreateAnalyticsCycleAnalyticsIssueStageEvents < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ execute <<~SQL
+ CREATE TABLE analytics_cycle_analytics_issue_stage_events (
+ stage_event_hash_id integer NOT NULL,
+ issue_id integer NOT NULL,
+ group_id integer NOT NULL,
+ project_id integer NOT NULL,
+ milestone_id integer,
+ author_id integer,
+ start_event_timestamp timestamp with time zone NOT NULL,
+ end_event_timestamp timestamp with time zone,
+ PRIMARY KEY (stage_event_hash_id, issue_id)
+ ) PARTITION BY HASH (stage_event_hash_id)
+ SQL
+
+ create_hash_partitions :analytics_cycle_analytics_issue_stage_events, 32
+ end
+
+ def down
+ drop_table :analytics_cycle_analytics_issue_stage_events
+ end
+end
diff --git a/db/migrate/20210825190458_add_user_deactivation_email_option_to_application_settings.rb b/db/migrate/20210825190458_add_user_deactivation_email_option_to_application_settings.rb
new file mode 100644
index 00000000000..dc3270dc5a7
--- /dev/null
+++ b/db/migrate/20210825190458_add_user_deactivation_email_option_to_application_settings.rb
@@ -0,0 +1,10 @@
+# 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 AddUserDeactivationEmailOptionToApplicationSettings < ActiveRecord::Migration[6.1]
+ def change
+ add_column :application_settings, :user_deactivation_emails_enabled, :boolean, default: true, null: false
+ end
+end
diff --git a/db/migrate/20210825193448_add_iteration_cadence_id_to_issue_boards.rb b/db/migrate/20210825193448_add_iteration_cadence_id_to_issue_boards.rb
new file mode 100644
index 00000000000..cbe7d08894e
--- /dev/null
+++ b/db/migrate/20210825193448_add_iteration_cadence_id_to_issue_boards.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddIterationCadenceIdToIssueBoards < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def change
+ add_column :boards, :iteration_cadence_id, :bigint
+ end
+end
diff --git a/db/migrate/20210826120834_add_locked_to_ci_job_artifacts.rb b/db/migrate/20210826120834_add_locked_to_ci_job_artifacts.rb
new file mode 100644
index 00000000000..2149265b4e7
--- /dev/null
+++ b/db/migrate/20210826120834_add_locked_to_ci_job_artifacts.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddLockedToCiJobArtifacts < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'ci_job_artifacts'
+ COLUMN_NAME = 'locked'
+
+ def up
+ with_lock_retries do
+ add_column TABLE_NAME, COLUMN_NAME, :smallint, default: 2
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column TABLE_NAME, COLUMN_NAME
+ end
+ end
+end
diff --git a/db/migrate/20210826122748_create_loose_foreign_keys_deleted_records.rb b/db/migrate/20210826122748_create_loose_foreign_keys_deleted_records.rb
new file mode 100644
index 00000000000..5abea4393b4
--- /dev/null
+++ b/db/migrate/20210826122748_create_loose_foreign_keys_deleted_records.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class CreateLooseForeignKeysDeletedRecords < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ def up
+ constraint_name = check_constraint_name('loose_foreign_keys_deleted_records', 'deleted_table_name', 'max_length')
+ execute(<<~SQL)
+ CREATE TABLE loose_foreign_keys_deleted_records (
+ created_at timestamp with time zone NOT NULL DEFAULT NOW(),
+ deleted_table_name text NOT NULL,
+ deleted_table_primary_key_value bigint NOT NULL,
+ PRIMARY KEY (created_at, deleted_table_name, deleted_table_primary_key_value),
+ CONSTRAINT #{constraint_name} CHECK ((char_length(deleted_table_name) <= 63))
+ ) PARTITION BY RANGE (created_at);
+ SQL
+
+ min_date = Date.today - 1.month
+ max_date = Date.today + 3.months
+ create_daterange_partitions('loose_foreign_keys_deleted_records', 'created_at', min_date, max_date)
+ end
+
+ def down
+ drop_table :loose_foreign_keys_deleted_records
+ end
+end
diff --git a/db/migrate/20210826124311_add_index_to_error_tracking_error.rb b/db/migrate/20210826124311_add_index_to_error_tracking_error.rb
new file mode 100644
index 00000000000..5973331e487
--- /dev/null
+++ b/db/migrate/20210826124311_add_index_to_error_tracking_error.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddIndexToErrorTrackingError < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :error_tracking_errors, [:project_id, :status, :last_seen_at], name: 'index_et_errors_on_project_id_and_status_and_last_seen_at'
+ add_concurrent_index :error_tracking_errors, [:project_id, :status, :first_seen_at], name: 'index_et_errors_on_project_id_and_status_and_first_seen_at'
+ add_concurrent_index :error_tracking_errors, [:project_id, :status, :events_count], name: 'index_et_errors_on_project_id_and_status_and_events_count'
+ add_concurrent_index :error_tracking_errors, [:project_id, :status, :id], name: 'index_et_errors_on_project_id_and_status_and_id'
+ end
+
+ def down
+ remove_concurrent_index :error_tracking_errors, [:project_id, :status, :last_seen_at], name: 'index_et_errors_on_project_id_and_status_and_last_seen_at'
+ remove_concurrent_index :error_tracking_errors, [:project_id, :status, :first_seen_at], name: 'index_et_errors_on_project_id_and_status_and_first_seen_at'
+ remove_concurrent_index :error_tracking_errors, [:project_id, :status, :events_count], name: 'index_et_errors_on_project_id_and_status_and_events_count'
+ remove_concurrent_index :error_tracking_errors, [:project_id, :status, :id], name: 'index_et_errors_on_project_id_and_status_and_id'
+ end
+end
diff --git a/db/migrate/20210826145509_add_function_for_inserting_deleted_records.rb b/db/migrate/20210826145509_add_function_for_inserting_deleted_records.rb
new file mode 100644
index 00000000000..ef688cdfd8c
--- /dev/null
+++ b/db/migrate/20210826145509_add_function_for_inserting_deleted_records.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class AddFunctionForInsertingDeletedRecords < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+ include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
+
+ def up
+ execute(<<~SQL)
+ CREATE FUNCTION #{DELETED_RECORDS_INSERT_FUNCTION_NAME}()
+ RETURNS TRIGGER AS
+ $$
+ BEGIN
+ INSERT INTO loose_foreign_keys_deleted_records
+ (deleted_table_name, deleted_table_primary_key_value)
+ SELECT TG_TABLE_NAME, old_table.id FROM old_table
+ ON CONFLICT DO NOTHING;
+
+ RETURN NULL;
+ END
+ $$ LANGUAGE PLPGSQL
+ SQL
+ end
+
+ def down
+ drop_function(DELETED_RECORDS_INSERT_FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20210826170902_add_throttle_unauthenticated_api_columns.rb b/db/migrate/20210826170902_add_throttle_unauthenticated_api_columns.rb
new file mode 100644
index 00000000000..675da2ea41c
--- /dev/null
+++ b/db/migrate/20210826170902_add_throttle_unauthenticated_api_columns.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddThrottleUnauthenticatedApiColumns < ActiveRecord::Migration[6.1]
+ def change
+ # The defaults match those from the current `throttle_unauthenticated_*` columns
+ add_column :application_settings, :throttle_unauthenticated_api_enabled, :boolean, default: false, null: false
+ add_column :application_settings, :throttle_unauthenticated_api_requests_per_period, :integer, default: 3600, null: false
+ add_column :application_settings, :throttle_unauthenticated_api_period_in_seconds, :integer, default: 3600, null: false
+ end
+end
diff --git a/db/migrate/20210830085837_add_throttle_authenticated_git_lfs_columns.rb b/db/migrate/20210830085837_add_throttle_authenticated_git_lfs_columns.rb
new file mode 100644
index 00000000000..bc515bc061c
--- /dev/null
+++ b/db/migrate/20210830085837_add_throttle_authenticated_git_lfs_columns.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddThrottleAuthenticatedGitLfsColumns < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column :application_settings, :throttle_authenticated_git_lfs_requests_per_period, :integer, default: 1000, null: false
+ add_column :application_settings, :throttle_authenticated_git_lfs_period_in_seconds, :integer, default: 60, null: false
+ add_column :application_settings, :throttle_authenticated_git_lfs_enabled, :boolean, default: false, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :application_settings, :throttle_authenticated_git_lfs_requests_per_period
+ remove_column :application_settings, :throttle_authenticated_git_lfs_period_in_seconds
+ remove_column :application_settings, :throttle_authenticated_git_lfs_enabled, :boolean
+ end
+ end
+end
diff --git a/db/migrate/20210830140524_add_state_to_member.rb b/db/migrate/20210830140524_add_state_to_member.rb
new file mode 100644
index 00000000000..6009376badb
--- /dev/null
+++ b/db/migrate/20210830140524_add_state_to_member.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddStateToMember < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ unless column_exists?(:members, :state)
+ with_lock_retries do
+ add_column :members, :state, :integer, limit: 2, default: 0
+ end
+ end
+ end
+
+ def down
+ if column_exists?(:members, :state)
+ with_lock_retries do
+ remove_column :members, :state
+ end
+ end
+ end
+end
diff --git a/db/migrate/20210830154358_add_yaml_limit_constraints.rb b/db/migrate/20210830154358_add_yaml_limit_constraints.rb
new file mode 100644
index 00000000000..74236993fff
--- /dev/null
+++ b/db/migrate/20210830154358_add_yaml_limit_constraints.rb
@@ -0,0 +1,25 @@
+# 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 AddYamlLimitConstraints < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ SIZE_CONSTRAINT_NAME = 'app_settings_yaml_max_size_positive'
+ DEPTH_CONSTRAINT_NAME = 'app_settings_yaml_max_depth_positive'
+
+ disable_ddl_transaction!
+
+ def up
+ add_check_constraint :application_settings, 'max_yaml_size_bytes > 0', SIZE_CONSTRAINT_NAME
+ add_check_constraint :application_settings, 'max_yaml_depth > 0', DEPTH_CONSTRAINT_NAME
+ end
+
+ def down
+ remove_check_constraint :application_settings, SIZE_CONSTRAINT_NAME
+ remove_check_constraint :application_settings, DEPTH_CONSTRAINT_NAME
+ end
+end
diff --git a/db/migrate/20210831134840_add_package_file_id_channel_idx_to_packages_helm_file_metadata.rb b/db/migrate/20210831134840_add_package_file_id_channel_idx_to_packages_helm_file_metadata.rb
new file mode 100644
index 00000000000..a3366bd9ddb
--- /dev/null
+++ b/db/migrate/20210831134840_add_package_file_id_channel_idx_to_packages_helm_file_metadata.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddPackageFileIdChannelIdxToPackagesHelmFileMetadata < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_packages_helm_file_metadata_on_pf_id_and_channel'
+
+ def up
+ add_concurrent_index :packages_helm_file_metadata, [:package_file_id, :channel], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :packages_helm_file_metadata, [:package_file_id, :channel], name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210831135249_add_installable_helm_pkgs_idx_to_packages.rb b/db/migrate/20210831135249_add_installable_helm_pkgs_idx_to_packages.rb
new file mode 100644
index 00000000000..5e65b5c0fe1
--- /dev/null
+++ b/db/migrate/20210831135249_add_installable_helm_pkgs_idx_to_packages.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddInstallableHelmPkgsIdxToPackages < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'idx_installable_helm_pkgs_on_project_id_id'
+
+ def up
+ add_concurrent_index :packages_packages, [:project_id, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :packages_packages, [:project_id, :id], name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210831203408_upsert_base_work_item_types.rb b/db/migrate/20210831203408_upsert_base_work_item_types.rb
new file mode 100644
index 00000000000..314412d8d3d
--- /dev/null
+++ b/db/migrate/20210831203408_upsert_base_work_item_types.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class UpsertBaseWorkItemTypes < ActiveRecord::Migration[6.1]
+ module WorkItem
+ class Type < ActiveRecord::Base
+ self.table_name = 'work_item_types'
+
+ enum base_type: {
+ issue: 0,
+ incident: 1,
+ test_case: 2,
+ requirement: 3
+ }
+ end
+ end
+
+ def up
+ # upsert default types
+ WorkItem::Type.find_or_create_by(name: 'Issue', namespace_id: nil, base_type: :issue, icon_name: 'issue-type-issue')
+ WorkItem::Type.find_or_create_by(name: 'Incident', namespace_id: nil, base_type: :incident, icon_name: 'issue-type-incident')
+ WorkItem::Type.find_or_create_by(name: 'Test Case', namespace_id: nil, base_type: :test_case, icon_name: 'issue-type-test-case')
+ WorkItem::Type.find_or_create_by(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/20210901065504_add_index_on_name_and_id_to_public_groups.rb b/db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb
new file mode 100644
index 00000000000..77b9e5297a7
--- /dev/null
+++ b/db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexOnNameAndIdToPublicGroups < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_namespaces_public_groups_name_id'
+ PUBLIC_VISIBILITY_LEVEL = 20
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :namespaces, [:name, :id], name: INDEX_NAME,
+ where: "type = 'Group' AND visibility_level = #{PUBLIC_VISIBILITY_LEVEL}"
+ end
+
+ def down
+ remove_concurrent_index_by_name :namespaces, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210902171406_add_latest_column_into_the_security_scans_table.rb b/db/migrate/20210902171406_add_latest_column_into_the_security_scans_table.rb
new file mode 100644
index 00000000000..3c022cbaf5e
--- /dev/null
+++ b/db/migrate/20210902171406_add_latest_column_into_the_security_scans_table.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddLatestColumnIntoTheSecurityScansTable < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def up
+ add_column :security_scans, :latest, :boolean, default: true, null: false
+ end
+
+ def down
+ remove_column :security_scans, :latest
+ end
+end
diff --git a/db/migrate/20210902171808_set_default_job_token_scope_false.rb b/db/migrate/20210902171808_set_default_job_token_scope_false.rb
new file mode 100644
index 00000000000..0680382094f
--- /dev/null
+++ b/db/migrate/20210902171808_set_default_job_token_scope_false.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class SetDefaultJobTokenScopeFalse < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ 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
diff --git a/db/migrate/20210902184334_add_expire_access_tokens_to_doorkeeper_application.rb b/db/migrate/20210902184334_add_expire_access_tokens_to_doorkeeper_application.rb
new file mode 100644
index 00000000000..4638637331d
--- /dev/null
+++ b/db/migrate/20210902184334_add_expire_access_tokens_to_doorkeeper_application.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddExpireAccessTokensToDoorkeeperApplication < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :oauth_applications, :expire_access_tokens, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20210903054158_recreate_stage_issue_events_table_with_bigints.rb b/db/migrate/20210903054158_recreate_stage_issue_events_table_with_bigints.rb
new file mode 100644
index 00000000000..6c5d23d8703
--- /dev/null
+++ b/db/migrate/20210903054158_recreate_stage_issue_events_table_with_bigints.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class RecreateStageIssueEventsTableWithBigints < Gitlab::Database::Migration[1.0]
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ def up
+ drop_table :analytics_cycle_analytics_issue_stage_events # rubocop:disable Migration/DropTable
+
+ execute <<~SQL
+ CREATE TABLE analytics_cycle_analytics_issue_stage_events (
+ stage_event_hash_id bigint NOT NULL,
+ issue_id bigint NOT NULL,
+ group_id bigint NOT NULL,
+ project_id bigint NOT NULL,
+ milestone_id bigint,
+ author_id bigint,
+ start_event_timestamp timestamp with time zone NOT NULL,
+ end_event_timestamp timestamp with time zone,
+ PRIMARY KEY (stage_event_hash_id, issue_id)
+ ) PARTITION BY HASH (stage_event_hash_id)
+ SQL
+
+ create_hash_partitions :analytics_cycle_analytics_issue_stage_events, 32
+ end
+
+ def down
+ drop_table :analytics_cycle_analytics_issue_stage_events
+
+ execute <<~SQL
+ CREATE TABLE analytics_cycle_analytics_issue_stage_events (
+ stage_event_hash_id integer NOT NULL,
+ issue_id integer NOT NULL,
+ group_id integer NOT NULL,
+ project_id integer NOT NULL,
+ milestone_id integer,
+ author_id integer,
+ start_event_timestamp timestamp with time zone NOT NULL,
+ end_event_timestamp timestamp with time zone,
+ PRIMARY KEY (stage_event_hash_id, issue_id)
+ ) PARTITION BY HASH (stage_event_hash_id)
+ SQL
+
+ create_hash_partitions :analytics_cycle_analytics_issue_stage_events, 32
+ end
+end
diff --git a/db/migrate/20210906100021_delete_project_namespace_trigger.rb b/db/migrate/20210906100021_delete_project_namespace_trigger.rb
new file mode 100644
index 00000000000..ce68cf7d6d4
--- /dev/null
+++ b/db/migrate/20210906100021_delete_project_namespace_trigger.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class DeleteProjectNamespaceTrigger < Gitlab::Database::Migration[1.0]
+ include Gitlab::Database::SchemaHelpers
+
+ TRIGGER_NAME = "trigger_delete_project_namespace_on_project_delete"
+ FUNCTION_NAME = 'delete_associated_project_namespace'
+
+ def up
+ create_trigger_function(FUNCTION_NAME, replace: true) do
+ <<~SQL
+ DELETE FROM namespaces
+ WHERE namespaces.id = OLD.project_namespace_id AND
+ namespaces.type = 'Project';
+ RETURN NULL;
+ SQL
+ end
+
+ execute(<<~SQL.squish)
+ CREATE TRIGGER #{TRIGGER_NAME}
+ AFTER DELETE ON projects FOR EACH ROW
+ WHEN (OLD.project_namespace_id IS NOT NULL)
+ EXECUTE FUNCTION #{FUNCTION_NAME}();
+ SQL
+ end
+
+ def down
+ drop_trigger(:projects, TRIGGER_NAME)
+ drop_function(FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20210907182337_add_group_id_fkey_for_user_group_callout.rb b/db/migrate/20210907182337_add_group_id_fkey_for_user_group_callout.rb
new file mode 100644
index 00000000000..540344bd761
--- /dev/null
+++ b/db/migrate/20210907182337_add_group_id_fkey_for_user_group_callout.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddGroupIdFkeyForUserGroupCallout < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :user_group_callouts, :namespaces, column: :group_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :user_group_callouts, column: :group_id
+ end
+ end
+end
diff --git a/db/migrate/20210907182359_add_user_id_fkey_for_user_group_callout.rb b/db/migrate/20210907182359_add_user_id_fkey_for_user_group_callout.rb
new file mode 100644
index 00000000000..37b73335933
--- /dev/null
+++ b/db/migrate/20210907182359_add_user_id_fkey_for_user_group_callout.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddUserIdFkeyForUserGroupCallout < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :user_group_callouts, :users, column: :user_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :user_group_callouts, column: :user_id
+ end
+ end
+end
diff --git a/db/migrate/20210908060951_add_dast_schedules_to_plan_limits.rb b/db/migrate/20210908060951_add_dast_schedules_to_plan_limits.rb
new file mode 100644
index 00000000000..85c7522d006
--- /dev/null
+++ b/db/migrate/20210908060951_add_dast_schedules_to_plan_limits.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddDastSchedulesToPlanLimits < Gitlab::Database::Migration[1.0]
+ def change
+ add_column(:plan_limits, :dast_profile_schedules, :integer, default: 1, null: false)
+ end
+end
diff --git a/db/migrate/20210908061132_insert_dast_profile_schedules_plan_limits.rb b/db/migrate/20210908061132_insert_dast_profile_schedules_plan_limits.rb
new file mode 100644
index 00000000000..b9980f65c98
--- /dev/null
+++ b/db/migrate/20210908061132_insert_dast_profile_schedules_plan_limits.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class InsertDastProfileSchedulesPlanLimits < Gitlab::Database::Migration[1.0]
+ def up
+ create_or_update_plan_limit('dast_profile_schedules', 'default', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'free', 1)
+ create_or_update_plan_limit('dast_profile_schedules', 'bronze', 1)
+ create_or_update_plan_limit('dast_profile_schedules', 'silver', 1)
+ create_or_update_plan_limit('dast_profile_schedules', 'premium', 1)
+ create_or_update_plan_limit('dast_profile_schedules', 'premium_trial', 1)
+ create_or_update_plan_limit('dast_profile_schedules', 'gold', 20)
+ create_or_update_plan_limit('dast_profile_schedules', 'ultimate', 20)
+ create_or_update_plan_limit('dast_profile_schedules', 'ultimate_trial', 20)
+ end
+
+ def down
+ create_or_update_plan_limit('dast_profile_schedules', 'default', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'free', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'bronze', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'silver', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'premium', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'premium_trial', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'gold', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'ultimate', 0)
+ create_or_update_plan_limit('dast_profile_schedules', 'ultimate_trial', 0)
+ end
+end
diff --git a/db/migrate/20210908100810_add_jobs_per_stage_page_size_to_application_settings.rb b/db/migrate/20210908100810_add_jobs_per_stage_page_size_to_application_settings.rb
new file mode 100644
index 00000000000..81a76ecb10a
--- /dev/null
+++ b/db/migrate/20210908100810_add_jobs_per_stage_page_size_to_application_settings.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddJobsPerStagePageSizeToApplicationSettings < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :application_settings, :jobs_per_stage_page_size, :integer, default: 200, null: false
+ end
+end
diff --git a/db/migrate/20210908140437_add_sidekiq_limits_to_application_settings.rb b/db/migrate/20210908140437_add_sidekiq_limits_to_application_settings.rb
new file mode 100644
index 00000000000..dd0796a1c86
--- /dev/null
+++ b/db/migrate/20210908140437_add_sidekiq_limits_to_application_settings.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddSidekiqLimitsToApplicationSettings < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction! # needed for now to avoid subtransactions
+
+ def up
+ with_lock_retries do
+ add_column :application_settings, :sidekiq_job_limiter_mode, :smallint, default: 1, null: false
+ add_column :application_settings, :sidekiq_job_limiter_compression_threshold_bytes, :integer, default: 100_000, null: false
+ add_column :application_settings, :sidekiq_job_limiter_limit_bytes, :integer, default: 0, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :application_settings, :sidekiq_job_limiter_mode
+ remove_column :application_settings, :sidekiq_job_limiter_compression_threshold_bytes
+ remove_column :application_settings, :sidekiq_job_limiter_limit_bytes
+ end
+ end
+end
diff --git a/db/migrate/20210908185736_add_status_to_dependency_proxy_manifests.rb b/db/migrate/20210908185736_add_status_to_dependency_proxy_manifests.rb
new file mode 100644
index 00000000000..b8e7c7af144
--- /dev/null
+++ b/db/migrate/20210908185736_add_status_to_dependency_proxy_manifests.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddStatusToDependencyProxyManifests < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :dependency_proxy_manifests, :status, :smallint, default: 0, null: false
+ end
+end
diff --git a/db/migrate/20210908185754_add_status_to_dependency_proxy_blobs.rb b/db/migrate/20210908185754_add_status_to_dependency_proxy_blobs.rb
new file mode 100644
index 00000000000..4fbdcad33cd
--- /dev/null
+++ b/db/migrate/20210908185754_add_status_to_dependency_proxy_blobs.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddStatusToDependencyProxyBlobs < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :dependency_proxy_blobs, :status, :smallint, default: 0, null: false
+ end
+end
diff --git a/db/migrate/20210909184349_add_index_package_id_id_on_package_files.rb b/db/migrate/20210909184349_add_index_package_id_id_on_package_files.rb
new file mode 100644
index 00000000000..38d9c4b5dd9
--- /dev/null
+++ b/db/migrate/20210909184349_add_index_package_id_id_on_package_files.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexPackageIdIdOnPackageFiles < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_packages_package_files_on_package_id_id'
+
+ def up
+ disable_statement_timeout do
+ execute "CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON packages_package_files (package_id, id)" unless index_exists_by_name?(:package_package_files, INDEX_NAME)
+ end
+ end
+
+ def down
+ remove_concurrent_index_by_name :packages_package_files, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20210910141043_change_ci_minutes_additional_pack_text_limit.rb b/db/migrate/20210910141043_change_ci_minutes_additional_pack_text_limit.rb
new file mode 100644
index 00000000000..ebb0de53d6a
--- /dev/null
+++ b/db/migrate/20210910141043_change_ci_minutes_additional_pack_text_limit.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class ChangeCiMinutesAdditionalPackTextLimit < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ remove_text_limit :ci_minutes_additional_packs, :purchase_xid
+ add_text_limit :ci_minutes_additional_packs, :purchase_xid, 50
+ end
+
+ def down
+ remove_text_limit :ci_minutes_additional_packs, :purchase_xid
+ add_text_limit :ci_minutes_additional_packs, :purchase_xid, 32, validate: false
+ end
+end
diff --git a/db/migrate/20210913010411_create_agent_project_authorizations.rb b/db/migrate/20210913010411_create_agent_project_authorizations.rb
new file mode 100644
index 00000000000..02b6ac677e0
--- /dev/null
+++ b/db/migrate/20210913010411_create_agent_project_authorizations.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class CreateAgentProjectAuthorizations < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :agent_project_authorizations do |t|
+ t.bigint :project_id, null: false
+ t.bigint :agent_id, null: false
+ t.jsonb :config, null: false
+
+ t.index :project_id
+ t.index [:agent_id, :project_id], unique: true
+ end
+ end
+end
diff --git a/db/migrate/20210913010432_add_agent_project_authorizations_foreign_keys.rb b/db/migrate/20210913010432_add_agent_project_authorizations_foreign_keys.rb
new file mode 100644
index 00000000000..545fc125950
--- /dev/null
+++ b/db/migrate/20210913010432_add_agent_project_authorizations_foreign_keys.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddAgentProjectAuthorizationsForeignKeys < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :agent_project_authorizations, :projects, column: :project_id
+ add_concurrent_foreign_key :agent_project_authorizations, :cluster_agents, column: :agent_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_project_authorizations, column: :project_id
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_project_authorizations, column: :agent_id
+ end
+ end
+end
diff --git a/db/migrate/20210913122457_add_namespace_traversal_ids_to_ci_pending_builds.rb b/db/migrate/20210913122457_add_namespace_traversal_ids_to_ci_pending_builds.rb
new file mode 100644
index 00000000000..9dd420604f4
--- /dev/null
+++ b/db/migrate/20210913122457_add_namespace_traversal_ids_to_ci_pending_builds.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddNamespaceTraversalIdsToCiPendingBuilds < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def change
+ add_column :ci_pending_builds, :namespace_traversal_ids, :integer, array: true, default: []
+ end
+end