Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20200913115700_add_kroki_application_settings.rb16
-rw-r--r--db/migrate/20201011005400_add_text_limit_to_application_settings_kroki_url.rb19
-rw-r--r--db/migrate/20201021155606_add_analytics_access_level_to_project_features.rb23
-rw-r--r--db/migrate/20201029144524_add_index_to_releases.rb18
-rw-r--r--db/migrate/20201030223933_add_ci_pipeline_deployments_to_plan_limits.rb9
-rw-r--r--db/migrate/20201103045515_add_issuable_metric_images.rb32
-rw-r--r--db/migrate/20201104142036_add_index_to_merge_request_metrics_target_project_id.rb18
-rw-r--r--db/migrate/20201106135608_remove_redundant_pipelines_index.rb17
-rw-r--r--db/migrate/20201106193452_add_converted_at_to_experiment_users.rb9
-rw-r--r--db/migrate/20201109080645_create_vulnerability_remediations_table.rb26
-rw-r--r--db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb16
-rw-r--r--db/migrate/20201110221400_create_experiment_subjects.rb25
-rw-r--r--db/migrate/20201111051655_add_foreign_key_to_experiment_subjects_on_user.rb19
-rw-r--r--db/migrate/20201111051847_add_foreign_key_to_experiment_subjects_on_group.rb19
-rw-r--r--db/migrate/20201111051904_add_foreign_key_to_experiment_subjects_on_project.rb19
-rw-r--r--db/migrate/20201111100136_create_analytics_devops_adoption_snapshots.rb21
-rw-r--r--db/migrate/20201111115414_create_incident_management_oncall_schedules.rb36
-rw-r--r--db/migrate/20201111145317_add_relation_to_indexes_view.rb58
-rw-r--r--db/migrate/20201112132808_create_bulk_import_failures.rb39
-rw-r--r--db/migrate/20201112173532_add_verification_state_to_package_files.rb10
-rw-r--r--db/migrate/20201112173911_add_index_on_verification_state_on_package_files.rb18
-rw-r--r--db/migrate/20201112215028_add_partitioned_audit_event_indexes.rb29
-rw-r--r--db/migrate/20201116090328_add_regulated_to_compliance_frameworks.rb9
-rw-r--r--db/migrate/20201116211829_create_user_permission_export_uploads.rb33
-rw-r--r--db/migrate/20201117054609_add_cloud_license_enabled_to_settings.rb9
-rw-r--r--db/migrate/20201117075742_change_webauthn_xid_length.rb18
-rw-r--r--db/migrate/20201117153333_add_index_on_package_size_and_project_id_to_project_statistics.rb19
-rw-r--r--db/migrate/20201117184334_add_index_to_project_repositories_shard_id_project_id.rb17
-rw-r--r--db/migrate/20201117203224_add_iteration_id_to_boards_table.rb19
-rw-r--r--db/migrate/20201117213024_add_iteration_id_index_to_boards_table.rb18
-rw-r--r--db/migrate/20201118093135_create_namespace_onboarding_actions.rb23
-rw-r--r--db/migrate/20201119031515_add_iteration_id_to_lists.rb9
-rw-r--r--db/migrate/20201119053603_add_iteration_lists_foreign_key.rb21
-rw-r--r--db/migrate/20201119125730_add_web_hooks_service_foreign_key.rb23
-rw-r--r--db/migrate/20201119133534_add_personal_access_token_prefix_to_application_setting.rb12
-rw-r--r--db/migrate/20201119133604_add_text_limit_to_application_setting_personal_access_token_prefix.rb16
-rw-r--r--db/migrate/20201119162801_change_services_inherit_from_id_foreign_key.rb19
-rw-r--r--db/migrate/20201119164605_add_checksum_into_vulnerability_remediations.rb11
-rw-r--r--db/migrate/20201119213406_change_terraform_versioning_enabled_default.rb9
-rw-r--r--db/migrate/20201120125953_replace_unused_labels_index.rb22
-rw-r--r--db/migrate/20201123081307_add_operations_project_feature_to_metrics.rb19
-rw-r--r--db/migrate/20201123161611_add_provisioned_by_group_to_user_details.rb29
-rw-r--r--db/migrate/20201124030537_create_incident_management_on_call_rotations.rb35
-rw-r--r--db/migrate/20201124075951_create_vulnerability_external_links.rb42
-rw-r--r--db/migrate/20201125030847_create_dependency_proxy_manifests.rb33
-rw-r--r--db/migrate/20201125233219_add_incident_management_on_call_participants.rb33
-rw-r--r--db/migrate/20201126165919_add_epic_boards.rb29
-rw-r--r--db/migrate/20201126172030_add_feed_token_off_to_settings.rb9
-rw-r--r--db/migrate/20201126190039_add_epic_board_labels.rb24
-rw-r--r--db/migrate/20201127141433_add_other_role_to_user_details.rb25
-rw-r--r--db/migrate/20201127170848_add_index_bloat_estimate_view.rb109
-rw-r--r--db/migrate/20201201033202_add_verification_indexes_for_package_files.rb24
-rw-r--r--db/migrate/20201201034258_add_index_for_non_system_noteables.rb24
-rw-r--r--db/migrate/20201201161655_add_primary_key_to_elastic_search_indexed_projects.rb31
-rw-r--r--db/migrate/20201201163227_add_finding_uuid_to_vulnerability_feedback.rb10
-rw-r--r--db/migrate/20201201175656_add_index_vulnerabilities_on_project_id_and_state_and_severity.rb18
-rw-r--r--db/migrate/20201201190002_add_other_context_to_experiment_user.rb19
-rw-r--r--db/migrate/20201201192112_add_primary_key_to_elastic_search_indexed_namespaces.rb38
-rw-r--r--db/migrate/20201202003042_add_epic_board_positions.rb27
-rw-r--r--db/migrate/20201202025644_add_column_to_security_findings.rb9
-rw-r--r--db/migrate/20201202025937_add_index_to_security_findings_uuid.rb18
-rw-r--r--db/migrate/20201202133606_add_sorted_to_merge_request_diffs.rb19
-rw-r--r--db/migrate/20201202142751_drop_index_vulnerabilities_on_project_id.rb18
-rw-r--r--db/migrate/20201202150001_add_details_to_vulnerability_findings.rb19
-rw-r--r--db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb31
-rw-r--r--db/migrate/20201202160105_add_group_file_name_index_to_dependency_proxy_manifests.rb22
-rw-r--r--db/migrate/20201202161021_remove_redundant_index_on_merge_request_context_commit_diff_files.rb17
-rw-r--r--db/migrate/20201203123524_add_domain_enum_to_alerts.rb19
-rw-r--r--db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb19
-rw-r--r--db/migrate/20201203171631_add_index_to_domain.rb17
-rw-r--r--db/migrate/20201204085522_add_project_id_into_vulnerability_remediations.rb19
-rw-r--r--db/migrate/20201204090855_add_compound_index_to_vulnerability_remediations_table.rb28
-rw-r--r--db/migrate/20201204141038_add_trace_bytesize_to_ci_build_pending_states.rb9
-rw-r--r--db/migrate/20201204205814_add_member_events_to_web_hooks.rb9
-rw-r--r--db/migrate/20201204215353_add_pull_mirror_interval_to_plan_limits.rb9
-rw-r--r--db/migrate/20201208081429_update_internal_ids_last_value_for_epics_renamed.rb27
-rw-r--r--db/migrate/20201208143911_add_approvals_created_at_index.rb19
-rw-r--r--db/migrate/20201208181411_remove_temporary_blocking_issues_index.rb21
-rw-r--r--db/migrate/20201209154746_expand_ci_pipelines_index_on_ci_ref_id.rb24
-rw-r--r--db/migrate/20201210101250_add_index_projects_on_import_type_and_creator_id.rb19
-rw-r--r--db/migrate/20201210175044_add_index_to_snippet_on_project_id.rb17
-rw-r--r--db/migrate/20201211042306_add_deployments_finder_by_finished_at_index.rb24
-rw-r--r--db/migrate/20201211145950_add_bloat_estimate_to_reindex_action.rb9
-rw-r--r--db/migrate/20201214084105_add_expiration_policy_completed_at_to_container_repositories.rb12
-rw-r--r--db/migrate/20201214113729_add_custom_mapping_columns_to_http_integrations.rb10
-rw-r--r--db/migrate/20201215084652_delete_mock_deployment_service_records.rb15
-rw-r--r--db/migrate/20201215132151_change_unique_index_on_security_findings.rb36
87 files changed, 1896 insertions, 0 deletions
diff --git a/db/migrate/20200913115700_add_kroki_application_settings.rb b/db/migrate/20200913115700_add_kroki_application_settings.rb
new file mode 100644
index 00000000000..84d490c2980
--- /dev/null
+++ b/db/migrate/20200913115700_add_kroki_application_settings.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddKrokiApplicationSettings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20201011005400_add_text_limit_to_application_settings_kroki_url.rb
+ #
+ def change
+ add_column :application_settings, :kroki_url, :text
+ add_column :application_settings, :kroki_enabled, :boolean, default: false, null: false
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+end
diff --git a/db/migrate/20201011005400_add_text_limit_to_application_settings_kroki_url.rb b/db/migrate/20201011005400_add_text_limit_to_application_settings_kroki_url.rb
new file mode 100644
index 00000000000..96427cc3454
--- /dev/null
+++ b/db/migrate/20201011005400_add_text_limit_to_application_settings_kroki_url.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddTextLimitToApplicationSettingsKrokiUrl < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :application_settings, :kroki_url, 1024
+ end
+
+ def down
+ # Down is required as `add_text_limit` is not reversible
+ #
+ remove_text_limit :application_settings, :kroki_url
+ end
+end
diff --git a/db/migrate/20201021155606_add_analytics_access_level_to_project_features.rb b/db/migrate/20201021155606_add_analytics_access_level_to_project_features.rb
new file mode 100644
index 00000000000..faedbced06b
--- /dev/null
+++ b/db/migrate/20201021155606_add_analytics_access_level_to_project_features.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddAnalyticsAccessLevelToProjectFeatures < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :project_features, :analytics_access_level, :integer, default: 20, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :project_features, :analytics_access_level, :integer
+ end
+ end
+end
diff --git a/db/migrate/20201029144524_add_index_to_releases.rb b/db/migrate/20201029144524_add_index_to_releases.rb
new file mode 100644
index 00000000000..fbffa1453af
--- /dev/null
+++ b/db/migrate/20201029144524_add_index_to_releases.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexToReleases < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_releases_on_released_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :releases, :released_at, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :releases, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201030223933_add_ci_pipeline_deployments_to_plan_limits.rb b/db/migrate/20201030223933_add_ci_pipeline_deployments_to_plan_limits.rb
new file mode 100644
index 00000000000..60f0ff9d6ed
--- /dev/null
+++ b/db/migrate/20201030223933_add_ci_pipeline_deployments_to_plan_limits.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddCiPipelineDeploymentsToPlanLimits < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :plan_limits, :ci_pipeline_deployments, :integer, default: 500, null: false
+ end
+end
diff --git a/db/migrate/20201103045515_add_issuable_metric_images.rb b/db/migrate/20201103045515_add_issuable_metric_images.rb
new file mode 100644
index 00000000000..c598bb468a1
--- /dev/null
+++ b/db/migrate/20201103045515_add_issuable_metric_images.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class AddIssuableMetricImages < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ unless table_exists?(:issuable_metric_images)
+ with_lock_retries do
+ create_table :issuable_metric_images do |t|
+ t.references :issue, null: false, index: true, foreign_key: { on_delete: :cascade }
+ t.timestamps_with_timezone
+ t.integer :file_store, limit: 2
+ t.text :file, null: false
+ t.text :url
+ end
+ end
+ end
+
+ add_text_limit(:issuable_metric_images, :url, 255)
+ add_text_limit(:issuable_metric_images, :file, 255)
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :issuable_metric_images
+ end
+ end
+end
diff --git a/db/migrate/20201104142036_add_index_to_merge_request_metrics_target_project_id.rb b/db/migrate/20201104142036_add_index_to_merge_request_metrics_target_project_id.rb
new file mode 100644
index 00000000000..348a3387b6f
--- /dev/null
+++ b/db/migrate/20201104142036_add_index_to_merge_request_metrics_target_project_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexToMergeRequestMetricsTargetProjectId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_mr_metrics_on_target_project_id_merged_at_time_to_merge'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :merge_request_metrics, [:target_project_id, :merged_at, :created_at], where: 'merged_at > created_at', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name(:merge_request_metrics, INDEX_NAME)
+ end
+end
diff --git a/db/migrate/20201106135608_remove_redundant_pipelines_index.rb b/db/migrate/20201106135608_remove_redundant_pipelines_index.rb
new file mode 100644
index 00000000000..03e757c0ec1
--- /dev/null
+++ b/db/migrate/20201106135608_remove_redundant_pipelines_index.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveRedundantPipelinesIndex < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :ci_pipelines, :index_ci_pipelines_on_project_id_and_created_at
+ end
+
+ def down
+ add_concurrent_index :ci_pipelines, [:project_id, :created_at]
+ end
+end
diff --git a/db/migrate/20201106193452_add_converted_at_to_experiment_users.rb b/db/migrate/20201106193452_add_converted_at_to_experiment_users.rb
new file mode 100644
index 00000000000..5391093516b
--- /dev/null
+++ b/db/migrate/20201106193452_add_converted_at_to_experiment_users.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddConvertedAtToExperimentUsers < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :experiment_users, :converted_at, :datetime_with_timezone
+ end
+end
diff --git a/db/migrate/20201109080645_create_vulnerability_remediations_table.rb b/db/migrate/20201109080645_create_vulnerability_remediations_table.rb
new file mode 100644
index 00000000000..b00ce797c7d
--- /dev/null
+++ b/db/migrate/20201109080645_create_vulnerability_remediations_table.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class CreateVulnerabilityRemediationsTable < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ create_table :vulnerability_remediations, if_not_exists: true do |t|
+ t.timestamps_with_timezone
+
+ t.integer :file_store, limit: 2
+ t.text :summary, null: false
+ t.text :file, null: false
+ end
+
+ add_text_limit :vulnerability_remediations, :summary, 200
+ add_text_limit :vulnerability_remediations, :file, 255
+ end
+
+ def down
+ drop_table :vulnerability_remediations
+ end
+end
diff --git a/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb b/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb
new file mode 100644
index 00000000000..157f0de0821
--- /dev/null
+++ b/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateVulnerabilityFindingsRemediationsJoinTable < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ create_table :vulnerability_findings_remediations do |t|
+ t.references :vulnerability_occurrence, index: false, foreign_key: { on_delete: :cascade }
+ t.references :vulnerability_remediation, index: { name: 'index_vulnerability_findings_remediations_on_remediation_id' }, foreign_key: { on_delete: :cascade }
+
+ t.timestamps_with_timezone
+
+ t.index [:vulnerability_occurrence_id, :vulnerability_remediation_id], unique: true, name: 'index_vulnerability_findings_remediations_on_unique_keys'
+ end
+ end
+end
diff --git a/db/migrate/20201110221400_create_experiment_subjects.rb b/db/migrate/20201110221400_create_experiment_subjects.rb
new file mode 100644
index 00000000000..0c04d5b219f
--- /dev/null
+++ b/db/migrate/20201110221400_create_experiment_subjects.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class CreateExperimentSubjects < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ create_table :experiment_subjects do |t|
+ t.references :experiment, index: true, foreign_key: { on_delete: :cascade }, null: false
+ t.bigint :user_id, index: true
+ t.bigint :group_id, index: true
+ t.bigint :project_id, index: true
+ t.integer :variant, limit: 2, null: false, default: 0
+ t.timestamps_with_timezone null: false
+ end
+
+ # Require exactly one of user_id, group_id, or project_id to be NOT NULL
+ execute <<-SQL
+ ALTER TABLE experiment_subjects ADD CONSTRAINT chk_has_one_subject CHECK (num_nonnulls(user_id, group_id, project_id) = 1);
+ SQL
+ end
+
+ def down
+ drop_table :experiment_subjects
+ end
+end
diff --git a/db/migrate/20201111051655_add_foreign_key_to_experiment_subjects_on_user.rb b/db/migrate/20201111051655_add_foreign_key_to_experiment_subjects_on_user.rb
new file mode 100644
index 00000000000..231d083dfda
--- /dev/null
+++ b/db/migrate/20201111051655_add_foreign_key_to_experiment_subjects_on_user.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToExperimentSubjectsOnUser < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ DOWNTIME = false
+
+ def up
+ add_concurrent_foreign_key :experiment_subjects, :users, column: :user_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :experiment_subjects, column: :user_id
+ end
+ end
+end
diff --git a/db/migrate/20201111051847_add_foreign_key_to_experiment_subjects_on_group.rb b/db/migrate/20201111051847_add_foreign_key_to_experiment_subjects_on_group.rb
new file mode 100644
index 00000000000..ad0d7ae027e
--- /dev/null
+++ b/db/migrate/20201111051847_add_foreign_key_to_experiment_subjects_on_group.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToExperimentSubjectsOnGroup < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ DOWNTIME = false
+
+ def up
+ add_concurrent_foreign_key :experiment_subjects, :namespaces, column: :group_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :experiment_subjects, column: :group_id
+ end
+ end
+end
diff --git a/db/migrate/20201111051904_add_foreign_key_to_experiment_subjects_on_project.rb b/db/migrate/20201111051904_add_foreign_key_to_experiment_subjects_on_project.rb
new file mode 100644
index 00000000000..a8a05292cca
--- /dev/null
+++ b/db/migrate/20201111051904_add_foreign_key_to_experiment_subjects_on_project.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToExperimentSubjectsOnProject < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ DOWNTIME = false
+
+ def up
+ add_concurrent_foreign_key :experiment_subjects, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :experiment_subjects, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20201111100136_create_analytics_devops_adoption_snapshots.rb b/db/migrate/20201111100136_create_analytics_devops_adoption_snapshots.rb
new file mode 100644
index 00000000000..ee029d17c94
--- /dev/null
+++ b/db/migrate/20201111100136_create_analytics_devops_adoption_snapshots.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class CreateAnalyticsDevopsAdoptionSnapshots < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ create_table :analytics_devops_adoption_snapshots do |t|
+ t.references :segment, index: false, null: false, foreign_key: { to_table: :analytics_devops_adoption_segments, on_delete: :cascade }
+ t.datetime_with_timezone :recorded_at, null: false
+ t.boolean :issue_opened, null: false
+ t.boolean :merge_request_opened, null: false
+ t.boolean :merge_request_approved, null: false
+ t.boolean :runner_configured, null: false
+ t.boolean :pipeline_succeeded, null: false
+ t.boolean :deploy_succeeded, null: false
+ t.boolean :security_scan_succeeded, null: false
+
+ t.index [:segment_id, :recorded_at], name: 'index_on_snapshots_segment_id_recorded_at'
+ end
+ end
+end
diff --git a/db/migrate/20201111115414_create_incident_management_oncall_schedules.rb b/db/migrate/20201111115414_create_incident_management_oncall_schedules.rb
new file mode 100644
index 00000000000..dbb7d1c0808
--- /dev/null
+++ b/db/migrate/20201111115414_create_incident_management_oncall_schedules.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class CreateIncidentManagementOncallSchedules < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ unless table_exists?(:incident_management_oncall_schedules)
+ create_table :incident_management_oncall_schedules do |t|
+ t.timestamps_with_timezone
+ t.references :project, index: true, null: false, foreign_key: { on_delete: :cascade }
+ t.integer :iid, null: false
+ t.text :name, null: false
+ t.text :description
+ t.text :timezone
+
+ t.index %w(project_id iid), name: 'index_im_oncall_schedules_on_project_id_and_iid', unique: true, using: :btree
+ end
+ end
+ end
+
+ add_text_limit :incident_management_oncall_schedules, :name, 200
+ add_text_limit :incident_management_oncall_schedules, :description, 1000
+ add_text_limit :incident_management_oncall_schedules, :timezone, 100
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :incident_management_oncall_schedules
+ end
+ end
+end
diff --git a/db/migrate/20201111145317_add_relation_to_indexes_view.rb b/db/migrate/20201111145317_add_relation_to_indexes_view.rb
new file mode 100644
index 00000000000..318b77c1dc6
--- /dev/null
+++ b/db/migrate/20201111145317_add_relation_to_indexes_view.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+class AddRelationToIndexesView < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ execute(<<~SQL)
+ DROP VIEW postgres_indexes;
+
+ CREATE VIEW postgres_indexes AS
+ SELECT (pg_namespace.nspname::text || '.'::text) || pg_class.relname::text AS identifier,
+ pg_index.indexrelid,
+ pg_namespace.nspname AS schema,
+ pg_class.relname AS name,
+ pg_indexes.tablename,
+ pg_index.indisunique AS "unique",
+ pg_index.indisvalid AS valid_index,
+ pg_class.relispartition AS partitioned,
+ pg_index.indisexclusion AS exclusion,
+ pg_index.indexprs IS NOT NULL as expression,
+ pg_index.indpred IS NOT NULL as partial,
+ pg_indexes.indexdef AS definition,
+ pg_relation_size(pg_class.oid::regclass) AS ondisk_size_bytes
+ FROM pg_index
+ JOIN pg_class ON pg_class.oid = pg_index.indexrelid
+ JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
+ JOIN pg_indexes ON pg_class.relname = pg_indexes.indexname
+ WHERE pg_namespace.nspname <> 'pg_catalog'::name
+ AND (pg_namespace.nspname = ANY (ARRAY["current_schema"(), 'gitlab_partitions_dynamic'::name, 'gitlab_partitions_static'::name]));
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ DROP VIEW postgres_indexes;
+
+ CREATE VIEW postgres_indexes AS
+ SELECT (pg_namespace.nspname::text || '.'::text) || pg_class.relname::text AS identifier,
+ pg_index.indexrelid,
+ pg_namespace.nspname AS schema,
+ pg_class.relname AS name,
+ pg_index.indisunique AS "unique",
+ pg_index.indisvalid AS valid_index,
+ pg_class.relispartition AS partitioned,
+ pg_index.indisexclusion AS exclusion,
+ pg_index.indexprs IS NOT NULL as expression,
+ pg_index.indpred IS NOT NULL as partial,
+ pg_indexes.indexdef AS definition,
+ pg_relation_size(pg_class.oid::regclass) AS ondisk_size_bytes
+ FROM pg_index
+ JOIN pg_class ON pg_class.oid = pg_index.indexrelid
+ JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
+ JOIN pg_indexes ON pg_class.relname = pg_indexes.indexname
+ WHERE pg_namespace.nspname <> 'pg_catalog'::name
+ AND (pg_namespace.nspname = ANY (ARRAY["current_schema"(), 'gitlab_partitions_dynamic'::name, 'gitlab_partitions_static'::name]));
+ SQL
+ end
+end
diff --git a/db/migrate/20201112132808_create_bulk_import_failures.rb b/db/migrate/20201112132808_create_bulk_import_failures.rb
new file mode 100644
index 00000000000..cdc5a4d6ff0
--- /dev/null
+++ b/db/migrate/20201112132808_create_bulk_import_failures.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class CreateBulkImportFailures < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ unless table_exists?(:bulk_import_failures)
+ create_table :bulk_import_failures do |t|
+ t.references :bulk_import_entity,
+ null: false,
+ index: true,
+ foreign_key: { on_delete: :cascade }
+
+ t.datetime_with_timezone :created_at, null: false
+ t.text :pipeline_class, null: false
+ t.text :exception_class, null: false
+ t.text :exception_message, null: false
+ t.text :correlation_id_value, index: true
+ end
+ end
+ end
+
+ add_text_limit :bulk_import_failures, :pipeline_class, 255
+ add_text_limit :bulk_import_failures, :exception_class, 255
+ add_text_limit :bulk_import_failures, :exception_message, 255
+ add_text_limit :bulk_import_failures, :correlation_id_value, 255
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :bulk_import_failures
+ end
+ end
+end
diff --git a/db/migrate/20201112173532_add_verification_state_to_package_files.rb b/db/migrate/20201112173532_add_verification_state_to_package_files.rb
new file mode 100644
index 00000000000..61f526bd77e
--- /dev/null
+++ b/db/migrate/20201112173532_add_verification_state_to_package_files.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddVerificationStateToPackageFiles < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :packages_package_files, :verification_state, :integer, default: 0, limit: 2, null: false
+ add_column :packages_package_files, :verification_started_at, :datetime_with_timezone
+ end
+end
diff --git a/db/migrate/20201112173911_add_index_on_verification_state_on_package_files.rb b/db/migrate/20201112173911_add_index_on_verification_state_on_package_files.rb
new file mode 100644
index 00000000000..17e6b7d01f6
--- /dev/null
+++ b/db/migrate/20201112173911_add_index_on_verification_state_on_package_files.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexOnVerificationStateOnPackageFiles < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_packages_package_files_on_verification_state'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :packages_package_files, :verification_state, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :packages_package_files, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201112215028_add_partitioned_audit_event_indexes.rb b/db/migrate/20201112215028_add_partitioned_audit_event_indexes.rb
new file mode 100644
index 00000000000..d8b2833474b
--- /dev/null
+++ b/db/migrate/20201112215028_add_partitioned_audit_event_indexes.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class AddPartitionedAuditEventIndexes < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ DOWNTIME = false
+
+ CREATED_AT_AUTHOR_ID_INDEX_NAME = 'analytics_index_audit_events_part_on_created_at_and_author_id'
+ ENTITY_ID_DESC_INDEX_NAME = 'idx_audit_events_part_on_entity_id_desc_author_id_created_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_partitioned_index :audit_events_part_5fc467ac26,
+ [:created_at, :author_id],
+ name: CREATED_AT_AUTHOR_ID_INDEX_NAME
+
+ add_concurrent_partitioned_index :audit_events_part_5fc467ac26,
+ [:entity_id, :entity_type, :id, :author_id, :created_at],
+ order: { id: :desc },
+ name: ENTITY_ID_DESC_INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_partitioned_index_by_name :audit_events_part_5fc467ac26, ENTITY_ID_DESC_INDEX_NAME
+
+ remove_concurrent_partitioned_index_by_name :audit_events_part_5fc467ac26, CREATED_AT_AUTHOR_ID_INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201116090328_add_regulated_to_compliance_frameworks.rb b/db/migrate/20201116090328_add_regulated_to_compliance_frameworks.rb
new file mode 100644
index 00000000000..f2e0c23ccfc
--- /dev/null
+++ b/db/migrate/20201116090328_add_regulated_to_compliance_frameworks.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddRegulatedToComplianceFrameworks < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column(:compliance_management_frameworks, :regulated, :boolean, default: true, null: false)
+ end
+end
diff --git a/db/migrate/20201116211829_create_user_permission_export_uploads.rb b/db/migrate/20201116211829_create_user_permission_export_uploads.rb
new file mode 100644
index 00000000000..d6207fe0c2c
--- /dev/null
+++ b/db/migrate/20201116211829_create_user_permission_export_uploads.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class CreateUserPermissionExportUploads < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ unless table_exists?(:user_permission_export_uploads)
+ create_table :user_permission_export_uploads do |t|
+ t.timestamps_with_timezone null: false
+ t.references :user, foreign_key: { on_delete: :cascade }, index: false, null: false
+ t.integer :file_store
+ t.integer :status, limit: 2, null: false, default: 0
+ t.text :file
+
+ t.index [:user_id, :status]
+ end
+ end
+ end
+
+ add_text_limit :user_permission_export_uploads, :file, 255
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :user_permission_export_uploads
+ end
+ end
+end
diff --git a/db/migrate/20201117054609_add_cloud_license_enabled_to_settings.rb b/db/migrate/20201117054609_add_cloud_license_enabled_to_settings.rb
new file mode 100644
index 00000000000..4488aa376a1
--- /dev/null
+++ b/db/migrate/20201117054609_add_cloud_license_enabled_to_settings.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddCloudLicenseEnabledToSettings < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :application_settings, :cloud_license_enabled, :boolean, null: false, default: false
+ end
+end
diff --git a/db/migrate/20201117075742_change_webauthn_xid_length.rb b/db/migrate/20201117075742_change_webauthn_xid_length.rb
new file mode 100644
index 00000000000..2d836662e01
--- /dev/null
+++ b/db/migrate/20201117075742_change_webauthn_xid_length.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class ChangeWebauthnXidLength < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :webauthn_registrations, :credential_xid, 340, constraint_name: check_constraint_name(:webauthn_registrations, :credential_xid, 'max_length_v2')
+ remove_text_limit :webauthn_registrations, :credential_xid, constraint_name: check_constraint_name(:webauthn_registrations, :credential_xid, 'max_length')
+ end
+
+ def down
+ # no-op: Danger of failling if there are records with length(credential_xid) > 255
+ end
+end
diff --git a/db/migrate/20201117153333_add_index_on_package_size_and_project_id_to_project_statistics.rb b/db/migrate/20201117153333_add_index_on_package_size_and_project_id_to_project_statistics.rb
new file mode 100644
index 00000000000..efb5cf14d3c
--- /dev/null
+++ b/db/migrate/20201117153333_add_index_on_package_size_and_project_id_to_project_statistics.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddIndexOnPackageSizeAndProjectIdToProjectStatistics < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_project_statistics_on_packages_size_and_project_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :project_statistics, [:packages_size, :project_id],
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :project_statistics, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201117184334_add_index_to_project_repositories_shard_id_project_id.rb b/db/migrate/20201117184334_add_index_to_project_repositories_shard_id_project_id.rb
new file mode 100644
index 00000000000..25d95231ac4
--- /dev/null
+++ b/db/migrate/20201117184334_add_index_to_project_repositories_shard_id_project_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToProjectRepositoriesShardIdProjectId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :project_repositories, [:shard_id, :project_id]
+ end
+
+ def down
+ remove_concurrent_index :project_repositories, [:shard_id, :project_id], name: 'index_project_repositories_on_shard_id_and_project_id'
+ end
+end
diff --git a/db/migrate/20201117203224_add_iteration_id_to_boards_table.rb b/db/migrate/20201117203224_add_iteration_id_to_boards_table.rb
new file mode 100644
index 00000000000..18abe096604
--- /dev/null
+++ b/db/migrate/20201117203224_add_iteration_id_to_boards_table.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddIterationIdToBoardsTable < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :boards, :iteration_id, :bigint
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :boards, :iteration_id
+ end
+ end
+end
diff --git a/db/migrate/20201117213024_add_iteration_id_index_to_boards_table.rb b/db/migrate/20201117213024_add_iteration_id_index_to_boards_table.rb
new file mode 100644
index 00000000000..e038b4eacd9
--- /dev/null
+++ b/db/migrate/20201117213024_add_iteration_id_index_to_boards_table.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIterationIdIndexToBoardsTable < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_boards_on_iteration_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :boards, :iteration_id, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :boards, :iteration_id, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201118093135_create_namespace_onboarding_actions.rb b/db/migrate/20201118093135_create_namespace_onboarding_actions.rb
new file mode 100644
index 00000000000..6b38a0dddca
--- /dev/null
+++ b/db/migrate/20201118093135_create_namespace_onboarding_actions.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class CreateNamespaceOnboardingActions < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ create_table :namespace_onboarding_actions do |t|
+ t.references :namespace, index: true, null: false, foreign_key: { on_delete: :cascade }
+ t.datetime_with_timezone :created_at, null: false
+ t.integer :action, limit: 2, null: false
+ end
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :namespace_onboarding_actions
+ end
+ end
+end
diff --git a/db/migrate/20201119031515_add_iteration_id_to_lists.rb b/db/migrate/20201119031515_add_iteration_id_to_lists.rb
new file mode 100644
index 00000000000..62e13f53e92
--- /dev/null
+++ b/db/migrate/20201119031515_add_iteration_id_to_lists.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddIterationIdToLists < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :lists, :iteration_id, :bigint
+ end
+end
diff --git a/db/migrate/20201119053603_add_iteration_lists_foreign_key.rb b/db/migrate/20201119053603_add_iteration_lists_foreign_key.rb
new file mode 100644
index 00000000000..8d9ec1f2e59
--- /dev/null
+++ b/db/migrate/20201119053603_add_iteration_lists_foreign_key.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddIterationListsForeignKey < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ INDEX_NAME = 'index_lists_on_iteration_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :lists, :iteration_id, name: INDEX_NAME
+ add_concurrent_foreign_key :lists, :sprints, column: :iteration_id, on_delete: :cascade
+ end
+
+ def down
+ remove_foreign_key_if_exists :lists, :sprints, column: :iteration_id
+ remove_concurrent_index_by_name :lists, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201119125730_add_web_hooks_service_foreign_key.rb b/db/migrate/20201119125730_add_web_hooks_service_foreign_key.rb
new file mode 100644
index 00000000000..d350a7de282
--- /dev/null
+++ b/db/migrate/20201119125730_add_web_hooks_service_foreign_key.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddWebHooksServiceForeignKey < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_web_hooks_on_service_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :web_hooks, :service_id, name: INDEX_NAME
+ add_concurrent_foreign_key :web_hooks, :services, column: :service_id, on_delete: :cascade, validate: false
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :web_hooks, column: :service_id
+ end
+
+ remove_concurrent_index_by_name :web_hooks, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201119133534_add_personal_access_token_prefix_to_application_setting.rb b/db/migrate/20201119133534_add_personal_access_token_prefix_to_application_setting.rb
new file mode 100644
index 00000000000..c6bb6b7d514
--- /dev/null
+++ b/db/migrate/20201119133534_add_personal_access_token_prefix_to_application_setting.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class AddPersonalAccessTokenPrefixToApplicationSetting < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20201119133604_add_text_limit_to_application_setting_personal_access_token_prefix
+ def change
+ add_column :application_settings, :personal_access_token_prefix, :text
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+end
diff --git a/db/migrate/20201119133604_add_text_limit_to_application_setting_personal_access_token_prefix.rb b/db/migrate/20201119133604_add_text_limit_to_application_setting_personal_access_token_prefix.rb
new file mode 100644
index 00000000000..a118da9e3e7
--- /dev/null
+++ b/db/migrate/20201119133604_add_text_limit_to_application_setting_personal_access_token_prefix.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddTextLimitToApplicationSettingPersonalAccessTokenPrefix < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :application_settings, :personal_access_token_prefix, 20
+ end
+
+ def down
+ remove_text_limit :application_settings, :personal_access_token_prefix
+ end
+end
diff --git a/db/migrate/20201119162801_change_services_inherit_from_id_foreign_key.rb b/db/migrate/20201119162801_change_services_inherit_from_id_foreign_key.rb
new file mode 100644
index 00000000000..a7f12fcf726
--- /dev/null
+++ b/db/migrate/20201119162801_change_services_inherit_from_id_foreign_key.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class ChangeServicesInheritFromIdForeignKey < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :services, :services, column: :inherit_from_id, on_delete: :cascade, name: 'fk_services_inherit_from_id'
+ remove_foreign_key_if_exists :services, name: 'fk_868a8e7ad6'
+ end
+
+ def down
+ remove_foreign_key_if_exists :services, name: 'fk_services_inherit_from_id'
+ add_concurrent_foreign_key :services, :services, column: :inherit_from_id, on_delete: :nullify, name: 'fk_868a8e7ad6'
+ end
+end
diff --git a/db/migrate/20201119164605_add_checksum_into_vulnerability_remediations.rb b/db/migrate/20201119164605_add_checksum_into_vulnerability_remediations.rb
new file mode 100644
index 00000000000..a9ac1ed0676
--- /dev/null
+++ b/db/migrate/20201119164605_add_checksum_into_vulnerability_remediations.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddChecksumIntoVulnerabilityRemediations < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :vulnerability_remediations, :checksum, :binary, null: false, comment: 'Stores the SHA256 checksum of the attached diff file' # rubocop:disable Rails/NotNullColumn
+
+ add_index :vulnerability_remediations, :checksum, unique: true # rubocop:disable Migration/AddIndex (Table is empty)
+ end
+end
diff --git a/db/migrate/20201119213406_change_terraform_versioning_enabled_default.rb b/db/migrate/20201119213406_change_terraform_versioning_enabled_default.rb
new file mode 100644
index 00000000000..490fe481589
--- /dev/null
+++ b/db/migrate/20201119213406_change_terraform_versioning_enabled_default.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class ChangeTerraformVersioningEnabledDefault < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ change_column_default :terraform_states, :versioning_enabled, from: false, to: true
+ end
+end
diff --git a/db/migrate/20201120125953_replace_unused_labels_index.rb b/db/migrate/20201120125953_replace_unused_labels_index.rb
new file mode 100644
index 00000000000..afddbce618d
--- /dev/null
+++ b/db/migrate/20201120125953_replace_unused_labels_index.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class ReplaceUnusedLabelsIndex < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ NEW_INDEX_NAME = 'index_labels_on_group_id_and_title_with_null_project_id'
+ OLD_INDEX_NAME = 'index_labels_on_group_id_and_title'
+
+ def up
+ add_concurrent_index :labels, [:group_id, :title], where: 'project_id IS NULL', name: NEW_INDEX_NAME
+ remove_concurrent_index_by_name :labels, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :labels, [:group_id, :title], where: 'project_id = NULL::integer', name: OLD_INDEX_NAME
+ remove_concurrent_index_by_name :labels, NEW_INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201123081307_add_operations_project_feature_to_metrics.rb b/db/migrate/20201123081307_add_operations_project_feature_to_metrics.rb
new file mode 100644
index 00000000000..6801b49fae5
--- /dev/null
+++ b/db/migrate/20201123081307_add_operations_project_feature_to_metrics.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddOperationsProjectFeatureToMetrics < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :project_features, :operations_access_level, :integer, default: 20, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :project_features, :operations_access_level
+ end
+ end
+end
diff --git a/db/migrate/20201123161611_add_provisioned_by_group_to_user_details.rb b/db/migrate/20201123161611_add_provisioned_by_group_to_user_details.rb
new file mode 100644
index 00000000000..6e4d0e84509
--- /dev/null
+++ b/db/migrate/20201123161611_add_provisioned_by_group_to_user_details.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class AddProvisionedByGroupToUserDetails < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_user_details_on_provisioned_by_group_id'
+
+ disable_ddl_transaction!
+
+ def up
+ unless column_exists?(:user_details, :provisioned_by_group_id)
+ with_lock_retries { add_column(:user_details, :provisioned_by_group_id, :integer, limit: 8) }
+ end
+
+ add_concurrent_index :user_details, :provisioned_by_group_id, name: INDEX_NAME
+ add_concurrent_foreign_key :user_details, :namespaces, column: :provisioned_by_group_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries { remove_foreign_key_without_error :user_details, column: :provisioned_by_group_id }
+
+ remove_concurrent_index_by_name :user_details, INDEX_NAME
+
+ if column_exists?(:user_details, :provisioned_by_group_id)
+ with_lock_retries { remove_column(:user_details, :provisioned_by_group_id) }
+ end
+ end
+end
diff --git a/db/migrate/20201124030537_create_incident_management_on_call_rotations.rb b/db/migrate/20201124030537_create_incident_management_on_call_rotations.rb
new file mode 100644
index 00000000000..18546d97fd5
--- /dev/null
+++ b/db/migrate/20201124030537_create_incident_management_on_call_rotations.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class CreateIncidentManagementOnCallRotations < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ unless table_exists?(:incident_management_oncall_rotations)
+ with_lock_retries do
+ create_table :incident_management_oncall_rotations do |t|
+ t.timestamps_with_timezone
+ t.references :oncall_schedule, index: false, null: false, foreign_key: { to_table: :incident_management_oncall_schedules, on_delete: :cascade }
+ t.integer :length, null: false
+ t.integer :length_unit, limit: 2, null: false
+ t.datetime_with_timezone :starts_at, null: false
+ t.text :name, null: false
+
+ t.index %w(oncall_schedule_id id), name: 'index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_id', unique: true, using: :btree
+ t.index %w(oncall_schedule_id name), name: 'index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_name', unique: true, using: :btree
+ end
+ end
+ end
+
+ add_text_limit :incident_management_oncall_rotations, :name, 200
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :incident_management_oncall_rotations
+ end
+ end
+end
diff --git a/db/migrate/20201124075951_create_vulnerability_external_links.rb b/db/migrate/20201124075951_create_vulnerability_external_links.rb
new file mode 100644
index 00000000000..8200b15559b
--- /dev/null
+++ b/db/migrate/20201124075951_create_vulnerability_external_links.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class CreateVulnerabilityExternalLinks < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ create_table :vulnerability_external_issue_links, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+ t.references :author, null: false, index: true, foreign_key: { to_table: :users, on_delete: :nullify }, type: :bigint
+ t.references :vulnerability, null: false, index: true, type: :bigint
+ t.integer :link_type, limit: 2, null: false, default: 1 # 'created'
+ t.integer :external_type, limit: 2, null: false, default: 1 # 'jira'
+ t.text :external_project_key, null: false
+ t.text :external_issue_key, null: false
+
+ t.index %i[vulnerability_id external_type external_project_key external_issue_key],
+ name: 'idx_vulnerability_ext_issue_links_on_vulne_id_and_ext_issue',
+ unique: true
+ t.index %i[vulnerability_id link_type],
+ name: 'idx_vulnerability_ext_issue_links_on_vulne_id_and_link_type',
+ where: 'link_type = 1',
+ unique: true # only one 'created' link per vulnerability is allowed
+ end
+ end
+
+ add_concurrent_foreign_key :vulnerability_external_issue_links, :vulnerabilities, column: :vulnerability_id, on_delete: :cascade
+
+ add_text_limit :vulnerability_external_issue_links, :external_project_key, 255
+ add_text_limit :vulnerability_external_issue_links, :external_issue_key, 255
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :vulnerability_external_issue_links
+ end
+ end
+end
diff --git a/db/migrate/20201125030847_create_dependency_proxy_manifests.rb b/db/migrate/20201125030847_create_dependency_proxy_manifests.rb
new file mode 100644
index 00000000000..6c1a3f23bf3
--- /dev/null
+++ b/db/migrate/20201125030847_create_dependency_proxy_manifests.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class CreateDependencyProxyManifests < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ create_table :dependency_proxy_manifests, if_not_exists: true do |t|
+ t.timestamps_with_timezone
+ t.references :group, index: false, null: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }, type: :bigint
+ t.bigint :size
+ t.integer :file_store, limit: 2
+ t.text :file_name, null: false
+ t.text :file, null: false
+ t.text :digest, null: false
+
+ t.index [:group_id, :digest], name: 'index_dependency_proxy_manifests_on_group_id_and_digest'
+ end
+ end
+
+ add_text_limit :dependency_proxy_manifests, :file_name, 255
+ add_text_limit :dependency_proxy_manifests, :file, 255
+ add_text_limit :dependency_proxy_manifests, :digest, 255
+ end
+
+ def down
+ drop_table :dependency_proxy_manifests
+ end
+end
diff --git a/db/migrate/20201125233219_add_incident_management_on_call_participants.rb b/db/migrate/20201125233219_add_incident_management_on_call_participants.rb
new file mode 100644
index 00000000000..2a9b1d8b276
--- /dev/null
+++ b/db/migrate/20201125233219_add_incident_management_on_call_participants.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class AddIncidentManagementOnCallParticipants < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ PARTICIPANT_ROTATION_INDEX_NAME = 'index_inc_mgmnt_oncall_participants_on_oncall_rotation_id'
+ PARTICIPANT_USER_INDEX_NAME = 'index_inc_mgmnt_oncall_participants_on_oncall_user_id'
+ UNIQUE_INDEX_NAME = 'index_inc_mgmnt_oncall_participants_on_user_id_and_rotation_id'
+
+ disable_ddl_transaction!
+
+ def up
+ unless table_exists?(:incident_management_oncall_participants)
+ with_lock_retries do
+ create_table :incident_management_oncall_participants do |t|
+ t.references :oncall_rotation, index: false, null: false, foreign_key: { to_table: :incident_management_oncall_rotations, on_delete: :cascade }
+ t.references :user, index: false, null: false, foreign_key: { on_delete: :cascade }
+ t.integer :color_palette, limit: 2, null: false
+ t.integer :color_weight, limit: 2, null: false
+ t.index :user_id, name: PARTICIPANT_USER_INDEX_NAME
+ t.index :oncall_rotation_id, name: PARTICIPANT_ROTATION_INDEX_NAME
+ t.index [:user_id, :oncall_rotation_id], unique: true, name: UNIQUE_INDEX_NAME
+ end
+ end
+ end
+ end
+
+ def down
+ drop_table :incident_management_oncall_participants
+ end
+end
diff --git a/db/migrate/20201126165919_add_epic_boards.rb b/db/migrate/20201126165919_add_epic_boards.rb
new file mode 100644
index 00000000000..432b839d6ea
--- /dev/null
+++ b/db/migrate/20201126165919_add_epic_boards.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class AddEpicBoards < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ create_table :boards_epic_boards do |t|
+ t.boolean :hide_backlog_list, default: false, null: false
+ t.boolean :hide_closed_list, default: false, null: false
+ t.references :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade }, null: false
+ t.timestamps_with_timezone
+ t.text :name, default: 'Development', null: false
+ end
+ end
+
+ add_text_limit :boards_epic_boards, :name, 255
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :boards_epic_boards
+ end
+ end
+end
diff --git a/db/migrate/20201126172030_add_feed_token_off_to_settings.rb b/db/migrate/20201126172030_add_feed_token_off_to_settings.rb
new file mode 100644
index 00000000000..04e05c9bd43
--- /dev/null
+++ b/db/migrate/20201126172030_add_feed_token_off_to_settings.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddFeedTokenOffToSettings < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :application_settings, :disable_feed_token, :boolean, null: false, default: false
+ end
+end
diff --git a/db/migrate/20201126190039_add_epic_board_labels.rb b/db/migrate/20201126190039_add_epic_board_labels.rb
new file mode 100644
index 00000000000..519e705ce14
--- /dev/null
+++ b/db/migrate/20201126190039_add_epic_board_labels.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AddEpicBoardLabels < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ create_table :boards_epic_board_labels do |t|
+ t.references :epic_board, index: true, foreign_key: { to_table: :boards_epic_boards, on_delete: :cascade }, null: false
+ t.references :label, index: true, foreign_key: { on_delete: :cascade }, null: false
+ end
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :boards_epic_board_labels
+ end
+ end
+end
diff --git a/db/migrate/20201127141433_add_other_role_to_user_details.rb b/db/migrate/20201127141433_add_other_role_to_user_details.rb
new file mode 100644
index 00000000000..586dbb033fd
--- /dev/null
+++ b/db/migrate/20201127141433_add_other_role_to_user_details.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class AddOtherRoleToUserDetails < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ unless column_exists?(:user_details, :other_role)
+ with_lock_retries do
+ add_column :user_details, :other_role, :text
+ end
+ end
+
+ add_text_limit :user_details, :other_role, 100
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :user_details, :other_role
+ end
+ end
+end
diff --git a/db/migrate/20201127170848_add_index_bloat_estimate_view.rb b/db/migrate/20201127170848_add_index_bloat_estimate_view.rb
new file mode 100644
index 00000000000..ab268f8569e
--- /dev/null
+++ b/db/migrate/20201127170848_add_index_bloat_estimate_view.rb
@@ -0,0 +1,109 @@
+# frozen_string_literal: true
+
+class AddIndexBloatEstimateView < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ execute(<<~SQL)
+ CREATE VIEW postgres_index_bloat_estimates AS
+ -- Originally from: https://github.com/ioguix/pgsql-bloat-estimation/blob/master/btree/btree_bloat.sql
+ -- WARNING: executed with a non-superuser role, the query inspect only index on tables you are granted to read.
+ -- WARNING: rows with is_na = 't' are known to have bad statistics ("name" type is not supported).
+ -- This query is compatible with PostgreSQL 8.2 and after
+ SELECT nspname || '.' || idxname as identifier,
+ CASE WHEN relpages > est_pages_ff
+ THEN bs*(relpages-est_pages_ff)
+ ELSE 0
+ END::bigint AS bloat_size_bytes
+ FROM (
+ SELECT
+ coalesce(1 +
+ ceil(reltuples/floor((bs-pageopqdata-pagehdr)*fillfactor/(100*(4+nulldatahdrwidth)::float))), 0
+ ) AS est_pages_ff,
+ bs, nspname, tblname, idxname, relpages, is_na
+ FROM (
+ SELECT maxalign, bs, nspname, tblname, idxname, reltuples, relpages, idxoid, fillfactor,
+ ( index_tuple_hdr_bm +
+ maxalign - CASE -- Add padding to the index tuple header to align on MAXALIGN
+ WHEN index_tuple_hdr_bm%maxalign = 0 THEN maxalign
+ ELSE index_tuple_hdr_bm%maxalign
+ END
+ + nulldatawidth + maxalign - CASE -- Add padding to the data to align on MAXALIGN
+ WHEN nulldatawidth = 0 THEN 0
+ WHEN nulldatawidth::integer%maxalign = 0 THEN maxalign
+ ELSE nulldatawidth::integer%maxalign
+ END
+ )::numeric AS nulldatahdrwidth, pagehdr, pageopqdata, is_na
+ FROM (
+ SELECT n.nspname, i.tblname, i.idxname, i.reltuples, i.relpages,
+ i.idxoid, i.fillfactor, current_setting('block_size')::numeric AS bs,
+ CASE -- MAXALIGN: 4 on 32bits, 8 on 64bits (and mingw32 ?)
+ WHEN version() ~ 'mingw32' OR version() ~ '64-bit|x86_64|ppc64|ia64|amd64' THEN 8
+ ELSE 4
+ END AS maxalign,
+ /* per page header, fixed size: 20 for 7.X, 24 for others */
+ 24 AS pagehdr,
+ /* per page btree opaque data */
+ 16 AS pageopqdata,
+ /* per tuple header: add IndexAttributeBitMapData if some cols are null-able */
+ CASE WHEN max(coalesce(s.null_frac,0)) = 0
+ THEN 2 -- IndexTupleData size
+ ELSE 2 + (( 32 + 8 - 1 ) / 8) -- IndexTupleData size + IndexAttributeBitMapData size ( max num filed per index + 8 - 1 /8)
+ END AS index_tuple_hdr_bm,
+ /* data len: we remove null values save space using it fractionnal part from stats */
+ sum( (1-coalesce(s.null_frac, 0)) * coalesce(s.avg_width, 1024)) AS nulldatawidth,
+ max( CASE WHEN i.atttypid = 'pg_catalog.name'::regtype THEN 1 ELSE 0 END ) > 0 AS is_na
+ FROM (
+ SELECT ct.relname AS tblname, ct.relnamespace, ic.idxname, ic.attpos, ic.indkey, ic.indkey[ic.attpos], ic.reltuples, ic.relpages, ic.tbloid, ic.idxoid, ic.fillfactor,
+ coalesce(a1.attnum, a2.attnum) AS attnum, coalesce(a1.attname, a2.attname) AS attname, coalesce(a1.atttypid, a2.atttypid) AS atttypid,
+ CASE WHEN a1.attnum IS NULL
+ THEN ic.idxname
+ ELSE ct.relname
+ END AS attrelname
+ FROM (
+ SELECT idxname, reltuples, relpages, tbloid, idxoid, fillfactor, indkey,
+ pg_catalog.generate_series(1,indnatts) AS attpos
+ FROM (
+ SELECT ci.relname AS idxname, ci.reltuples, ci.relpages, i.indrelid AS tbloid,
+ i.indexrelid AS idxoid,
+ coalesce(substring(
+ array_to_string(ci.reloptions, ' ')
+ from 'fillfactor=([0-9]+)')::smallint, 90) AS fillfactor,
+ i.indnatts,
+ pg_catalog.string_to_array(pg_catalog.textin(
+ pg_catalog.int2vectorout(i.indkey)),' ')::int[] AS indkey
+ FROM pg_catalog.pg_index i
+ JOIN pg_catalog.pg_class ci ON ci.oid = i.indexrelid
+ WHERE ci.relam=(SELECT oid FROM pg_am WHERE amname = 'btree')
+ AND ci.relpages > 0
+ ) AS idx_data
+ ) AS ic
+ JOIN pg_catalog.pg_class ct ON ct.oid = ic.tbloid
+ LEFT JOIN pg_catalog.pg_attribute a1 ON
+ ic.indkey[ic.attpos] <> 0
+ AND a1.attrelid = ic.tbloid
+ AND a1.attnum = ic.indkey[ic.attpos]
+ LEFT JOIN pg_catalog.pg_attribute a2 ON
+ ic.indkey[ic.attpos] = 0
+ AND a2.attrelid = ic.idxoid
+ AND a2.attnum = ic.attpos
+ ) i
+ JOIN pg_catalog.pg_namespace n ON n.oid = i.relnamespace
+ JOIN pg_catalog.pg_stats s ON s.schemaname = n.nspname
+ AND s.tablename = i.attrelname
+ AND s.attname = i.attname
+ GROUP BY 1,2,3,4,5,6,7,8,9,10,11
+ ) AS rows_data_stats
+ ) AS rows_hdr_pdg_stats
+ ) AS relation_stats
+ WHERE nspname IN ("current_schema"(), 'gitlab_partitions_dynamic', 'gitlab_partitions_static') AND NOT is_na
+ ORDER BY nspname, tblname, idxname;
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ DROP VIEW postgres_index_bloat_estimates
+ SQL
+ end
+end
diff --git a/db/migrate/20201201033202_add_verification_indexes_for_package_files.rb b/db/migrate/20201201033202_add_verification_indexes_for_package_files.rb
new file mode 100644
index 00000000000..b7f55101682
--- /dev/null
+++ b/db/migrate/20201201033202_add_verification_indexes_for_package_files.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AddVerificationIndexesForPackageFiles < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ PENDING_VERIFICATION_INDEX_NAME = "packages_packages_pending_verification"
+ FAILED_VERIFICATION_INDEX_NAME = "packages_packages_failed_verification"
+ NEEDS_VERIFICATION_INDEX_NAME = "packages_packages_needs_verification"
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :packages_package_files, :verified_at, where: "(verification_state = 0)", order: { verified_at: 'ASC NULLS FIRST' }, name: PENDING_VERIFICATION_INDEX_NAME
+ add_concurrent_index :packages_package_files, :verification_retry_at, where: "(verification_state = 3)", order: { verification_retry_at: 'ASC NULLS FIRST' }, name: FAILED_VERIFICATION_INDEX_NAME
+ add_concurrent_index :packages_package_files, :verification_state, where: "(verification_state = 0 OR verification_state = 3)", name: NEEDS_VERIFICATION_INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :packages_package_files, PENDING_VERIFICATION_INDEX_NAME
+ remove_concurrent_index_by_name :packages_package_files, FAILED_VERIFICATION_INDEX_NAME
+ remove_concurrent_index_by_name :packages_package_files, NEEDS_VERIFICATION_INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201201034258_add_index_for_non_system_noteables.rb b/db/migrate/20201201034258_add_index_for_non_system_noteables.rb
new file mode 100644
index 00000000000..5927463e767
--- /dev/null
+++ b/db/migrate/20201201034258_add_index_for_non_system_noteables.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AddIndexForNonSystemNoteables < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ LEGACY_INDEX_NAME = "index_notes_on_noteable_id_and_noteable_type"
+ NEW_INDEX_NAME = "index_notes_on_noteable_id_and_noteable_type_and_system"
+
+ def up
+ add_concurrent_index :notes, [:noteable_id, :noteable_type, :system], name: NEW_INDEX_NAME
+
+ remove_concurrent_index_by_name :notes, LEGACY_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :notes, [:noteable_id, :noteable_type], name: LEGACY_INDEX_NAME
+
+ remove_concurrent_index_by_name :notes, NEW_INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201201161655_add_primary_key_to_elastic_search_indexed_projects.rb b/db/migrate/20201201161655_add_primary_key_to_elastic_search_indexed_projects.rb
new file mode 100644
index 00000000000..cf7221693f9
--- /dev/null
+++ b/db/migrate/20201201161655_add_primary_key_to_elastic_search_indexed_projects.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class AddPrimaryKeyToElasticSearchIndexedProjects < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ UNIQUE_INDEX_NAME = 'index_elasticsearch_indexed_projects_on_project_id'
+ PRIMARY_KEY_NAME = 'elasticsearch_indexed_projects_pkey'
+
+ def up
+ execute(<<~SQL)
+ DELETE FROM elasticsearch_indexed_projects
+ WHERE project_id IS NULL
+ SQL
+
+ execute(<<~SQL)
+ ALTER TABLE elasticsearch_indexed_projects
+ ALTER COLUMN project_id SET NOT NULL,
+ ADD CONSTRAINT #{PRIMARY_KEY_NAME} PRIMARY KEY USING INDEX #{UNIQUE_INDEX_NAME}
+ SQL
+ end
+
+ def down
+ add_index :elasticsearch_indexed_projects, :project_id, unique: true, name: UNIQUE_INDEX_NAME # rubocop:disable Migration/AddIndex
+
+ execute(<<~SQL)
+ ALTER TABLE elasticsearch_indexed_projects
+ DROP CONSTRAINT #{PRIMARY_KEY_NAME},
+ ALTER COLUMN project_id DROP NOT NULL
+ SQL
+ end
+end
diff --git a/db/migrate/20201201163227_add_finding_uuid_to_vulnerability_feedback.rb b/db/migrate/20201201163227_add_finding_uuid_to_vulnerability_feedback.rb
new file mode 100644
index 00000000000..a2e13806000
--- /dev/null
+++ b/db/migrate/20201201163227_add_finding_uuid_to_vulnerability_feedback.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddFindingUuidToVulnerabilityFeedback < ActiveRecord::Migration[6.0]
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ def change
+ add_column :vulnerability_feedback, :finding_uuid, :uuid
+ end
+end
diff --git a/db/migrate/20201201175656_add_index_vulnerabilities_on_project_id_and_state_and_severity.rb b/db/migrate/20201201175656_add_index_vulnerabilities_on_project_id_and_state_and_severity.rb
new file mode 100644
index 00000000000..d0e8920d7a5
--- /dev/null
+++ b/db/migrate/20201201175656_add_index_vulnerabilities_on_project_id_and_state_and_severity.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexVulnerabilitiesOnProjectIdAndStateAndSeverity < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_vulnerabilities_on_project_id_and_state_and_severity'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerabilities, [:project_id, :state, :severity], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201201190002_add_other_context_to_experiment_user.rb b/db/migrate/20201201190002_add_other_context_to_experiment_user.rb
new file mode 100644
index 00000000000..c901f049e75
--- /dev/null
+++ b/db/migrate/20201201190002_add_other_context_to_experiment_user.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddOtherContextToExperimentUser < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :experiment_users, :context, :jsonb, default: {}, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :experiment_users, :context
+ end
+ end
+end
diff --git a/db/migrate/20201201192112_add_primary_key_to_elastic_search_indexed_namespaces.rb b/db/migrate/20201201192112_add_primary_key_to_elastic_search_indexed_namespaces.rb
new file mode 100644
index 00000000000..610cd2828ca
--- /dev/null
+++ b/db/migrate/20201201192112_add_primary_key_to_elastic_search_indexed_namespaces.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class AddPrimaryKeyToElasticSearchIndexedNamespaces < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ UNIQUE_INDEX_NAME = 'index_elasticsearch_indexed_namespaces_on_namespace_id'
+ PRIMARY_KEY_NAME = 'elasticsearch_indexed_namespaces_pkey'
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ execute(<<~SQL)
+ LOCK TABLE elasticsearch_indexed_namespaces IN ACCESS EXCLUSIVE MODE;
+
+ DELETE FROM elasticsearch_indexed_namespaces
+ WHERE namespace_id IS NULL;
+
+ ALTER TABLE elasticsearch_indexed_namespaces
+ ADD CONSTRAINT #{PRIMARY_KEY_NAME} PRIMARY KEY USING INDEX #{UNIQUE_INDEX_NAME};
+ SQL
+ end
+ end
+
+ def down
+ add_concurrent_index :elasticsearch_indexed_namespaces, :namespace_id, unique: true, name: UNIQUE_INDEX_NAME
+
+ with_lock_retries do
+ execute(<<~SQL)
+ ALTER TABLE elasticsearch_indexed_namespaces
+ DROP CONSTRAINT #{PRIMARY_KEY_NAME},
+ ALTER COLUMN namespace_id DROP NOT NULL
+ SQL
+ end
+ end
+end
diff --git a/db/migrate/20201202003042_add_epic_board_positions.rb b/db/migrate/20201202003042_add_epic_board_positions.rb
new file mode 100644
index 00000000000..528d5ed3af1
--- /dev/null
+++ b/db/migrate/20201202003042_add_epic_board_positions.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class AddEpicBoardPositions < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ create_table :boards_epic_board_positions do |t|
+ t.references :epic_board, foreign_key: { to_table: :boards_epic_boards, on_delete: :cascade }, null: false, index: false
+ t.references :epic, foreign_key: { on_delete: :cascade }, null: false, index: true
+ t.integer :relative_position
+
+ t.timestamps_with_timezone null: false
+
+ t.index [:epic_board_id, :epic_id], unique: true, name: :index_boards_epic_board_positions_on_epic_board_id_and_epic_id
+ end
+ end
+ end
+
+ def down
+ with_lock_retries do
+ drop_table :boards_epic_board_positions
+ end
+ end
+end
diff --git a/db/migrate/20201202025644_add_column_to_security_findings.rb b/db/migrate/20201202025644_add_column_to_security_findings.rb
new file mode 100644
index 00000000000..0b63b79d949
--- /dev/null
+++ b/db/migrate/20201202025644_add_column_to_security_findings.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+#
+class AddColumnToSecurityFindings < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :security_findings, :uuid, :uuid
+ end
+end
diff --git a/db/migrate/20201202025937_add_index_to_security_findings_uuid.rb b/db/migrate/20201202025937_add_index_to_security_findings_uuid.rb
new file mode 100644
index 00000000000..4c33809fbfc
--- /dev/null
+++ b/db/migrate/20201202025937_add_index_to_security_findings_uuid.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexToSecurityFindingsUuid < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_security_findings_on_uuid'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :security_findings, :uuid, name: INDEX_NAME, unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :security_findings, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201202133606_add_sorted_to_merge_request_diffs.rb b/db/migrate/20201202133606_add_sorted_to_merge_request_diffs.rb
new file mode 100644
index 00000000000..4c0d28d70a1
--- /dev/null
+++ b/db/migrate/20201202133606_add_sorted_to_merge_request_diffs.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddSortedToMergeRequestDiffs < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :merge_request_diffs, :sorted, :boolean, null: false, default: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :merge_request_diffs, :sorted
+ end
+ end
+end
diff --git a/db/migrate/20201202142751_drop_index_vulnerabilities_on_project_id.rb b/db/migrate/20201202142751_drop_index_vulnerabilities_on_project_id.rb
new file mode 100644
index 00000000000..c1ca32a1978
--- /dev/null
+++ b/db/migrate/20201202142751_drop_index_vulnerabilities_on_project_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class DropIndexVulnerabilitiesOnProjectId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_vulnerabilities_on_project_id'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :vulnerabilities, :project_id, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201202150001_add_details_to_vulnerability_findings.rb b/db/migrate/20201202150001_add_details_to_vulnerability_findings.rb
new file mode 100644
index 00000000000..b7639bdfaa3
--- /dev/null
+++ b/db/migrate/20201202150001_add_details_to_vulnerability_findings.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddDetailsToVulnerabilityFindings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :vulnerability_occurrences, :details, :jsonb, default: {}, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :vulnerability_occurrences, :details
+ end
+ end
+end
diff --git a/db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb b/db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb
new file mode 100644
index 00000000000..90c7b2731c8
--- /dev/null
+++ b/db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class AddPrimaryKeyToMergeRequestContextCommitDiffFiles < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ execute(<<~SQL)
+ DELETE FROM merge_request_context_commit_diff_files
+ WHERE merge_request_context_commit_id IS NULL;
+
+ DELETE FROM merge_request_context_commit_diff_files df1
+ USING merge_request_context_commit_diff_files df2
+ WHERE df1.ctid < df2.ctid
+ AND df1.merge_request_context_commit_id = df2.merge_request_context_commit_id
+ AND df1.relative_order = df2.relative_order;
+
+ ALTER TABLE merge_request_context_commit_diff_files
+ ADD CONSTRAINT merge_request_context_commit_diff_files_pkey PRIMARY KEY (merge_request_context_commit_id, relative_order);
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ ALTER TABLE merge_request_context_commit_diff_files
+ DROP CONSTRAINT merge_request_context_commit_diff_files_pkey,
+ ALTER COLUMN merge_request_context_commit_id DROP NOT NULL
+ SQL
+ end
+end
diff --git a/db/migrate/20201202160105_add_group_file_name_index_to_dependency_proxy_manifests.rb b/db/migrate/20201202160105_add_group_file_name_index_to_dependency_proxy_manifests.rb
new file mode 100644
index 00000000000..a0bafeedaec
--- /dev/null
+++ b/db/migrate/20201202160105_add_group_file_name_index_to_dependency_proxy_manifests.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddGroupFileNameIndexToDependencyProxyManifests < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ NEW_INDEX = 'index_dependency_proxy_manifests_on_group_id_and_file_name'
+ OLD_INDEX = 'index_dependency_proxy_manifests_on_group_id_and_digest'
+
+ def up
+ add_concurrent_index :dependency_proxy_manifests, [:group_id, :file_name], name: NEW_INDEX, unique: true
+ remove_concurrent_index_by_name :dependency_proxy_manifests, OLD_INDEX
+ end
+
+ def down
+ add_concurrent_index :dependency_proxy_manifests, [:group_id, :digest], name: OLD_INDEX
+ remove_concurrent_index_by_name :dependency_proxy_manifests, NEW_INDEX
+ end
+end
diff --git a/db/migrate/20201202161021_remove_redundant_index_on_merge_request_context_commit_diff_files.rb b/db/migrate/20201202161021_remove_redundant_index_on_merge_request_context_commit_diff_files.rb
new file mode 100644
index 00000000000..a9c0a079955
--- /dev/null
+++ b/db/migrate/20201202161021_remove_redundant_index_on_merge_request_context_commit_diff_files.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveRedundantIndexOnMergeRequestContextCommitDiffFiles < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :merge_request_context_commit_diff_files, 'idx_mr_cc_diff_files_on_mr_cc_id'
+ end
+
+ def down
+ # no-op: this index is not tracked in structure.sql, and is redundant due to idx_mr_cc_diff_files_on_mr_cc_id_and_sha
+ end
+end
diff --git a/db/migrate/20201203123524_add_domain_enum_to_alerts.rb b/db/migrate/20201203123524_add_domain_enum_to_alerts.rb
new file mode 100644
index 00000000000..f1dec91a346
--- /dev/null
+++ b/db/migrate/20201203123524_add_domain_enum_to_alerts.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddDomainEnumToAlerts < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :alert_management_alerts, :domain, :integer, limit: 2, default: 0
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :alert_management_alerts, :domain, :integer, limit: 2
+ end
+ end
+end
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
new file mode 100644
index 00000000000..efca683d748
--- /dev/null
+++ b/db/migrate/20201203144655_add_allow_to_edit_commit_to_project_settings.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddAllowToEditCommitToProjectSettings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ with_lock_retries do
+ add_column :project_settings, :allow_editing_commit_messages, :boolean, default: false, null: false
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :project_settings, :allow_editing_commit_messages
+ end
+ end
+end
diff --git a/db/migrate/20201203171631_add_index_to_domain.rb b/db/migrate/20201203171631_add_index_to_domain.rb
new file mode 100644
index 00000000000..dc7b9539e95
--- /dev/null
+++ b/db/migrate/20201203171631_add_index_to_domain.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToDomain < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+ DOWNTIME = false
+ INDEX_NAME = 'index_alert_management_alerts_on_domain'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :alert_management_alerts, :domain, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :alert_management_alerts, :domain, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201204085522_add_project_id_into_vulnerability_remediations.rb b/db/migrate/20201204085522_add_project_id_into_vulnerability_remediations.rb
new file mode 100644
index 00000000000..6a136ab0389
--- /dev/null
+++ b/db/migrate/20201204085522_add_project_id_into_vulnerability_remediations.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddProjectIdIntoVulnerabilityRemediations < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ connection.execute('DELETE FROM vulnerability_remediations')
+
+ add_column :vulnerability_remediations, :project_id, :bigint, null: false # rubocop:disable Rails/NotNullColumn
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :vulnerability_remediations, :project_id
+ end
+ end
+end
diff --git a/db/migrate/20201204090855_add_compound_index_to_vulnerability_remediations_table.rb b/db/migrate/20201204090855_add_compound_index_to_vulnerability_remediations_table.rb
new file mode 100644
index 00000000000..0b4b6e552aa
--- /dev/null
+++ b/db/migrate/20201204090855_add_compound_index_to_vulnerability_remediations_table.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class AddCompoundIndexToVulnerabilityRemediationsTable < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ NEW_INDEX_NAME = 'index_vulnerability_remediations_on_project_id_and_checksum'
+ OLD_INDEX_NAME = 'index_vulnerability_remediations_on_checksum'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerability_remediations, [:project_id, :checksum], unique: true, name: NEW_INDEX_NAME
+ add_concurrent_foreign_key :vulnerability_remediations, :projects, column: :project_id
+
+ remove_concurrent_index_by_name :vulnerability_remediations, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :vulnerability_remediations, :checksum, unique: true, name: OLD_INDEX_NAME
+
+ remove_concurrent_index_by_name :vulnerability_remediations, NEW_INDEX_NAME
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :vulnerability_remediations, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20201204141038_add_trace_bytesize_to_ci_build_pending_states.rb b/db/migrate/20201204141038_add_trace_bytesize_to_ci_build_pending_states.rb
new file mode 100644
index 00000000000..c866493e8d8
--- /dev/null
+++ b/db/migrate/20201204141038_add_trace_bytesize_to_ci_build_pending_states.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddTraceBytesizeToCiBuildPendingStates < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :ci_build_pending_states, :trace_bytesize, :bigint
+ end
+end
diff --git a/db/migrate/20201204205814_add_member_events_to_web_hooks.rb b/db/migrate/20201204205814_add_member_events_to_web_hooks.rb
new file mode 100644
index 00000000000..edb374f1bdd
--- /dev/null
+++ b/db/migrate/20201204205814_add_member_events_to_web_hooks.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddMemberEventsToWebHooks < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :web_hooks, :member_events, :boolean, null: false, default: false
+ end
+end
diff --git a/db/migrate/20201204215353_add_pull_mirror_interval_to_plan_limits.rb b/db/migrate/20201204215353_add_pull_mirror_interval_to_plan_limits.rb
new file mode 100644
index 00000000000..3484e4c8afa
--- /dev/null
+++ b/db/migrate/20201204215353_add_pull_mirror_interval_to_plan_limits.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddPullMirrorIntervalToPlanLimits < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :plan_limits, :pull_mirror_interval_seconds, :integer, default: 300, null: false
+ end
+end
diff --git a/db/migrate/20201208081429_update_internal_ids_last_value_for_epics_renamed.rb b/db/migrate/20201208081429_update_internal_ids_last_value_for_epics_renamed.rb
new file mode 100644
index 00000000000..fadc365d53c
--- /dev/null
+++ b/db/migrate/20201208081429_update_internal_ids_last_value_for_epics_renamed.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class UpdateInternalIdsLastValueForEpicsRenamed < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ ApplicationRecord.connection.execute(<<-SQL.squish)
+ UPDATE internal_ids
+ SET last_value = epics_max_iids.maximum_iid
+ FROM
+ (
+ SELECT
+ MAX(epics.iid) AS maximum_iid,
+ epics.group_id AS epics_group_id
+ FROM epics
+ GROUP BY epics.group_id
+ ) epics_max_iids
+ WHERE internal_ids.last_value < epics_max_iids.maximum_iid
+ AND namespace_id = epics_max_iids.epics_group_id
+ AND internal_ids.usage = 4
+ SQL
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20201208143911_add_approvals_created_at_index.rb b/db/migrate/20201208143911_add_approvals_created_at_index.rb
new file mode 100644
index 00000000000..cfec6b257c2
--- /dev/null
+++ b/db/migrate/20201208143911_add_approvals_created_at_index.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddApprovalsCreatedAtIndex < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_approvals_on_merge_request_id_and_created_at'
+
+ def up
+ add_concurrent_index :approvals, [:merge_request_id, :created_at], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :approvals, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201208181411_remove_temporary_blocking_issues_index.rb b/db/migrate/20201208181411_remove_temporary_blocking_issues_index.rb
new file mode 100644
index 00000000000..ea63d2d1ed3
--- /dev/null
+++ b/db/migrate/20201208181411_remove_temporary_blocking_issues_index.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RemoveTemporaryBlockingIssuesIndex < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name(:issue_links, 'tmp_idx_blocking_type_links')
+ remove_concurrent_index_by_name(:issue_links, 'tmp_idx_blocked_by_type_links')
+ remove_concurrent_index_by_name(:issues, 'tmp_idx_index_issues_with_outdate_blocking_count')
+ end
+
+ def down
+ add_concurrent_index :issue_links, [:source_id], where: 'link_type = 1', name: 'tmp_idx_blocking_type_links'
+ add_concurrent_index :issue_links, [:target_id], where: 'link_type = 2', name: 'tmp_idx_blocked_by_type_links'
+ add_concurrent_index :issues, :id, where: '(state_id = 1 AND blocking_issues_count = 0)', name: 'tmp_idx_index_issues_with_outdate_blocking_count'
+ end
+end
diff --git a/db/migrate/20201209154746_expand_ci_pipelines_index_on_ci_ref_id.rb b/db/migrate/20201209154746_expand_ci_pipelines_index_on_ci_ref_id.rb
new file mode 100644
index 00000000000..b88763a30f9
--- /dev/null
+++ b/db/migrate/20201209154746_expand_ci_pipelines_index_on_ci_ref_id.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ExpandCiPipelinesIndexOnCiRefId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ NEW_NAME = 'index_ci_pipelines_on_ci_ref_id_and_more'
+ OLD_NAME = 'index_ci_pipelines_on_ci_ref_id'
+
+ def up
+ add_concurrent_index :ci_pipelines, %i[ci_ref_id id source status], order: { id: :desc }, where: 'ci_ref_id IS NOT NULL', name: NEW_NAME
+
+ remove_concurrent_index_by_name :ci_pipelines, OLD_NAME
+ end
+
+ def down
+ add_concurrent_index :ci_pipelines, :ci_ref_id, where: 'ci_ref_id IS NOT NULL', name: OLD_NAME
+
+ remove_concurrent_index_by_name :ci_pipelines, NEW_NAME
+ end
+end
diff --git a/db/migrate/20201210101250_add_index_projects_on_import_type_and_creator_id.rb b/db/migrate/20201210101250_add_index_projects_on_import_type_and_creator_id.rb
new file mode 100644
index 00000000000..5eb8f1d658e
--- /dev/null
+++ b/db/migrate/20201210101250_add_index_projects_on_import_type_and_creator_id.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddIndexProjectsOnImportTypeAndCreatorId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :projects, [:creator_id, :import_type, :created_at],
+ where: 'import_type IS NOT NULL',
+ name: 'index_projects_on_creator_id_import_type_and_created_at_partial'
+ end
+
+ def down
+ remove_concurrent_index_by_name :projects, 'index_projects_on_creator_id_import_type_and_created_at_partial'
+ end
+end
diff --git a/db/migrate/20201210175044_add_index_to_snippet_on_project_id.rb b/db/migrate/20201210175044_add_index_to_snippet_on_project_id.rb
new file mode 100644
index 00000000000..6de4a840409
--- /dev/null
+++ b/db/migrate/20201210175044_add_index_to_snippet_on_project_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToSnippetOnProjectId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+ INDEX_NAME = "index_snippet_on_id_and_project_id"
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :snippets, [:id, :project_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :snippets, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201211042306_add_deployments_finder_by_finished_at_index.rb b/db/migrate/20201211042306_add_deployments_finder_by_finished_at_index.rb
new file mode 100644
index 00000000000..f937ff7a436
--- /dev/null
+++ b/db/migrate/20201211042306_add_deployments_finder_by_finished_at_index.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AddDeploymentsFinderByFinishedAtIndex < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = "index_deployments_on_project_and_finished"
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :deployments,
+ [:project_id, :finished_at],
+ where: 'status = 2',
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :deployments,
+ [:project_id, :finished_at],
+ where: 'status = 2',
+ name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20201211145950_add_bloat_estimate_to_reindex_action.rb b/db/migrate/20201211145950_add_bloat_estimate_to_reindex_action.rb
new file mode 100644
index 00000000000..894cee92284
--- /dev/null
+++ b/db/migrate/20201211145950_add_bloat_estimate_to_reindex_action.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddBloatEstimateToReindexAction < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :postgres_reindex_actions, :bloat_estimate_bytes_start, :bigint
+ end
+end
diff --git a/db/migrate/20201214084105_add_expiration_policy_completed_at_to_container_repositories.rb b/db/migrate/20201214084105_add_expiration_policy_completed_at_to_container_repositories.rb
new file mode 100644
index 00000000000..9e1f21068c2
--- /dev/null
+++ b/db/migrate/20201214084105_add_expiration_policy_completed_at_to_container_repositories.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+class AddExpirationPolicyCompletedAtToContainerRepositories < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ add_column(:container_repositories, :expiration_policy_completed_at, :datetime_with_timezone)
+ end
+
+ def down
+ remove_column(:container_repositories, :expiration_policy_completed_at)
+ end
+end
diff --git a/db/migrate/20201214113729_add_custom_mapping_columns_to_http_integrations.rb b/db/migrate/20201214113729_add_custom_mapping_columns_to_http_integrations.rb
new file mode 100644
index 00000000000..dbad28280ac
--- /dev/null
+++ b/db/migrate/20201214113729_add_custom_mapping_columns_to_http_integrations.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class AddCustomMappingColumnsToHttpIntegrations < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column :alert_management_http_integrations, :payload_example, :jsonb, null: false, default: {}
+ add_column :alert_management_http_integrations, :payload_attribute_mapping, :jsonb, null: false, default: {}
+ end
+end
diff --git a/db/migrate/20201215084652_delete_mock_deployment_service_records.rb b/db/migrate/20201215084652_delete_mock_deployment_service_records.rb
new file mode 100644
index 00000000000..6c601a5e852
--- /dev/null
+++ b/db/migrate/20201215084652_delete_mock_deployment_service_records.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DeleteMockDeploymentServiceRecords < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ if Rails.env.development?
+ execute("DELETE FROM services WHERE type = 'MockDeploymentService'")
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20201215132151_change_unique_index_on_security_findings.rb b/db/migrate/20201215132151_change_unique_index_on_security_findings.rb
new file mode 100644
index 00000000000..fe474ef3991
--- /dev/null
+++ b/db/migrate/20201215132151_change_unique_index_on_security_findings.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ChangeUniqueIndexOnSecurityFindings < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ OLD_INDEX_NAME = 'index_security_findings_on_uuid'
+ NEW_INDEX_NAME = 'index_security_findings_on_uuid_and_scan_id'
+
+ disable_ddl_transaction!
+
+ class SecurityFinding < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'security_findings'
+ end
+
+ def up
+ add_concurrent_index :security_findings, [:uuid, :scan_id], unique: true, name: NEW_INDEX_NAME
+
+ remove_concurrent_index_by_name :security_findings, OLD_INDEX_NAME
+ end
+
+ def down
+ # It is very unlikely that we rollback this migration but just in case if we have to,
+ # we have to clear the table because there can be multiple records with the same UUID
+ # which would break the creation of unique index on the `uuid` column.
+ # We choose clearing the table because just removing the duplicated records would
+ # cause data inconsistencies.
+ SecurityFinding.each_batch(of: 10000) { |relation| relation.delete_all }
+
+ add_concurrent_index :security_findings, :uuid, unique: true, name: OLD_INDEX_NAME
+
+ remove_concurrent_index_by_name :security_findings, NEW_INDEX_NAME
+ end
+end