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/20211008043855_remove_notes_trigram_index.rb15
-rw-r--r--db/migrate/20211011140930_create_ci_namespace_mirrors.rb15
-rw-r--r--db/migrate/20211011140931_create_ci_project_mirrors.rb12
-rw-r--r--db/migrate/20211011140932_create_namespaces_sync_events.rb9
-rw-r--r--db/migrate/20211011141239_create_projects_sync_events.rb9
-rw-r--r--db/migrate/20211011141242_create_namespaces_sync_trigger.rb37
-rw-r--r--db/migrate/20211011141243_create_projects_sync_trigger.rb37
-rw-r--r--db/migrate/20211101165656_create_upload_states.rb32
-rw-r--r--db/migrate/20211108204736_add_policy_idx_to_approval_project_rule.rb9
-rw-r--r--db/migrate/20211110014701_create_agent_activity_events.rb22
-rw-r--r--db/migrate/20211110015252_add_agent_activity_events_foreign_keys.rb35
-rw-r--r--db/migrate/20211110092710_create_issue_emails.rb21
-rw-r--r--db/migrate/20211111112425_create_merge_requests_compliance_violations.rb13
-rw-r--r--db/migrate/20211111112639_add_fk_compliance_violations_merge_request.rb18
-rw-r--r--db/migrate/20211111112713_add_fk_compliance_violations_violating_user.rb18
-rw-r--r--db/migrate/20211111164025_add_squash_commit_template_to_project_settings.rb9
-rw-r--r--db/migrate/20211111164047_add_squash_commit_template_limit_to_project_settings.rb13
-rw-r--r--db/migrate/20211112073413_change_package_index_on_corpus.rb19
-rw-r--r--db/migrate/20211115132613_create_incident_management_timeline_events.rb30
-rw-r--r--db/migrate/20211115142803_add_foreign_key_to_incident_management_timeline_events_on_project.rb15
-rw-r--r--db/migrate/20211115142847_add_foreign_key_to_incident_management_timeline_events_on_user.rb15
-rw-r--r--db/migrate/20211115142911_add_foreign_key_to_incident_management_timeline_events_on_issue.rb15
-rw-r--r--db/migrate/20211115145107_add_created_at_to_namespace_monthly_usages.rb17
-rw-r--r--db/migrate/20211115154103_add_created_at_to_project_monthly_usage.rb17
-rw-r--r--db/migrate/20211116093739_add_foreign_key_to_incident_management_timeline_events_on_updated_by_user.rb15
-rw-r--r--db/migrate/20211117174209_create_vulnerability_reads.rb24
-rw-r--r--db/migrate/20211118100959_change_default_value_of_loose_fk_deleted_records_partition.rb9
-rw-r--r--db/migrate/20211118103439_remove_hardcoded_partition_from_loose_fk_trigger_function.rb40
-rw-r--r--db/migrate/20211118114228_add_max_ssh_key_lifetime_to_application_settings.rb7
-rw-r--r--db/migrate/20211118124537_add_foreign_key_to_vulnerability_reads_on_vulnerability.rb15
-rw-r--r--db/migrate/20211118124628_add_foreign_key_to_vulnerability_reads_on_project.rb15
-rw-r--r--db/migrate/20211118124650_add_foreign_key_to_vulnerability_reads_on_scanner.rb15
-rw-r--r--db/migrate/20211119085015_add_orignal_filename_to_ci_job_artifact.rb16
-rw-r--r--db/migrate/20211119154221_create_pages_deployment_states.rb38
-rw-r--r--db/migrate/20211119170805_remove_test_report_requirement_issue_constraint.rb16
-rw-r--r--db/migrate/20211119194024_add_required_approval_count_to_protected_environments.rb7
-rw-r--r--db/migrate/20211119195201_create_deployment_approvals.rb13
-rw-r--r--db/migrate/20211122215001_add_policy_idx_to_approval_merge_request_rule.rb9
-rw-r--r--db/migrate/20211123181236_add_user_foreign_key_to_deployment_approvals.rb15
-rw-r--r--db/migrate/20211123182614_make_iteration_cadences_start_date_nullable.rb7
-rw-r--r--db/migrate/20211124132319_add_encrypted_static_objects_external_storage_auth_token.rb14
-rw-r--r--db/migrate/20211126042235_add_sequence_column_to_sprints_table.rb14
-rw-r--r--db/migrate/20211126113029_add_text_limit_for_static_objects_external_storage_auth_token.rb12
-rw-r--r--db/migrate/20211126115449_encrypt_static_objects_external_storage_auth_token.rb29
-rw-r--r--db/migrate/20211126142200_add_encrypted_static_object_token.rb16
-rw-r--r--db/migrate/20211126142354_add_text_limit_to_encrypted_static_object_token.rb13
-rw-r--r--db/migrate/20211126204445_add_task_to_work_item_types.rb31
-rw-r--r--db/migrate/20211129151155_add_migrated_to_new_structure_column_to_vulnerability_occurrences.rb7
-rw-r--r--db/migrate/20211129151832_add_index_on_vulnerability_occurrences_migrated_to_new_structure_column.rb15
-rw-r--r--db/migrate/20211130151724_add_foreign_key_to_incident_management_timeline_events_on_note.rb15
-rw-r--r--db/migrate/20211130205719_add_uniqueness_for_evidence_occurrence_id.rb18
-rw-r--r--db/migrate/20211201061733_add_future_subscriptions_to_application_settings.rb7
-rw-r--r--db/migrate/20211201143042_create_lfs_object_states.rb32
-rw-r--r--db/migrate/20211202041233_add_deployment_foreign_key_to_deployment_approvals.rb15
-rw-r--r--db/migrate/20211202094944_move_loose_fk_deleted_records_to_dynamic_schema.rb17
-rw-r--r--db/migrate/20211202135508_add_index_on_packages_build_infos_package_id_pipeline_id.rb18
-rw-r--r--db/migrate/20211204010826_add_index_snippets_on_project_id_and_title.rb15
-rw-r--r--db/migrate/20211207154413_add_ci_runners_index_on_created_at_where_active_is_false.rb15
-rw-r--r--db/migrate/20211207154414_add_ci_runners_index_on_contacted_at_where_active_is_false.rb15
-rw-r--r--db/migrate/20211207165508_add_protected_environments_required_approval_count_check_constraint.rb15
-rw-r--r--db/migrate/20211208111425_add_executor_type_column_to_ci_runners.rb7
-rw-r--r--db/migrate/20211213130324_update_timelogs_spent_at_default.rb7
-rw-r--r--db/migrate/20211214110307_remove_temp_index_from_vulnerability_occurrences.rb15
63 files changed, 1075 insertions, 0 deletions
diff --git a/db/migrate/20211008043855_remove_notes_trigram_index.rb b/db/migrate/20211008043855_remove_notes_trigram_index.rb
new file mode 100644
index 00000000000..a20ef1852e2
--- /dev/null
+++ b/db/migrate/20211008043855_remove_notes_trigram_index.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveNotesTrigramIndex < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ NOTES_TRIGRAM_INDEX_NAME = 'index_notes_on_note_trigram'
+
+ def up
+ remove_concurrent_index_by_name(:notes, NOTES_TRIGRAM_INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index :notes, :note, name: NOTES_TRIGRAM_INDEX_NAME, using: :gin, opclass: { content: :gin_trgm_ops }
+ end
+end
diff --git a/db/migrate/20211011140930_create_ci_namespace_mirrors.rb b/db/migrate/20211011140930_create_ci_namespace_mirrors.rb
new file mode 100644
index 00000000000..b9a708c5d7b
--- /dev/null
+++ b/db/migrate/20211011140930_create_ci_namespace_mirrors.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class CreateCiNamespaceMirrors < Gitlab::Database::Migration[1.0]
+ TABLE_NAME = :ci_namespace_mirrors
+ INDEX_NAME = "index_gin_#{TABLE_NAME}_on_traversal_ids"
+
+ def change
+ create_table TABLE_NAME do |t|
+ t.integer :namespace_id, null: false, index: { unique: true }
+ t.integer :traversal_ids, array: true, default: [], null: false
+
+ t.index :traversal_ids, name: INDEX_NAME, using: :gin
+ end
+ end
+end
diff --git a/db/migrate/20211011140931_create_ci_project_mirrors.rb b/db/migrate/20211011140931_create_ci_project_mirrors.rb
new file mode 100644
index 00000000000..2407b7e0b84
--- /dev/null
+++ b/db/migrate/20211011140931_create_ci_project_mirrors.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class CreateCiProjectMirrors < Gitlab::Database::Migration[1.0]
+ TABLE_NAME = :ci_project_mirrors
+
+ def change
+ create_table TABLE_NAME do |t|
+ t.integer :project_id, null: false, index: { unique: true }
+ t.integer :namespace_id, null: false, index: true
+ end
+ end
+end
diff --git a/db/migrate/20211011140932_create_namespaces_sync_events.rb b/db/migrate/20211011140932_create_namespaces_sync_events.rb
new file mode 100644
index 00000000000..06831423343
--- /dev/null
+++ b/db/migrate/20211011140932_create_namespaces_sync_events.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class CreateNamespacesSyncEvents < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :namespaces_sync_events do |t|
+ t.references :namespace, null: false, index: true, foreign_key: { on_delete: :cascade }
+ end
+ end
+end
diff --git a/db/migrate/20211011141239_create_projects_sync_events.rb b/db/migrate/20211011141239_create_projects_sync_events.rb
new file mode 100644
index 00000000000..50fe988ac1b
--- /dev/null
+++ b/db/migrate/20211011141239_create_projects_sync_events.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class CreateProjectsSyncEvents < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :projects_sync_events do |t|
+ t.references :project, null: false, index: true, foreign_key: { on_delete: :cascade }
+ end
+ end
+end
diff --git a/db/migrate/20211011141242_create_namespaces_sync_trigger.rb b/db/migrate/20211011141242_create_namespaces_sync_trigger.rb
new file mode 100644
index 00000000000..91f64709f28
--- /dev/null
+++ b/db/migrate/20211011141242_create_namespaces_sync_trigger.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class CreateNamespacesSyncTrigger < Gitlab::Database::Migration[1.0]
+ include Gitlab::Database::SchemaHelpers
+
+ enable_lock_retries!
+
+ TABLE_NAME = 'namespaces'
+ EVENT_TABLE_NAME = 'namespaces_sync_events'
+ FUNCTION_NAME = 'insert_namespaces_sync_event'
+ TRIGGER_ON_INSERT = 'trigger_namespaces_parent_id_on_insert'
+ TRIGGER_ON_UPDATE = 'trigger_namespaces_parent_id_on_update'
+
+ def up
+ create_trigger_function(FUNCTION_NAME) do
+ <<~SQL
+ INSERT INTO #{EVENT_TABLE_NAME} (namespace_id)
+ VALUES(COALESCE(NEW.id, OLD.id));
+ RETURN NULL;
+ SQL
+ end
+
+ create_trigger(TABLE_NAME, TRIGGER_ON_INSERT, FUNCTION_NAME, fires: 'AFTER INSERT')
+
+ create_trigger(TABLE_NAME, TRIGGER_ON_UPDATE, FUNCTION_NAME, fires: 'AFTER UPDATE') do
+ <<~SQL
+ WHEN (OLD.parent_id IS DISTINCT FROM NEW.parent_id)
+ SQL
+ end
+ end
+
+ def down
+ drop_trigger(TABLE_NAME, TRIGGER_ON_INSERT)
+ drop_trigger(TABLE_NAME, TRIGGER_ON_UPDATE)
+ drop_function(FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20211011141243_create_projects_sync_trigger.rb b/db/migrate/20211011141243_create_projects_sync_trigger.rb
new file mode 100644
index 00000000000..03b31c35a3a
--- /dev/null
+++ b/db/migrate/20211011141243_create_projects_sync_trigger.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class CreateProjectsSyncTrigger < Gitlab::Database::Migration[1.0]
+ include Gitlab::Database::SchemaHelpers
+
+ enable_lock_retries!
+
+ TABLE_NAME = 'projects'
+ EVENT_TABLE_NAME = 'projects_sync_events'
+ FUNCTION_NAME = 'insert_projects_sync_event'
+ TRIGGER_ON_INSERT = 'trigger_projects_parent_id_on_insert'
+ TRIGGER_ON_UPDATE = 'trigger_projects_parent_id_on_update'
+
+ def up
+ create_trigger_function(FUNCTION_NAME) do
+ <<~SQL
+ INSERT INTO #{EVENT_TABLE_NAME} (project_id)
+ VALUES(COALESCE(NEW.id, OLD.id));
+ RETURN NULL;
+ SQL
+ end
+
+ create_trigger(TABLE_NAME, TRIGGER_ON_INSERT, FUNCTION_NAME, fires: 'AFTER INSERT')
+
+ create_trigger(TABLE_NAME, TRIGGER_ON_UPDATE, FUNCTION_NAME, fires: 'AFTER UPDATE') do
+ <<~SQL
+ WHEN (OLD.namespace_id IS DISTINCT FROM NEW.namespace_id)
+ SQL
+ end
+ end
+
+ def down
+ drop_trigger(TABLE_NAME, TRIGGER_ON_INSERT)
+ drop_trigger(TABLE_NAME, TRIGGER_ON_UPDATE)
+ drop_function(FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20211101165656_create_upload_states.rb b/db/migrate/20211101165656_create_upload_states.rb
new file mode 100644
index 00000000000..64873f4c9a2
--- /dev/null
+++ b/db/migrate/20211101165656_create_upload_states.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class CreateUploadStates < Gitlab::Database::Migration[1.0]
+ VERIFICATION_STATE_INDEX_NAME = "index_upload_states_on_verification_state"
+ PENDING_VERIFICATION_INDEX_NAME = "index_upload_states_pending_verification"
+ FAILED_VERIFICATION_INDEX_NAME = "index_upload_states_failed_verification"
+ NEEDS_VERIFICATION_INDEX_NAME = "index_upload_states_needs_verification"
+
+ disable_ddl_transaction!
+
+ def up
+ create_table :upload_states, id: false do |t|
+ t.datetime_with_timezone :verification_started_at
+ t.datetime_with_timezone :verification_retry_at
+ t.datetime_with_timezone :verified_at
+ t.references :upload, primary_key: true, null: false, foreign_key: { on_delete: :cascade }
+ t.integer :verification_state, default: 0, limit: 2, null: false
+ t.integer :verification_retry_count, limit: 2
+ t.binary :verification_checksum, using: 'verification_checksum::bytea'
+ t.text :verification_failure, limit: 255
+
+ t.index :verification_state, name: VERIFICATION_STATE_INDEX_NAME
+ t.index :verified_at, where: "(verification_state = 0)", order: { verified_at: 'ASC NULLS FIRST' }, name: PENDING_VERIFICATION_INDEX_NAME
+ t.index :verification_retry_at, where: "(verification_state = 3)", order: { verification_retry_at: 'ASC NULLS FIRST' }, name: FAILED_VERIFICATION_INDEX_NAME
+ t.index :verification_state, where: "(verification_state = 0 OR verification_state = 3)", name: NEEDS_VERIFICATION_INDEX_NAME
+ end
+ end
+
+ def down
+ drop_table :upload_states
+ end
+end
diff --git a/db/migrate/20211108204736_add_policy_idx_to_approval_project_rule.rb b/db/migrate/20211108204736_add_policy_idx_to_approval_project_rule.rb
new file mode 100644
index 00000000000..90e5fa34817
--- /dev/null
+++ b/db/migrate/20211108204736_add_policy_idx_to_approval_project_rule.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddPolicyIdxToApprovalProjectRule < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def change
+ add_column :approval_project_rules, :orchestration_policy_idx, :integer, limit: 2
+ end
+end
diff --git a/db/migrate/20211110014701_create_agent_activity_events.rb b/db/migrate/20211110014701_create_agent_activity_events.rb
new file mode 100644
index 00000000000..11b9c6d03b3
--- /dev/null
+++ b/db/migrate/20211110014701_create_agent_activity_events.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class CreateAgentActivityEvents < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :agent_activity_events do |t|
+ t.bigint :agent_id, null: false
+ t.bigint :user_id, index: { where: 'user_id IS NOT NULL' }
+ t.bigint :project_id, index: { where: 'project_id IS NOT NULL' }
+ t.bigint :merge_request_id, index: { where: 'merge_request_id IS NOT NULL' }
+ t.bigint :agent_token_id, index: { where: 'agent_token_id IS NOT NULL' }
+
+ t.datetime_with_timezone :recorded_at, null: false
+ t.integer :kind, limit: 2, null: false
+ t.integer :level, limit: 2, null: false
+
+ t.binary :sha
+ t.text :detail, limit: 255
+
+ t.index [:agent_id, :recorded_at, :id]
+ end
+ end
+end
diff --git a/db/migrate/20211110015252_add_agent_activity_events_foreign_keys.rb b/db/migrate/20211110015252_add_agent_activity_events_foreign_keys.rb
new file mode 100644
index 00000000000..fcbafcccb06
--- /dev/null
+++ b/db/migrate/20211110015252_add_agent_activity_events_foreign_keys.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class AddAgentActivityEventsForeignKeys < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :agent_activity_events, :cluster_agents, column: :agent_id, on_delete: :cascade
+ add_concurrent_foreign_key :agent_activity_events, :users, column: :user_id, on_delete: :nullify
+ add_concurrent_foreign_key :agent_activity_events, :projects, column: :project_id, on_delete: :nullify
+ add_concurrent_foreign_key :agent_activity_events, :merge_requests, column: :merge_request_id, on_delete: :nullify
+ add_concurrent_foreign_key :agent_activity_events, :cluster_agent_tokens, column: :agent_token_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_activity_events, column: :agent_id
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_activity_events, column: :user_id
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_activity_events, column: :project_id
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_activity_events, column: :merge_request_id
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :agent_activity_events, column: :agent_token_id
+ end
+ end
+end
diff --git a/db/migrate/20211110092710_create_issue_emails.rb b/db/migrate/20211110092710_create_issue_emails.rb
new file mode 100644
index 00000000000..5f6104fa2c3
--- /dev/null
+++ b/db/migrate/20211110092710_create_issue_emails.rb
@@ -0,0 +1,21 @@
+# 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 CreateIssueEmails < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def up
+ create_table :issue_emails do |t|
+ t.references :issue, index: true, null: false, unique: true, foreign_key: { on_delete: :cascade }
+ t.text :email_message_id, null: false, limit: 1000
+
+ t.index :email_message_id
+ end
+ end
+
+ def down
+ drop_table :issue_emails
+ end
+end
diff --git a/db/migrate/20211111112425_create_merge_requests_compliance_violations.rb b/db/migrate/20211111112425_create_merge_requests_compliance_violations.rb
new file mode 100644
index 00000000000..064dc38f5b3
--- /dev/null
+++ b/db/migrate/20211111112425_create_merge_requests_compliance_violations.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class CreateMergeRequestsComplianceViolations < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :merge_requests_compliance_violations do |t|
+ t.bigint :violating_user_id, null: false
+ t.bigint :merge_request_id, null: false
+ t.integer :reason, limit: 2, null: false
+ t.index :violating_user_id
+ t.index [:merge_request_id, :violating_user_id, :reason], unique: true, name: 'index_merge_requests_compliance_violations_unique_columns'
+ end
+ end
+end
diff --git a/db/migrate/20211111112639_add_fk_compliance_violations_merge_request.rb b/db/migrate/20211111112639_add_fk_compliance_violations_merge_request.rb
new file mode 100644
index 00000000000..b280c35433b
--- /dev/null
+++ b/db/migrate/20211111112639_add_fk_compliance_violations_merge_request.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddFkComplianceViolationsMergeRequest < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :merge_requests_compliance_violations,
+ :merge_requests,
+ column: :merge_request_id,
+ on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :merge_requests_compliance_violations, column: :merge_request_id
+ end
+ end
+end
diff --git a/db/migrate/20211111112713_add_fk_compliance_violations_violating_user.rb b/db/migrate/20211111112713_add_fk_compliance_violations_violating_user.rb
new file mode 100644
index 00000000000..af1cd6f07ed
--- /dev/null
+++ b/db/migrate/20211111112713_add_fk_compliance_violations_violating_user.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddFkComplianceViolationsViolatingUser < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :merge_requests_compliance_violations,
+ :users,
+ column: :violating_user_id,
+ on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :merge_requests_compliance_violations, column: :violating_user_id
+ end
+ end
+end
diff --git a/db/migrate/20211111164025_add_squash_commit_template_to_project_settings.rb b/db/migrate/20211111164025_add_squash_commit_template_to_project_settings.rb
new file mode 100644
index 00000000000..6120a6ed0b4
--- /dev/null
+++ b/db/migrate/20211111164025_add_squash_commit_template_to_project_settings.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddSquashCommitTemplateToProjectSettings < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def change
+ add_column :project_settings, :squash_commit_template, :text # rubocop:disable Migration/AddLimitToTextColumns
+ end
+end
diff --git a/db/migrate/20211111164047_add_squash_commit_template_limit_to_project_settings.rb b/db/migrate/20211111164047_add_squash_commit_template_limit_to_project_settings.rb
new file mode 100644
index 00000000000..578d2271d60
--- /dev/null
+++ b/db/migrate/20211111164047_add_squash_commit_template_limit_to_project_settings.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddSquashCommitTemplateLimitToProjectSettings < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :project_settings, :squash_commit_template, 500
+ end
+
+ def down
+ remove_text_limit :project_settings, :squash_commit_template
+ end
+end
diff --git a/db/migrate/20211112073413_change_package_index_on_corpus.rb b/db/migrate/20211112073413_change_package_index_on_corpus.rb
new file mode 100644
index 00000000000..6e8222f853c
--- /dev/null
+++ b/db/migrate/20211112073413_change_package_index_on_corpus.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class ChangePackageIndexOnCorpus < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_coverage_fuzzing_corpuses_on_package_id'
+
+ disable_ddl_transaction!
+
+ # Changing this index is safe.
+ # The table does not have any data in it as it's behind a feature flag.
+ def up
+ remove_concurrent_index :coverage_fuzzing_corpuses, :package_id, name: INDEX_NAME
+ add_concurrent_index :coverage_fuzzing_corpuses, :package_id, unique: true, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :coverage_fuzzing_corpuses, :package_id, name: INDEX_NAME
+ add_concurrent_index :coverage_fuzzing_corpuses, :package_id, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211115132613_create_incident_management_timeline_events.rb b/db/migrate/20211115132613_create_incident_management_timeline_events.rb
new file mode 100644
index 00000000000..217dcd27b4c
--- /dev/null
+++ b/db/migrate/20211115132613_create_incident_management_timeline_events.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class CreateIncidentManagementTimelineEvents < Gitlab::Database::Migration[1.0]
+ def up
+ create_table :incident_management_timeline_events do |t|
+ t.timestamps_with_timezone null: false
+ t.datetime_with_timezone :occurred_at, null: false
+ t.bigint :project_id, null: false
+ t.bigint :author_id
+ t.bigint :issue_id, null: false
+ t.bigint :updated_by_user_id
+ t.bigint :promoted_from_note_id
+ t.integer :cached_markdown_version
+ t.boolean :editable, null: false, default: false
+ t.text :note, limit: 10_000, null: false
+ t.text :note_html, limit: 10_000, null: false
+ t.text :action, limit: 128, null: false
+
+ t.index :project_id, name: 'index_im_timeline_events_project_id'
+ t.index :author_id, name: 'index_im_timeline_events_author_id'
+ t.index :issue_id, name: 'index_im_timeline_events_issue_id'
+ t.index :updated_by_user_id, name: 'index_im_timeline_events_updated_by_user_id'
+ t.index :promoted_from_note_id, name: 'index_im_timeline_events_promoted_from_note_id'
+ end
+ end
+
+ def down
+ drop_table :incident_management_timeline_events
+ end
+end
diff --git a/db/migrate/20211115142803_add_foreign_key_to_incident_management_timeline_events_on_project.rb b/db/migrate/20211115142803_add_foreign_key_to_incident_management_timeline_events_on_project.rb
new file mode 100644
index 00000000000..893043cc1ab
--- /dev/null
+++ b/db/migrate/20211115142803_add_foreign_key_to_incident_management_timeline_events_on_project.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToIncidentManagementTimelineEventsOnProject < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :incident_management_timeline_events, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :incident_management_timeline_events, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20211115142847_add_foreign_key_to_incident_management_timeline_events_on_user.rb b/db/migrate/20211115142847_add_foreign_key_to_incident_management_timeline_events_on_user.rb
new file mode 100644
index 00000000000..0f5886eb5ed
--- /dev/null
+++ b/db/migrate/20211115142847_add_foreign_key_to_incident_management_timeline_events_on_user.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToIncidentManagementTimelineEventsOnUser < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :incident_management_timeline_events, :users, column: :author_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :incident_management_timeline_events, column: :author_id
+ end
+ end
+end
diff --git a/db/migrate/20211115142911_add_foreign_key_to_incident_management_timeline_events_on_issue.rb b/db/migrate/20211115142911_add_foreign_key_to_incident_management_timeline_events_on_issue.rb
new file mode 100644
index 00000000000..bdcf7f389d1
--- /dev/null
+++ b/db/migrate/20211115142911_add_foreign_key_to_incident_management_timeline_events_on_issue.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToIncidentManagementTimelineEventsOnIssue < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :incident_management_timeline_events, :issues, column: :issue_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :incident_management_timeline_events, column: :issue_id
+ end
+ end
+end
diff --git a/db/migrate/20211115145107_add_created_at_to_namespace_monthly_usages.rb b/db/migrate/20211115145107_add_created_at_to_namespace_monthly_usages.rb
new file mode 100644
index 00000000000..e0e2bec72ad
--- /dev/null
+++ b/db/migrate/20211115145107_add_created_at_to_namespace_monthly_usages.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddCreatedAtToNamespaceMonthlyUsages < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column :ci_namespace_monthly_usages, :created_at, :datetime_with_timezone
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :ci_namespace_monthly_usages, :created_at
+ end
+ end
+end
diff --git a/db/migrate/20211115154103_add_created_at_to_project_monthly_usage.rb b/db/migrate/20211115154103_add_created_at_to_project_monthly_usage.rb
new file mode 100644
index 00000000000..eb0cd448da3
--- /dev/null
+++ b/db/migrate/20211115154103_add_created_at_to_project_monthly_usage.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddCreatedAtToProjectMonthlyUsage < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ add_column :ci_project_monthly_usages, :created_at, :datetime_with_timezone
+ end
+ end
+
+ def down
+ with_lock_retries do
+ remove_column :ci_project_monthly_usages, :created_at
+ end
+ end
+end
diff --git a/db/migrate/20211116093739_add_foreign_key_to_incident_management_timeline_events_on_updated_by_user.rb b/db/migrate/20211116093739_add_foreign_key_to_incident_management_timeline_events_on_updated_by_user.rb
new file mode 100644
index 00000000000..a35020699fc
--- /dev/null
+++ b/db/migrate/20211116093739_add_foreign_key_to_incident_management_timeline_events_on_updated_by_user.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToIncidentManagementTimelineEventsOnUpdatedByUser < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :incident_management_timeline_events, :users, column: :updated_by_user_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :incident_management_timeline_events, column: :updated_by_user_id
+ end
+ end
+end
diff --git a/db/migrate/20211117174209_create_vulnerability_reads.rb b/db/migrate/20211117174209_create_vulnerability_reads.rb
new file mode 100644
index 00000000000..b9e32bfd0fa
--- /dev/null
+++ b/db/migrate/20211117174209_create_vulnerability_reads.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class CreateVulnerabilityReads < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :vulnerability_reads do |t|
+ t.bigint :vulnerability_id, null: false
+ t.bigint :project_id, null: false
+ t.bigint :scanner_id, null: false
+ t.integer :report_type, limit: 2, null: false
+ t.integer :severity, limit: 2, null: false
+ t.integer :state, limit: 2, null: false
+ t.boolean :has_issues, default: false, null: false
+ t.boolean :resolved_on_default_branch, default: false, null: false
+ t.uuid :uuid, null: false
+ t.text :location_image, limit: 2048
+
+ t.index :vulnerability_id, unique: true
+ t.index :scanner_id
+ t.index :uuid, unique: true
+ t.index [:project_id, :state, :severity, :vulnerability_id], name: :index_vuln_reads_on_project_id_state_severity_and_vuln_id, order: { vulnerability_id: :desc }
+ t.index :location_image, where: "report_type IN (2, 7)", name: :index_vulnerability_reads_on_location_image
+ end
+ end
+end
diff --git a/db/migrate/20211118100959_change_default_value_of_loose_fk_deleted_records_partition.rb b/db/migrate/20211118100959_change_default_value_of_loose_fk_deleted_records_partition.rb
new file mode 100644
index 00000000000..185178d8025
--- /dev/null
+++ b/db/migrate/20211118100959_change_default_value_of_loose_fk_deleted_records_partition.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class ChangeDefaultValueOfLooseFkDeletedRecordsPartition < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def change
+ change_column_default(:loose_foreign_keys_deleted_records, :partition, from: nil, to: 1)
+ end
+end
diff --git a/db/migrate/20211118103439_remove_hardcoded_partition_from_loose_fk_trigger_function.rb b/db/migrate/20211118103439_remove_hardcoded_partition_from_loose_fk_trigger_function.rb
new file mode 100644
index 00000000000..33159167b19
--- /dev/null
+++ b/db/migrate/20211118103439_remove_hardcoded_partition_from_loose_fk_trigger_function.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class RemoveHardcodedPartitionFromLooseFkTriggerFunction < Gitlab::Database::Migration[1.0]
+ include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
+
+ enable_lock_retries!
+
+ def up
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION #{DELETED_RECORDS_INSERT_FUNCTION_NAME}()
+ RETURNS TRIGGER AS
+ $$
+ BEGIN
+ INSERT INTO loose_foreign_keys_deleted_records
+ (fully_qualified_table_name, primary_key_value)
+ SELECT TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table;
+
+ RETURN NULL;
+ END
+ $$ LANGUAGE PLPGSQL
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION #{DELETED_RECORDS_INSERT_FUNCTION_NAME}()
+ RETURNS TRIGGER AS
+ $$
+ BEGIN
+ INSERT INTO loose_foreign_keys_deleted_records
+ (partition, fully_qualified_table_name, primary_key_value)
+ SELECT 1, TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table
+ ON CONFLICT DO NOTHING;
+
+ RETURN NULL;
+ END
+ $$ LANGUAGE PLPGSQL
+ SQL
+ end
+end
diff --git a/db/migrate/20211118114228_add_max_ssh_key_lifetime_to_application_settings.rb b/db/migrate/20211118114228_add_max_ssh_key_lifetime_to_application_settings.rb
new file mode 100644
index 00000000000..1b0d2104c91
--- /dev/null
+++ b/db/migrate/20211118114228_add_max_ssh_key_lifetime_to_application_settings.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddMaxSshKeyLifetimeToApplicationSettings < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :application_settings, :max_ssh_key_lifetime, :integer
+ end
+end
diff --git a/db/migrate/20211118124537_add_foreign_key_to_vulnerability_reads_on_vulnerability.rb b/db/migrate/20211118124537_add_foreign_key_to_vulnerability_reads_on_vulnerability.rb
new file mode 100644
index 00000000000..dd5b0bdc028
--- /dev/null
+++ b/db/migrate/20211118124537_add_foreign_key_to_vulnerability_reads_on_vulnerability.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToVulnerabilityReadsOnVulnerability < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :vulnerability_reads, :vulnerabilities, column: :vulnerability_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :vulnerability_reads, column: :vulnerability_id
+ end
+ end
+end
diff --git a/db/migrate/20211118124628_add_foreign_key_to_vulnerability_reads_on_project.rb b/db/migrate/20211118124628_add_foreign_key_to_vulnerability_reads_on_project.rb
new file mode 100644
index 00000000000..14dde371e3d
--- /dev/null
+++ b/db/migrate/20211118124628_add_foreign_key_to_vulnerability_reads_on_project.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToVulnerabilityReadsOnProject < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :vulnerability_reads, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :vulnerability_reads, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20211118124650_add_foreign_key_to_vulnerability_reads_on_scanner.rb b/db/migrate/20211118124650_add_foreign_key_to_vulnerability_reads_on_scanner.rb
new file mode 100644
index 00000000000..923e62a4beb
--- /dev/null
+++ b/db/migrate/20211118124650_add_foreign_key_to_vulnerability_reads_on_scanner.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToVulnerabilityReadsOnScanner < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :vulnerability_reads, :vulnerability_scanners, column: :scanner_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :vulnerability_reads, column: :scanner_id
+ end
+ end
+end
diff --git a/db/migrate/20211119085015_add_orignal_filename_to_ci_job_artifact.rb b/db/migrate/20211119085015_add_orignal_filename_to_ci_job_artifact.rb
new file mode 100644
index 00000000000..f52bc346d16
--- /dev/null
+++ b/db/migrate/20211119085015_add_orignal_filename_to_ci_job_artifact.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddOrignalFilenameToCiJobArtifact < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20211119085036_add_text_limit_to_job_artifact_original_filename.rb
+ def up
+ add_column :ci_job_artifacts, :original_filename, :text
+ end
+ # rubocop:enable Migration/AddLimitToTextColumns
+
+ def down
+ remove_column :ci_job_artifacts, :original_filename, :text
+ end
+end
diff --git a/db/migrate/20211119154221_create_pages_deployment_states.rb b/db/migrate/20211119154221_create_pages_deployment_states.rb
new file mode 100644
index 00000000000..283f6c7d0d7
--- /dev/null
+++ b/db/migrate/20211119154221_create_pages_deployment_states.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class CreatePagesDeploymentStates < Gitlab::Database::Migration[1.0]
+ VERIFICATION_STATE_INDEX_NAME = "index_pages_deployment_states_on_verification_state"
+ PENDING_VERIFICATION_INDEX_NAME = "index_pages_deployment_states_pending_verification"
+ FAILED_VERIFICATION_INDEX_NAME = "index_pages_deployment_states_failed_verification"
+ NEEDS_VERIFICATION_INDEX_NAME = "index_pages_deployment_states_needs_verification"
+
+ disable_ddl_transaction!
+
+ def up
+ unless table_exists?(:pages_deployment_states)
+ with_lock_retries do
+ create_table :pages_deployment_states, id: false do |t|
+ t.references :pages_deployment, primary_key: true, null: false, foreign_key: { on_delete: :cascade }
+ t.integer :verification_state, default: 0, limit: 2, null: false
+ t.column :verification_started_at, :datetime_with_timezone
+ t.datetime_with_timezone :verification_retry_at
+ t.datetime_with_timezone :verified_at
+ t.integer :verification_retry_count, limit: 2
+ t.binary :verification_checksum, using: 'verification_checksum::bytea'
+ t.text :verification_failure
+
+ t.index :verification_state, name: VERIFICATION_STATE_INDEX_NAME
+ t.index :verified_at, where: "(verification_state = 0)", order: { verified_at: 'ASC NULLS FIRST' }, name: PENDING_VERIFICATION_INDEX_NAME
+ t.index :verification_retry_at, where: "(verification_state = 3)", order: { verification_retry_at: 'ASC NULLS FIRST' }, name: FAILED_VERIFICATION_INDEX_NAME
+ t.index :verification_state, where: "(verification_state = 0 OR verification_state = 3)", name: NEEDS_VERIFICATION_INDEX_NAME
+ end
+ end
+ end
+
+ add_text_limit :pages_deployment_states, :verification_failure, 255
+ end
+
+ def down
+ drop_table :pages_deployment_states
+ end
+end
diff --git a/db/migrate/20211119170805_remove_test_report_requirement_issue_constraint.rb b/db/migrate/20211119170805_remove_test_report_requirement_issue_constraint.rb
new file mode 100644
index 00000000000..9064242ee30
--- /dev/null
+++ b/db/migrate/20211119170805_remove_test_report_requirement_issue_constraint.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveTestReportRequirementIssueConstraint < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ TARGET_TABLE = :requirements_management_test_reports
+ CONSTRAINT_NAME = 'requirements_test_reports_requirement_id_xor_issue_id'
+
+ def up
+ remove_check_constraint TARGET_TABLE, CONSTRAINT_NAME
+ end
+
+ def down
+ add_check_constraint(TARGET_TABLE, 'num_nonnulls(requirement_id, issue_id) = 1', CONSTRAINT_NAME)
+ end
+end
diff --git a/db/migrate/20211119194024_add_required_approval_count_to_protected_environments.rb b/db/migrate/20211119194024_add_required_approval_count_to_protected_environments.rb
new file mode 100644
index 00000000000..ca6b78efbc7
--- /dev/null
+++ b/db/migrate/20211119194024_add_required_approval_count_to_protected_environments.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddRequiredApprovalCountToProtectedEnvironments < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :protected_environments, :required_approval_count, :integer, default: 0, null: false
+ end
+end
diff --git a/db/migrate/20211119195201_create_deployment_approvals.rb b/db/migrate/20211119195201_create_deployment_approvals.rb
new file mode 100644
index 00000000000..a238da302f9
--- /dev/null
+++ b/db/migrate/20211119195201_create_deployment_approvals.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class CreateDeploymentApprovals < Gitlab::Database::Migration[1.0]
+ def change
+ create_table :deployment_approvals do |t|
+ t.bigint :deployment_id, null: false
+ t.bigint :user_id, null: false, index: true
+ t.timestamps_with_timezone null: false
+ t.integer :status, limit: 2, null: false
+ t.index [:deployment_id, :user_id], unique: true
+ end
+ end
+end
diff --git a/db/migrate/20211122215001_add_policy_idx_to_approval_merge_request_rule.rb b/db/migrate/20211122215001_add_policy_idx_to_approval_merge_request_rule.rb
new file mode 100644
index 00000000000..b1c7bc4d5ce
--- /dev/null
+++ b/db/migrate/20211122215001_add_policy_idx_to_approval_merge_request_rule.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddPolicyIdxToApprovalMergeRequestRule < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def change
+ add_column :approval_merge_request_rules, :orchestration_policy_idx, :integer, limit: 2
+ end
+end
diff --git a/db/migrate/20211123181236_add_user_foreign_key_to_deployment_approvals.rb b/db/migrate/20211123181236_add_user_foreign_key_to_deployment_approvals.rb
new file mode 100644
index 00000000000..da20e9a8f8e
--- /dev/null
+++ b/db/migrate/20211123181236_add_user_foreign_key_to_deployment_approvals.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddUserForeignKeyToDeploymentApprovals < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :deployment_approvals, :users, column: :user_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :deployment_approvals, :users
+ end
+ end
+end
diff --git a/db/migrate/20211123182614_make_iteration_cadences_start_date_nullable.rb b/db/migrate/20211123182614_make_iteration_cadences_start_date_nullable.rb
new file mode 100644
index 00000000000..10a0c6ca402
--- /dev/null
+++ b/db/migrate/20211123182614_make_iteration_cadences_start_date_nullable.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class MakeIterationCadencesStartDateNullable < Gitlab::Database::Migration[1.0]
+ def change
+ change_column_null :iterations_cadences, :start_date, true
+ end
+end
diff --git a/db/migrate/20211124132319_add_encrypted_static_objects_external_storage_auth_token.rb b/db/migrate/20211124132319_add_encrypted_static_objects_external_storage_auth_token.rb
new file mode 100644
index 00000000000..868bc4f14f2
--- /dev/null
+++ b/db/migrate/20211124132319_add_encrypted_static_objects_external_storage_auth_token.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddEncryptedStaticObjectsExternalStorageAuthToken < Gitlab::Database::Migration[1.0]
+ def up
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20211126113029_add_text_limit_for_static_objects_external_storage_auth_token
+ add_column :application_settings, :static_objects_external_storage_auth_token_encrypted, :text
+ # rubocop:enable Migration/AddLimitToTextColumns
+ end
+
+ def down
+ remove_column :application_settings, :static_objects_external_storage_auth_token_encrypted
+ end
+end
diff --git a/db/migrate/20211126042235_add_sequence_column_to_sprints_table.rb b/db/migrate/20211126042235_add_sequence_column_to_sprints_table.rb
new file mode 100644
index 00000000000..cbe5dbf99fc
--- /dev/null
+++ b/db/migrate/20211126042235_add_sequence_column_to_sprints_table.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddSequenceColumnToSprintsTable < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def up
+ add_column :sprints, :sequence, :integer
+ execute "ALTER TABLE sprints ADD CONSTRAINT sequence_is_unique_per_iterations_cadence_id UNIQUE (iterations_cadence_id, sequence) DEFERRABLE INITIALLY DEFERRED"
+ end
+
+ def down
+ remove_column :sprints, :sequence
+ end
+end
diff --git a/db/migrate/20211126113029_add_text_limit_for_static_objects_external_storage_auth_token.rb b/db/migrate/20211126113029_add_text_limit_for_static_objects_external_storage_auth_token.rb
new file mode 100644
index 00000000000..45c4686e674
--- /dev/null
+++ b/db/migrate/20211126113029_add_text_limit_for_static_objects_external_storage_auth_token.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+class AddTextLimitForStaticObjectsExternalStorageAuthToken < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :application_settings, :static_objects_external_storage_auth_token_encrypted, 255
+ end
+
+ def down
+ remove_text_limit :application_settings, :static_objects_external_storage_auth_token_encrypted
+ end
+end
diff --git a/db/migrate/20211126115449_encrypt_static_objects_external_storage_auth_token.rb b/db/migrate/20211126115449_encrypt_static_objects_external_storage_auth_token.rb
new file mode 100644
index 00000000000..9ce034b0065
--- /dev/null
+++ b/db/migrate/20211126115449_encrypt_static_objects_external_storage_auth_token.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class EncryptStaticObjectsExternalStorageAuthToken < Gitlab::Database::Migration[1.0]
+ class ApplicationSetting < ActiveRecord::Base
+ self.table_name = 'application_settings'
+
+ scope :encrypted_token_is_null, -> { where(static_objects_external_storage_auth_token_encrypted: nil) }
+ scope :encrypted_token_is_not_null, -> { where.not(static_objects_external_storage_auth_token_encrypted: nil) }
+ scope :plaintext_token_is_not_null, -> { where.not(static_objects_external_storage_auth_token: nil) }
+ end
+
+ def up
+ ApplicationSetting.reset_column_information
+
+ ApplicationSetting.encrypted_token_is_null.plaintext_token_is_not_null.find_each do |application_setting|
+ token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(application_setting.static_objects_external_storage_auth_token)
+ application_setting.update!(static_objects_external_storage_auth_token_encrypted: token_encrypted)
+ end
+ end
+
+ def down
+ ApplicationSetting.reset_column_information
+
+ ApplicationSetting.encrypted_token_is_not_null.find_each do |application_setting|
+ token = Gitlab::CryptoHelper.aes256_gcm_decrypt(application_setting.static_objects_external_storage_auth_token_encrypted)
+ application_setting.update!(static_objects_external_storage_auth_token: token, static_objects_external_storage_auth_token_encrypted: nil)
+ end
+ end
+end
diff --git a/db/migrate/20211126142200_add_encrypted_static_object_token.rb b/db/migrate/20211126142200_add_encrypted_static_object_token.rb
new file mode 100644
index 00000000000..839354244e7
--- /dev/null
+++ b/db/migrate/20211126142200_add_encrypted_static_object_token.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddEncryptedStaticObjectToken < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def up
+ # rubocop:disable Migration/AddLimitToTextColumns
+ # limit is added in 20211126142354_add_text_limit_to_encrypted_static_object_token
+ add_column :users, :static_object_token_encrypted, :text # rubocop:disable Migration/AddColumnsToWideTables
+ # rubocop:enable Migration/AddLimitToTextColumns
+ end
+
+ def down
+ remove_column :users, :static_object_token_encrypted
+ end
+end
diff --git a/db/migrate/20211126142354_add_text_limit_to_encrypted_static_object_token.rb b/db/migrate/20211126142354_add_text_limit_to_encrypted_static_object_token.rb
new file mode 100644
index 00000000000..a43e7d9a741
--- /dev/null
+++ b/db/migrate/20211126142354_add_text_limit_to_encrypted_static_object_token.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddTextLimitToEncryptedStaticObjectToken < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_text_limit :users, :static_object_token_encrypted, 255
+ end
+
+ def down
+ remove_text_limit :users, :static_object_token_encrypted
+ end
+end
diff --git a/db/migrate/20211126204445_add_task_to_work_item_types.rb b/db/migrate/20211126204445_add_task_to_work_item_types.rb
new file mode 100644
index 00000000000..875c2272c6d
--- /dev/null
+++ b/db/migrate/20211126204445_add_task_to_work_item_types.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class AddTaskToWorkItemTypes < Gitlab::Database::Migration[1.0]
+ TASK_ENUM_VALUE = 4
+
+ class WorkItemType < ActiveRecord::Base
+ self.inheritance_column = :_type_disabled
+ self.table_name = 'work_item_types'
+
+ validates :name, uniqueness: { case_sensitive: false, scope: [:namespace_id] }
+ end
+
+ def up
+ # New instances will not run this migration and add this type via fixtures
+ # checking if record exists mostly because migration specs will run all migrations
+ # and that will conflict with the preloaded base work item types
+ task_work_item = WorkItemType.find_by(name: 'Task', namespace_id: nil)
+
+ if task_work_item
+ say('Task item record exist, skipping creation')
+ else
+ WorkItemType.create(name: 'Task', namespace_id: nil, base_type: TASK_ENUM_VALUE, icon_name: 'issue-type-task')
+ end
+ end
+
+ def down
+ # There's the remote possibility that issues could already be
+ # using this issue type, with a tight foreign constraint.
+ # Therefore we will not attempt to remove any data.
+ end
+end
diff --git a/db/migrate/20211129151155_add_migrated_to_new_structure_column_to_vulnerability_occurrences.rb b/db/migrate/20211129151155_add_migrated_to_new_structure_column_to_vulnerability_occurrences.rb
new file mode 100644
index 00000000000..8c3cf82d7c7
--- /dev/null
+++ b/db/migrate/20211129151155_add_migrated_to_new_structure_column_to_vulnerability_occurrences.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddMigratedToNewStructureColumnToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :vulnerability_occurrences, :migrated_to_new_structure, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20211129151832_add_index_on_vulnerability_occurrences_migrated_to_new_structure_column.rb b/db/migrate/20211129151832_add_index_on_vulnerability_occurrences_migrated_to_new_structure_column.rb
new file mode 100644
index 00000000000..4cf8263f8f0
--- /dev/null
+++ b/db/migrate/20211129151832_add_index_on_vulnerability_occurrences_migrated_to_new_structure_column.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexOnVulnerabilityOccurrencesMigratedToNewStructureColumn < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_vulnerability_occurrences_on_migrated_to_new_structure'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerability_occurrences, [:migrated_to_new_structure, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211130151724_add_foreign_key_to_incident_management_timeline_events_on_note.rb b/db/migrate/20211130151724_add_foreign_key_to_incident_management_timeline_events_on_note.rb
new file mode 100644
index 00000000000..a09409900f7
--- /dev/null
+++ b/db/migrate/20211130151724_add_foreign_key_to_incident_management_timeline_events_on_note.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToIncidentManagementTimelineEventsOnNote < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :incident_management_timeline_events, :notes, column: :promoted_from_note_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :incident_management_timeline_events, column: :promoted_from_note_id
+ end
+ end
+end
diff --git a/db/migrate/20211130205719_add_uniqueness_for_evidence_occurrence_id.rb b/db/migrate/20211130205719_add_uniqueness_for_evidence_occurrence_id.rb
new file mode 100644
index 00000000000..1aca3e7e8e2
--- /dev/null
+++ b/db/migrate/20211130205719_add_uniqueness_for_evidence_occurrence_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddUniquenessForEvidenceOccurrenceId < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'finding_evidences_on_vulnerability_occurrence_id'
+ UNIQUE_INDEX_NAME = 'finding_evidences_on_unique_vulnerability_occurrence_id'
+
+ def up
+ add_concurrent_index :vulnerability_finding_evidences, [:vulnerability_occurrence_id], unique: true, name: UNIQUE_INDEX_NAME
+ remove_concurrent_index :vulnerability_finding_evidences, [:vulnerability_occurrence_id], name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :vulnerability_finding_evidences, [:vulnerability_occurrence_id], name: INDEX_NAME
+ remove_concurrent_index :vulnerability_finding_evidences, [:vulnerability_occurrence_id], name: UNIQUE_INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211201061733_add_future_subscriptions_to_application_settings.rb b/db/migrate/20211201061733_add_future_subscriptions_to_application_settings.rb
new file mode 100644
index 00000000000..9cbbef42327
--- /dev/null
+++ b/db/migrate/20211201061733_add_future_subscriptions_to_application_settings.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddFutureSubscriptionsToApplicationSettings < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :application_settings, :future_subscriptions, :jsonb, null: false, default: []
+ end
+end
diff --git a/db/migrate/20211201143042_create_lfs_object_states.rb b/db/migrate/20211201143042_create_lfs_object_states.rb
new file mode 100644
index 00000000000..91accbcd438
--- /dev/null
+++ b/db/migrate/20211201143042_create_lfs_object_states.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class CreateLfsObjectStates < Gitlab::Database::Migration[1.0]
+ VERIFICATION_STATE_INDEX_NAME = "index_lfs_object_states_on_verification_state"
+ PENDING_VERIFICATION_INDEX_NAME = "index_lfs_object_states_pending_verification"
+ FAILED_VERIFICATION_INDEX_NAME = "index_lfs_object_states_failed_verification"
+ NEEDS_VERIFICATION_INDEX_NAME = "index_lfs_object_states_needs_verification"
+
+ disable_ddl_transaction!
+
+ def up
+ create_table :lfs_object_states, id: false do |t|
+ t.datetime_with_timezone :verification_started_at
+ t.datetime_with_timezone :verification_retry_at
+ t.datetime_with_timezone :verified_at
+ t.references :lfs_object, primary_key: true, null: false, foreign_key: { on_delete: :cascade }
+ t.integer :verification_state, default: 0, limit: 2, null: false
+ t.integer :verification_retry_count, limit: 2
+ t.binary :verification_checksum, using: 'verification_checksum::bytea'
+ t.text :verification_failure, limit: 255
+
+ t.index :verification_state, name: VERIFICATION_STATE_INDEX_NAME
+ t.index :verified_at, where: "(verification_state = 0)", order: { verified_at: 'ASC NULLS FIRST' }, name: PENDING_VERIFICATION_INDEX_NAME
+ t.index :verification_retry_at, where: "(verification_state = 3)", order: { verification_retry_at: 'ASC NULLS FIRST' }, name: FAILED_VERIFICATION_INDEX_NAME
+ t.index :verification_state, where: "(verification_state = 0 OR verification_state = 3)", name: NEEDS_VERIFICATION_INDEX_NAME
+ end
+ end
+
+ def down
+ drop_table :lfs_object_states
+ end
+end
diff --git a/db/migrate/20211202041233_add_deployment_foreign_key_to_deployment_approvals.rb b/db/migrate/20211202041233_add_deployment_foreign_key_to_deployment_approvals.rb
new file mode 100644
index 00000000000..60bc892d792
--- /dev/null
+++ b/db/migrate/20211202041233_add_deployment_foreign_key_to_deployment_approvals.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddDeploymentForeignKeyToDeploymentApprovals < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :deployment_approvals, :deployments, column: :deployment_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :deployment_approvals, :deployments
+ end
+ end
+end
diff --git a/db/migrate/20211202094944_move_loose_fk_deleted_records_to_dynamic_schema.rb b/db/migrate/20211202094944_move_loose_fk_deleted_records_to_dynamic_schema.rb
new file mode 100644
index 00000000000..84bc551d2b5
--- /dev/null
+++ b/db/migrate/20211202094944_move_loose_fk_deleted_records_to_dynamic_schema.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class MoveLooseFkDeletedRecordsToDynamicSchema < Gitlab::Database::Migration[1.0]
+ enable_lock_retries!
+
+ def up
+ if table_exists?('gitlab_partitions_static.loose_foreign_keys_deleted_records_1')
+ execute 'ALTER TABLE gitlab_partitions_static.loose_foreign_keys_deleted_records_1 SET SCHEMA gitlab_partitions_dynamic'
+ end
+ end
+
+ def down
+ if table_exists?('gitlab_partitions_dynamic.loose_foreign_keys_deleted_records_1')
+ execute 'ALTER TABLE gitlab_partitions_dynamic.loose_foreign_keys_deleted_records_1 SET SCHEMA gitlab_partitions_static'
+ end
+ end
+end
diff --git a/db/migrate/20211202135508_add_index_on_packages_build_infos_package_id_pipeline_id.rb b/db/migrate/20211202135508_add_index_on_packages_build_infos_package_id_pipeline_id.rb
new file mode 100644
index 00000000000..47a155d40fa
--- /dev/null
+++ b/db/migrate/20211202135508_add_index_on_packages_build_infos_package_id_pipeline_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexOnPackagesBuildInfosPackageIdPipelineId < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_packages_build_infos_package_id_pipeline_id'
+ OLD_INDEX_NAME = 'idx_packages_build_infos_on_package_id'
+
+ def up
+ add_concurrent_index :packages_build_infos, [:package_id, :pipeline_id], name: INDEX_NAME
+ remove_concurrent_index_by_name :packages_build_infos, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :packages_build_infos, :package_id, name: OLD_INDEX_NAME
+ remove_concurrent_index :packages_build_infos, [:package_id, :pipeline_id], name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211204010826_add_index_snippets_on_project_id_and_title.rb b/db/migrate/20211204010826_add_index_snippets_on_project_id_and_title.rb
new file mode 100644
index 00000000000..35a3a98030a
--- /dev/null
+++ b/db/migrate/20211204010826_add_index_snippets_on_project_id_and_title.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexSnippetsOnProjectIdAndTitle < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_snippets_on_project_id_and_title'
+
+ def up
+ add_concurrent_index :snippets, [:project_id, :title], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :snippets, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211207154413_add_ci_runners_index_on_created_at_where_active_is_false.rb b/db/migrate/20211207154413_add_ci_runners_index_on_created_at_where_active_is_false.rb
new file mode 100644
index 00000000000..da391da33ec
--- /dev/null
+++ b/db/migrate/20211207154413_add_ci_runners_index_on_created_at_where_active_is_false.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddCiRunnersIndexOnCreatedAtWhereActiveIsFalse < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_ci_runners_on_created_at_and_id_where_inactive'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :ci_runners, [:created_at, :id], where: 'active = FALSE', order: { created_at: :desc, id: :desc }, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_runners, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211207154414_add_ci_runners_index_on_contacted_at_where_active_is_false.rb b/db/migrate/20211207154414_add_ci_runners_index_on_contacted_at_where_active_is_false.rb
new file mode 100644
index 00000000000..e25d3c0dffa
--- /dev/null
+++ b/db/migrate/20211207154414_add_ci_runners_index_on_contacted_at_where_active_is_false.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddCiRunnersIndexOnContactedAtWhereActiveIsFalse < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_ci_runners_on_contacted_at_and_id_where_inactive'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :ci_runners, [:contacted_at, :id], where: 'active = FALSE', order: { contacted_at: :desc, id: :desc }, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_runners, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20211207165508_add_protected_environments_required_approval_count_check_constraint.rb b/db/migrate/20211207165508_add_protected_environments_required_approval_count_check_constraint.rb
new file mode 100644
index 00000000000..fb1339cecfa
--- /dev/null
+++ b/db/migrate/20211207165508_add_protected_environments_required_approval_count_check_constraint.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddProtectedEnvironmentsRequiredApprovalCountCheckConstraint < Gitlab::Database::Migration[1.0]
+ CONSTRAINT_NAME = 'protected_environments_required_approval_count_positive'
+
+ disable_ddl_transaction!
+
+ def up
+ add_check_constraint :protected_environments, 'required_approval_count >= 0', CONSTRAINT_NAME
+ end
+
+ def down
+ remove_check_constraint :protected_environments, CONSTRAINT_NAME
+ end
+end
diff --git a/db/migrate/20211208111425_add_executor_type_column_to_ci_runners.rb b/db/migrate/20211208111425_add_executor_type_column_to_ci_runners.rb
new file mode 100644
index 00000000000..1e1fdbdb122
--- /dev/null
+++ b/db/migrate/20211208111425_add_executor_type_column_to_ci_runners.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddExecutorTypeColumnToCiRunners < Gitlab::Database::Migration[1.0]
+ def change
+ add_column :ci_runners, :executor_type, :smallint, null: true
+ end
+end
diff --git a/db/migrate/20211213130324_update_timelogs_spent_at_default.rb b/db/migrate/20211213130324_update_timelogs_spent_at_default.rb
new file mode 100644
index 00000000000..f90b19b5f68
--- /dev/null
+++ b/db/migrate/20211213130324_update_timelogs_spent_at_default.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class UpdateTimelogsSpentAtDefault < Gitlab::Database::Migration[1.0]
+ def change
+ change_column_default(:timelogs, :spent_at, from: nil, to: -> { 'NOW()' })
+ end
+end
diff --git a/db/migrate/20211214110307_remove_temp_index_from_vulnerability_occurrences.rb b/db/migrate/20211214110307_remove_temp_index_from_vulnerability_occurrences.rb
new file mode 100644
index 00000000000..99f985d528c
--- /dev/null
+++ b/db/migrate/20211214110307_remove_temp_index_from_vulnerability_occurrences.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveTempIndexFromVulnerabilityOccurrences < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'vulnerability_occurrences_location_temp_index'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :vulnerability_occurrences, name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :vulnerability_occurrences, :id, where: 'location IS NULL', name: INDEX_NAME
+ end
+end