diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /db/migrate | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'db/migrate')
92 files changed, 1527 insertions, 12 deletions
diff --git a/db/migrate/20190402150158_backport_enterprise_schema.rb b/db/migrate/20190402150158_backport_enterprise_schema.rb index c4fbb4b2ab9..ba5f700a877 100644 --- a/db/migrate/20190402150158_backport_enterprise_schema.rb +++ b/db/migrate/20190402150158_backport_enterprise_schema.rb @@ -914,7 +914,7 @@ class BackportEnterpriseSchema < ActiveRecord::Migration[5.0] MSG end - raise StandardError.new(message) + raise StandardError, message end def create_missing_tables diff --git a/db/migrate/20190801060809_delete_kubernetes_services.rb b/db/migrate/20190801060809_delete_kubernetes_services.rb index 018976584d4..88717293817 100644 --- a/db/migrate/20190801060809_delete_kubernetes_services.rb +++ b/db/migrate/20190801060809_delete_kubernetes_services.rb @@ -3,6 +3,11 @@ class DeleteKubernetesServices < ActiveRecord::Migration[5.2] DOWNTIME = false + class Service < ActiveRecord::Base + self.table_name = 'services' + self.inheritance_column = :_type_disabled + end + def up Service.where(type: "KubernetesService").delete_all end diff --git a/db/migrate/20191120115530_encrypt_plaintext_attributes_on_application_settings.rb b/db/migrate/20191120115530_encrypt_plaintext_attributes_on_application_settings.rb index e6b9a40ad4f..3ae5e3265e8 100644 --- a/db/migrate/20191120115530_encrypt_plaintext_attributes_on_application_settings.rb +++ b/db/migrate/20191120115530_encrypt_plaintext_attributes_on_application_settings.rb @@ -17,21 +17,21 @@ class EncryptPlaintextAttributesOnApplicationSettings < ActiveRecord::Migration[ class ApplicationSetting < ActiveRecord::Base self.table_name = 'application_settings' - def self.encryption_options_base_truncated_aes_256_gcm + def self.encryption_options_base_32_aes_256_gcm { mode: :per_attribute_iv, - key: Gitlab::Application.secrets.db_key_base[0..31], + key: Gitlab::Utils.ensure_utf8_size(Rails.application.secrets.db_key_base, bytes: 32.bytes), algorithm: 'aes-256-gcm', encode: true } end - attr_encrypted :akismet_api_key, encryption_options_base_truncated_aes_256_gcm - attr_encrypted :elasticsearch_aws_secret_access_key, encryption_options_base_truncated_aes_256_gcm - attr_encrypted :recaptcha_private_key, encryption_options_base_truncated_aes_256_gcm - attr_encrypted :recaptcha_site_key, encryption_options_base_truncated_aes_256_gcm - attr_encrypted :slack_app_secret, encryption_options_base_truncated_aes_256_gcm - attr_encrypted :slack_app_verification_token, encryption_options_base_truncated_aes_256_gcm + attr_encrypted :akismet_api_key, encryption_options_base_32_aes_256_gcm + attr_encrypted :elasticsearch_aws_secret_access_key, encryption_options_base_32_aes_256_gcm + attr_encrypted :recaptcha_private_key, encryption_options_base_32_aes_256_gcm + attr_encrypted :recaptcha_site_key, encryption_options_base_32_aes_256_gcm + attr_encrypted :slack_app_secret, encryption_options_base_32_aes_256_gcm + attr_encrypted :slack_app_verification_token, encryption_options_base_32_aes_256_gcm def akismet_api_key decrypt(:akismet_api_key, self[:encrypted_akismet_api_key]) || self[:akismet_api_key] diff --git a/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb b/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb index 7983a56f439..5d7b6349fe6 100644 --- a/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb +++ b/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb @@ -8,7 +8,7 @@ class GenerateCiJwtSigningKey < ActiveRecord::Migration[6.0] attr_encrypted :ci_jwt_signing_key, { mode: :per_attribute_iv, - key: Rails.application.secrets.db_key_base[0..31], + key: Gitlab::Utils.ensure_utf8_size(Rails.application.secrets.db_key_base, bytes: 32.bytes), algorithm: 'aes-256-gcm', encode: true } diff --git a/db/migrate/20210215172449_remove_artifact_expiry_temp_index.rb b/db/migrate/20210215172449_remove_artifact_expiry_temp_index.rb new file mode 100644 index 00000000000..1e6619731a2 --- /dev/null +++ b/db/migrate/20210215172449_remove_artifact_expiry_temp_index.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveArtifactExpiryTempIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'expired_artifacts_temp_index' + INDEX_CONDITION = "expire_at IS NULL AND date(created_at AT TIME ZONE 'UTC') < '2020-06-22'::date" + + def up + remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME + end + + def down + add_concurrent_index(:ci_job_artifacts, %i(id created_at), where: INDEX_CONDITION, name: INDEX_NAME) + end +end diff --git a/db/migrate/20210311120153_initialize_conversion_of_events_id_to_bigint.rb b/db/migrate/20210311120153_initialize_conversion_of_events_id_to_bigint.rb index 72536d24fe1..f5ff0816047 100644 --- a/db/migrate/20210311120153_initialize_conversion_of_events_id_to_bigint.rb +++ b/db/migrate/20210311120153_initialize_conversion_of_events_id_to_bigint.rb @@ -14,7 +14,7 @@ class InitializeConversionOfEventsIdToBigint < ActiveRecord::Migration[6.0] def down trigger_name = rename_trigger_name(:events, :id, :id_convert_to_bigint) - remove_rename_triggers_for_postgresql :events, trigger_name + remove_rename_triggers :events, trigger_name remove_column :events, :id_convert_to_bigint end diff --git a/db/migrate/20210311120154_initialize_conversion_of_push_event_payloads_event_id_to_bigint.rb b/db/migrate/20210311120154_initialize_conversion_of_push_event_payloads_event_id_to_bigint.rb index 9ce3b59e2dd..651c9ed993d 100644 --- a/db/migrate/20210311120154_initialize_conversion_of_push_event_payloads_event_id_to_bigint.rb +++ b/db/migrate/20210311120154_initialize_conversion_of_push_event_payloads_event_id_to_bigint.rb @@ -14,7 +14,7 @@ class InitializeConversionOfPushEventPayloadsEventIdToBigint < ActiveRecord::Mig def down trigger_name = rename_trigger_name(:push_event_payloads, :event_id, :event_id_convert_to_bigint) - remove_rename_triggers_for_postgresql :push_event_payloads, trigger_name + remove_rename_triggers :push_event_payloads, trigger_name remove_column :push_event_payloads, :event_id_convert_to_bigint end diff --git a/db/migrate/20210316171009_create_packages_helm_file_metadata.rb b/db/migrate/20210316171009_create_packages_helm_file_metadata.rb new file mode 100644 index 00000000000..f5a9c5f1146 --- /dev/null +++ b/db/migrate/20210316171009_create_packages_helm_file_metadata.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CreatePackagesHelmFileMetadata < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table_with_constraints :packages_helm_file_metadata, id: false do |t| + t.timestamps_with_timezone + t.references :package_file, primary_key: true, index: false, default: nil, null: false, foreign_key: { to_table: :packages_package_files, on_delete: :cascade }, type: :bigint + t.text :channel, null: false + t.jsonb :metadata + + t.text_limit :channel, 63 + + t.index :channel + end + end +end diff --git a/db/migrate/20210317123054_add_throttle_package_registry_columns.rb b/db/migrate/20210317123054_add_throttle_package_registry_columns.rb new file mode 100644 index 00000000000..0bb731306c0 --- /dev/null +++ b/db/migrate/20210317123054_add_throttle_package_registry_columns.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddThrottlePackageRegistryColumns < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :throttle_unauthenticated_packages_api_requests_per_period, :integer, default: 800, null: false + add_column :application_settings, :throttle_unauthenticated_packages_api_period_in_seconds, :integer, default: 15, null: false + add_column :application_settings, :throttle_authenticated_packages_api_requests_per_period, :integer, default: 1000, null: false + add_column :application_settings, :throttle_authenticated_packages_api_period_in_seconds, :integer, default: 15, null: false + add_column :application_settings, :throttle_unauthenticated_packages_api_enabled, :boolean, default: false, null: false + add_column :application_settings, :throttle_authenticated_packages_api_enabled, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210319071214_add_helm_max_file_size_to_plan_limits.rb b/db/migrate/20210319071214_add_helm_max_file_size_to_plan_limits.rb new file mode 100644 index 00000000000..9a4789b5c1a --- /dev/null +++ b/db/migrate/20210319071214_add_helm_max_file_size_to_plan_limits.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddHelmMaxFileSizeToPlanLimits < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :plan_limits, :helm_max_file_size, :bigint, default: 5.megabyte, null: false + end +end diff --git a/db/migrate/20210323125809_create_status_check_responses_table.rb b/db/migrate/20210323125809_create_status_check_responses_table.rb new file mode 100644 index 00000000000..3fa7ff7165c --- /dev/null +++ b/db/migrate/20210323125809_create_status_check_responses_table.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class CreateStatusCheckResponsesTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + create_table :status_check_responses do |t| + t.bigint :merge_request_id, null: false + t.bigint :external_approval_rule_id, null: false + end + + add_index :status_check_responses, :merge_request_id + add_index :status_check_responses, :external_approval_rule_id + end + + def down + drop_table :status_check_responses + end +end diff --git a/db/migrate/20210323130831_add_merge_request_foreign_key_to_status_check_responses.rb b/db/migrate/20210323130831_add_merge_request_foreign_key_to_status_check_responses.rb new file mode 100644 index 00000000000..cee0b9a231e --- /dev/null +++ b/db/migrate/20210323130831_add_merge_request_foreign_key_to_status_check_responses.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddMergeRequestForeignKeyToStatusCheckResponses < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :status_check_responses, :merge_requests, column: :merge_request_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :status_check_responses, column: :merge_request_id + end + end +end diff --git a/db/migrate/20210323131543_add_external_approval_rule_foreign_key_to_status_check_responses.rb b/db/migrate/20210323131543_add_external_approval_rule_foreign_key_to_status_check_responses.rb new file mode 100644 index 00000000000..ab28c20dbb1 --- /dev/null +++ b/db/migrate/20210323131543_add_external_approval_rule_foreign_key_to_status_check_responses.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddExternalApprovalRuleForeignKeyToStatusCheckResponses < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :status_check_responses, :external_approval_rules, column: :external_approval_rule_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :status_check_responses, column: :external_approval_rule_id + end + end +end diff --git a/db/migrate/20210407111027_add_whats_new_application_setting.rb b/db/migrate/20210407111027_add_whats_new_application_setting.rb new file mode 100644 index 00000000000..450c26e2199 --- /dev/null +++ b/db/migrate/20210407111027_add_whats_new_application_setting.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddWhatsNewApplicationSetting < ActiveRecord::Migration[6.0] + def change + add_column :application_settings, :whats_new_variant, :integer, limit: 2, default: 0 + end +end diff --git a/db/migrate/20210407140539_add_verification_state_and_started_at_to_terraform_state_version_table.rb b/db/migrate/20210407140539_add_verification_state_and_started_at_to_terraform_state_version_table.rb new file mode 100644 index 00000000000..987be4ab1f0 --- /dev/null +++ b/db/migrate/20210407140539_add_verification_state_and_started_at_to_terraform_state_version_table.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddVerificationStateAndStartedAtToTerraformStateVersionTable < ActiveRecord::Migration[6.0] + def change + change_table(:terraform_state_versions) do |t| + t.column :verification_started_at, :datetime_with_timezone + t.integer :verification_state, default: 0, limit: 2, null: false + end + end +end diff --git a/db/migrate/20210412111213_create_security_orchestration_policy_rule_schedule.rb b/db/migrate/20210412111213_create_security_orchestration_policy_rule_schedule.rb new file mode 100644 index 00000000000..c7035400cba --- /dev/null +++ b/db/migrate/20210412111213_create_security_orchestration_policy_rule_schedule.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class CreateSecurityOrchestrationPolicyRuleSchedule < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_PREFIX = 'index_sop_schedules_' + + disable_ddl_transaction! + + def up + table_comment = { owner: 'group::container security', description: 'Schedules used to store relationship between project and security policy repository' } + + create_table_with_constraints :security_orchestration_policy_rule_schedules, comment: table_comment.to_json do |t| + t.timestamps_with_timezone + t.datetime_with_timezone :next_run_at, null: true + + t.references :security_orchestration_policy_configuration, null: false, foreign_key: { to_table: :security_orchestration_policy_configurations, on_delete: :cascade }, index: { name: INDEX_PREFIX + 'on_sop_configuration_id' } + t.references :user, null: false, foreign_key: { on_delete: :cascade }, index: { name: INDEX_PREFIX + 'on_user_id' } + + t.integer :policy_index, null: false + t.text :cron, null: false + + t.text_limit :cron, 255 + end + end + + def down + with_lock_retries do + drop_table :security_orchestration_policy_rule_schedules + end + end +end diff --git a/db/migrate/20210412172030_add_configured_at_to_security_orchestration_policy.rb b/db/migrate/20210412172030_add_configured_at_to_security_orchestration_policy.rb new file mode 100644 index 00000000000..8e21e0f5182 --- /dev/null +++ b/db/migrate/20210412172030_add_configured_at_to_security_orchestration_policy.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddConfiguredAtToSecurityOrchestrationPolicy < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :security_orchestration_policy_configurations, :configured_at, :datetime_with_timezone, null: true + end +end diff --git a/db/migrate/20210413155324_add_pause_seconds_to_batched_background_migrations.rb b/db/migrate/20210413155324_add_pause_seconds_to_batched_background_migrations.rb new file mode 100644 index 00000000000..ca73c85963e --- /dev/null +++ b/db/migrate/20210413155324_add_pause_seconds_to_batched_background_migrations.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPauseSecondsToBatchedBackgroundMigrations < ActiveRecord::Migration[6.0] + def change + add_column :batched_background_migrations, :pause_ms, :integer, null: false, default: 100 + end +end diff --git a/db/migrate/20210414045322_add_pause_seconds_to_batched_background_migration_jobs.rb b/db/migrate/20210414045322_add_pause_seconds_to_batched_background_migration_jobs.rb new file mode 100644 index 00000000000..d232f9c0305 --- /dev/null +++ b/db/migrate/20210414045322_add_pause_seconds_to_batched_background_migration_jobs.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPauseSecondsToBatchedBackgroundMigrationJobs < ActiveRecord::Migration[6.0] + def change + add_column :batched_background_migration_jobs, :pause_ms, :integer, null: false, default: 100 + end +end diff --git a/db/migrate/20210414100914_add_bulk_import_exports_table.rb b/db/migrate/20210414100914_add_bulk_import_exports_table.rb new file mode 100644 index 00000000000..14a7421c1e4 --- /dev/null +++ b/db/migrate/20210414100914_add_bulk_import_exports_table.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddBulkImportExportsTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + create_table_with_constraints :bulk_import_exports do |t| + t.bigint :group_id + t.bigint :project_id + t.timestamps_with_timezone null: false + t.integer :status, limit: 2, null: false, default: 0 + t.text :relation, null: false + t.text :jid, unique: true + t.text :error + + t.text_limit :relation, 255 + t.text_limit :jid, 255 + t.text_limit :error, 255 + end + end + + def down + drop_table :bulk_import_exports + end +end diff --git a/db/migrate/20210414130017_add_foreign_key_to_bulk_import_exports_on_project.rb b/db/migrate/20210414130017_add_foreign_key_to_bulk_import_exports_on_project.rb new file mode 100644 index 00000000000..2f7d3713302 --- /dev/null +++ b/db/migrate/20210414130017_add_foreign_key_to_bulk_import_exports_on_project.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddForeignKeyToBulkImportExportsOnProject < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :bulk_import_exports, :projects, column: :project_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :bulk_import_exports, column: :project_id + end + end +end diff --git a/db/migrate/20210414130526_add_foreign_key_to_bulk_import_exports_on_group.rb b/db/migrate/20210414130526_add_foreign_key_to_bulk_import_exports_on_group.rb new file mode 100644 index 00000000000..b7172c6987e --- /dev/null +++ b/db/migrate/20210414130526_add_foreign_key_to_bulk_import_exports_on_group.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddForeignKeyToBulkImportExportsOnGroup < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :bulk_import_exports, :namespaces, column: :group_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :bulk_import_exports, column: :group_id + end + end +end diff --git a/db/migrate/20210414131807_add_bulk_import_exports_table_indexes.rb b/db/migrate/20210414131807_add_bulk_import_exports_table_indexes.rb new file mode 100644 index 00000000000..1cbd1cadf5e --- /dev/null +++ b/db/migrate/20210414131807_add_bulk_import_exports_table_indexes.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class AddBulkImportExportsTableIndexes < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + GROUP_INDEX_NAME = 'partial_index_bulk_import_exports_on_group_id_and_relation' + PROJECT_INDEX_NAME = 'partial_index_bulk_import_exports_on_project_id_and_relation' + + def up + add_concurrent_index :bulk_import_exports, + [:group_id, :relation], + unique: true, + where: 'group_id IS NOT NULL', + name: GROUP_INDEX_NAME + + add_concurrent_index :bulk_import_exports, + [:project_id, :relation], + unique: true, + where: 'project_id IS NOT NULL', + name: PROJECT_INDEX_NAME + end + + def down + remove_concurrent_index_by_name(:bulk_import_exports, GROUP_INDEX_NAME) + remove_concurrent_index_by_name(:bulk_import_exports, PROJECT_INDEX_NAME) + end +end diff --git a/db/migrate/20210414133310_add_bulk_import_export_uploads_table.rb b/db/migrate/20210414133310_add_bulk_import_export_uploads_table.rb new file mode 100644 index 00000000000..d20e57848e9 --- /dev/null +++ b/db/migrate/20210414133310_add_bulk_import_export_uploads_table.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddBulkImportExportUploadsTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + create_table_with_constraints :bulk_import_export_uploads do |t| + t.references :export, index: true, null: false, foreign_key: { to_table: :bulk_import_exports, on_delete: :cascade } + t.datetime_with_timezone :updated_at, null: false + t.text :export_file + + t.text_limit :export_file, 255 + end + end + + def down + drop_table :bulk_import_export_uploads + end +end diff --git a/db/migrate/20210415100159_initialize_conversion_of_ci_build_needs_to_bigint.rb b/db/migrate/20210415100159_initialize_conversion_of_ci_build_needs_to_bigint.rb new file mode 100644 index 00000000000..068dceda272 --- /dev/null +++ b/db/migrate/20210415100159_initialize_conversion_of_ci_build_needs_to_bigint.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiBuildNeedsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + initialize_conversion_of_integer_to_bigint :ci_build_needs, :build_id + end + + def down + trigger_name = rename_trigger_name(:ci_build_needs, :build_id, :build_id_convert_to_bigint) + + remove_rename_triggers :ci_build_needs, trigger_name + + remove_column :ci_build_needs, :build_id_convert_to_bigint + end +end diff --git a/db/migrate/20210415172516_create_vulnerability_finding_evidence_requests.rb b/db/migrate/20210415172516_create_vulnerability_finding_evidence_requests.rb new file mode 100644 index 00000000000..2fe33ff23ba --- /dev/null +++ b/db/migrate/20210415172516_create_vulnerability_finding_evidence_requests.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingEvidenceRequests < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_finding_evidence_requests do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_requests_on_finding_evidence_id' }, null: false, foreign_key: { on_delete: :cascade } + t.text :method + t.text :url + + t.text_limit :method, 32 + t.text_limit :url, 2048 + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_evidence_requests + end + end +end diff --git a/db/migrate/20210416172516_create_vulnerability_finding_evidence_responses.rb b/db/migrate/20210416172516_create_vulnerability_finding_evidence_responses.rb new file mode 100644 index 00000000000..c9740a48117 --- /dev/null +++ b/db/migrate/20210416172516_create_vulnerability_finding_evidence_responses.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingEvidenceResponses < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_finding_evidence_responses do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_responses_on_finding_evidences_id' }, null: false, foreign_key: { on_delete: :cascade } + t.integer :status_code + t.text :reason_phrase + + t.text_limit :reason_phrase, 2048 + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_evidence_responses + end + end +end diff --git a/db/migrate/20210419090412_remove_debian_group_architectures_distribution_id_index.rb b/db/migrate/20210419090412_remove_debian_group_architectures_distribution_id_index.rb new file mode 100644 index 00000000000..1df56742480 --- /dev/null +++ b/db/migrate/20210419090412_remove_debian_group_architectures_distribution_id_index.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveDebianGroupArchitecturesDistributionIdIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_NAME = 'idx_pkgs_deb_grp_architectures_on_distribution_id' + + disable_ddl_transaction! + + def up + remove_concurrent_index :packages_debian_group_architectures, :distribution_id, name: INDEX_NAME + end + + def down + add_concurrent_index :packages_debian_group_architectures, :distribution_id, name: INDEX_NAME + end +end diff --git a/db/migrate/20210419090542_remove_debian_project_architectures_distribution_id_index.rb b/db/migrate/20210419090542_remove_debian_project_architectures_distribution_id_index.rb new file mode 100644 index 00000000000..1f918bd4dec --- /dev/null +++ b/db/migrate/20210419090542_remove_debian_project_architectures_distribution_id_index.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveDebianProjectArchitecturesDistributionIdIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_NAME = 'idx_pkgs_deb_proj_architectures_on_distribution_id' + + disable_ddl_transaction! + + def up + remove_concurrent_index :packages_debian_project_architectures, :distribution_id, name: INDEX_NAME + end + + def down + add_concurrent_index :packages_debian_project_architectures, :distribution_id, name: INDEX_NAME + end +end diff --git a/db/migrate/20210419203017_add_remote_import_url_to_import_export_upload.rb b/db/migrate/20210419203017_add_remote_import_url_to_import_export_upload.rb new file mode 100644 index 00000000000..00c5329406e --- /dev/null +++ b/db/migrate/20210419203017_add_remote_import_url_to_import_export_upload.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddRemoteImportUrlToImportExportUpload < ActiveRecord::Migration[6.0] + # limit is added in 20210419203018_add_remote_text_limit_to_import_url_in_import_export_upload.rb + def change + add_column :import_export_uploads, :remote_import_url, :text # rubocop:disable Migration/AddLimitToTextColumns + end +end diff --git a/db/migrate/20210419203018_add_remote_text_limit_to_import_url_in_import_export_upload.rb b/db/migrate/20210419203018_add_remote_text_limit_to_import_url_in_import_export_upload.rb new file mode 100644 index 00000000000..81b4e76b8d9 --- /dev/null +++ b/db/migrate/20210419203018_add_remote_text_limit_to_import_url_in_import_export_upload.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddRemoteTextLimitToImportUrlInImportExportUpload < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :import_export_uploads, :remote_import_url, 512 + end + + def down + remove_text_limit :import_export_uploads, :remote_import_url + end +end diff --git a/db/migrate/20210419224834_update_issues_iteration_foreign_key.rb b/db/migrate/20210419224834_update_issues_iteration_foreign_key.rb new file mode 100644 index 00000000000..d071ac8d1d4 --- /dev/null +++ b/db/migrate/20210419224834_update_issues_iteration_foreign_key.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class UpdateIssuesIterationForeignKey < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:issues, column: :sprint_id) + end + + add_concurrent_foreign_key(:issues, :sprints, column: :sprint_id, on_delete: :nullify) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(:issues, column: :sprint_id) + end + + add_concurrent_foreign_key(:issues, :sprints, column: :sprint_id, on_delete: :cascade) + end +end diff --git a/db/migrate/20210420012444_change_web_hook_events_default.rb b/db/migrate/20210420012444_change_web_hook_events_default.rb new file mode 100644 index 00000000000..b5a63a5a2a8 --- /dev/null +++ b/db/migrate/20210420012444_change_web_hook_events_default.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class ChangeWebHookEventsDefault < ActiveRecord::Migration[6.0] + def up + change_column_default :web_hooks, :push_events, true + change_column_default :web_hooks, :issues_events, false + change_column_default :web_hooks, :merge_requests_events, false + change_column_default :web_hooks, :tag_push_events, false + end + + # This is a NOP because this migration is supposed to restore the + # intended schema, not revert it. + def down + end +end diff --git a/db/migrate/20210420012909_index_cluster_agent_tokens_on_last_used_at.rb b/db/migrate/20210420012909_index_cluster_agent_tokens_on_last_used_at.rb new file mode 100644 index 00000000000..c1715d8ac29 --- /dev/null +++ b/db/migrate/20210420012909_index_cluster_agent_tokens_on_last_used_at.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class IndexClusterAgentTokensOnLastUsedAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + OLD_INDEX = 'index_cluster_agent_tokens_on_agent_id' + NEW_INDEX = 'index_cluster_agent_tokens_on_agent_id_and_last_used_at' + + disable_ddl_transaction! + + def up + add_concurrent_index :cluster_agent_tokens, 'agent_id, last_used_at DESC NULLS LAST', name: NEW_INDEX + remove_concurrent_index_by_name :cluster_agent_tokens, OLD_INDEX + end + + def down + add_concurrent_index :cluster_agent_tokens, :agent_id, name: OLD_INDEX + remove_concurrent_index_by_name :cluster_agent_tokens, NEW_INDEX + end +end diff --git a/db/migrate/20210420120734_initialize_conversion_of_ci_job_artifacts_to_bigint.rb b/db/migrate/20210420120734_initialize_conversion_of_ci_job_artifacts_to_bigint.rb new file mode 100644 index 00000000000..cc8f0686841 --- /dev/null +++ b/db/migrate/20210420120734_initialize_conversion_of_ci_job_artifacts_to_bigint.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiJobArtifactsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_job_artifacts + COLUMNS = %i(id job_id) + TARGET_COLUMNS = COLUMNS.map { |col| "#{col}_convert_to_bigint" } + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + trigger_name = rename_trigger_name(TABLE, COLUMNS, TARGET_COLUMNS) + remove_rename_triggers TABLE, trigger_name + + TARGET_COLUMNS.each do |column| + remove_column TABLE, column + end + end +end diff --git a/db/migrate/20210420173030_add_verification_indexes_to_terraform_state_versions.rb b/db/migrate/20210420173030_add_verification_indexes_to_terraform_state_versions.rb new file mode 100644 index 00000000000..2c0d0bee39d --- /dev/null +++ b/db/migrate/20210420173030_add_verification_indexes_to_terraform_state_versions.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class AddVerificationIndexesToTerraformStateVersions < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + VERIFICATION_STATE_INDEX_NAME = "index_terraform_state_versions_on_verification_state" + PENDING_VERIFICATION_INDEX_NAME = "index_terraform_state_versions_pending_verification" + FAILED_VERIFICATION_INDEX_NAME = "index_terraform_state_versions_failed_verification" + NEEDS_VERIFICATION_INDEX_NAME = "index_terraform_state_versions_needs_verification" + + disable_ddl_transaction! + + def up + add_concurrent_index :terraform_state_versions, :verification_state, name: VERIFICATION_STATE_INDEX_NAME + add_concurrent_index :terraform_state_versions, :verified_at, where: "(verification_state = 0)", order: { verified_at: 'ASC NULLS FIRST' }, name: PENDING_VERIFICATION_INDEX_NAME + add_concurrent_index :terraform_state_versions, :verification_retry_at, where: "(verification_state = 3)", order: { verification_retry_at: 'ASC NULLS FIRST' }, name: FAILED_VERIFICATION_INDEX_NAME + add_concurrent_index :terraform_state_versions, :verification_state, where: "(verification_state = 0 OR verification_state = 3)", name: NEEDS_VERIFICATION_INDEX_NAME + end + + def down + remove_concurrent_index_by_name :terraform_state_versions, VERIFICATION_STATE_INDEX_NAME + remove_concurrent_index_by_name :terraform_state_versions, PENDING_VERIFICATION_INDEX_NAME + remove_concurrent_index_by_name :terraform_state_versions, FAILED_VERIFICATION_INDEX_NAME + remove_concurrent_index_by_name :terraform_state_versions, NEEDS_VERIFICATION_INDEX_NAME + end +end diff --git a/db/migrate/20210420210642_recreate_index_for_project_deployments_with_environment_id_and_date_at.rb b/db/migrate/20210420210642_recreate_index_for_project_deployments_with_environment_id_and_date_at.rb new file mode 100644 index 00000000000..2674d9e50c8 --- /dev/null +++ b/db/migrate/20210420210642_recreate_index_for_project_deployments_with_environment_id_and_date_at.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# This migration recreates the index that introduced in 20210326035553_add_index_for_project_deployments_with_environment_id_and_updated_at.rb. +class RecreateIndexForProjectDeploymentsWithEnvironmentIdAndDateAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_deployments_on_project_and_environment_and_updated_at' + NEW_INDEX_NAME = 'index_deployments_on_project_and_environment_and_updated_at_id' + + def up + add_concurrent_index :deployments, [:project_id, :environment_id, :updated_at, :id], name: NEW_INDEX_NAME + remove_concurrent_index_by_name :deployments, OLD_INDEX_NAME + end + + def down + add_concurrent_index :deployments, [:project_id, :environment_id, :updated_at], name: OLD_INDEX_NAME + remove_concurrent_index_by_name :deployments, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20210420221106_update_merge_requests_iteration_foreign_key.rb b/db/migrate/20210420221106_update_merge_requests_iteration_foreign_key.rb new file mode 100644 index 00000000000..64786f0b20c --- /dev/null +++ b/db/migrate/20210420221106_update_merge_requests_iteration_foreign_key.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class UpdateMergeRequestsIterationForeignKey < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + with_lock_retries do + remove_foreign_key_if_exists(:merge_requests, column: :sprint_id) + end + + add_concurrent_foreign_key(:merge_requests, :sprints, column: :sprint_id, on_delete: :nullify) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(:merge_requests, column: :sprint_id) + end + + add_concurrent_foreign_key(:merge_requests, :sprints, column: :sprint_id, on_delete: :cascade) + end +end diff --git a/db/migrate/20210421021510_add_deactivate_dormant_users_to_application_settings.rb b/db/migrate/20210421021510_add_deactivate_dormant_users_to_application_settings.rb new file mode 100644 index 00000000000..74d197cd3b8 --- /dev/null +++ b/db/migrate/20210421021510_add_deactivate_dormant_users_to_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDeactivateDormantUsersToApplicationSettings < ActiveRecord::Migration[6.0] + def change + add_column :application_settings, :deactivate_dormant_users, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210421022010_add_index_for_dormant_users.rb b/db/migrate/20210421022010_add_index_for_dormant_users.rb new file mode 100644 index 00000000000..48eff184ca0 --- /dev/null +++ b/db/migrate/20210421022010_add_index_for_dormant_users.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIndexForDormantUsers < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_users_on_id_and_last_activity_on_for_non_internal_active' + + disable_ddl_transaction! + + def up + index_condition = "state = 'active' AND (users.user_type IS NULL OR users.user_type IN (NULL, 6, 4))" + + add_concurrent_index :users, [:id, :last_activity_on], where: index_condition, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :users, INDEX_NAME + end +end diff --git a/db/migrate/20210421081724_add_codeowners_devops_adoption_snapshot.rb b/db/migrate/20210421081724_add_codeowners_devops_adoption_snapshot.rb new file mode 100644 index 00000000000..3d65abc5608 --- /dev/null +++ b/db/migrate/20210421081724_add_codeowners_devops_adoption_snapshot.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddCodeownersDevopsAdoptionSnapshot < ActiveRecord::Migration[6.0] + def change + add_column :analytics_devops_adoption_snapshots, :total_projects_count, :integer + add_column :analytics_devops_adoption_snapshots, :code_owners_used_count, :integer + end +end diff --git a/db/migrate/20210421190157_remove_elastic_task_null_constraint_from_elastic_reindexing_subtasks.rb b/db/migrate/20210421190157_remove_elastic_task_null_constraint_from_elastic_reindexing_subtasks.rb new file mode 100644 index 00000000000..301e75aa093 --- /dev/null +++ b/db/migrate/20210421190157_remove_elastic_task_null_constraint_from_elastic_reindexing_subtasks.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveElasticTaskNullConstraintFromElasticReindexingSubtasks < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + ELASTIC_TASK = 'elastic_task' + + disable_ddl_transaction! + + def up + remove_not_null_constraint :elastic_reindexing_subtasks, :elastic_task + change_column_null(:elastic_reindexing_subtasks, :elastic_task, true) + end + + def down + # there may be elastic_task values which are null so we fill them with a dummy value + change_column_null(:elastic_reindexing_subtasks, :elastic_task, false, ELASTIC_TASK) + add_not_null_constraint :elastic_reindexing_subtasks, :elastic_task, validate: false + end +end diff --git a/db/migrate/20210422022825_initialize_conversion_of_ci_sources_pipelines_source_job_id_to_bigint.rb b/db/migrate/20210422022825_initialize_conversion_of_ci_sources_pipelines_source_job_id_to_bigint.rb new file mode 100644 index 00000000000..ea716afe84b --- /dev/null +++ b/db/migrate/20210422022825_initialize_conversion_of_ci_sources_pipelines_source_job_id_to_bigint.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiSourcesPipelinesSourceJobIdToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + # Foreign key that references ci_builds.id + initialize_conversion_of_integer_to_bigint :ci_sources_pipelines, :source_job_id + end + + def down + trigger_name = rename_trigger_name(:ci_sources_pipelines, :source_job_id, :source_job_id_convert_to_bigint) + + remove_rename_triggers :ci_sources_pipelines, trigger_name + + remove_column :ci_sources_pipelines, :source_job_id_convert_to_bigint + end +end diff --git a/db/migrate/20210422142647_add_project_id_next_run_at_index_to_container_expiration_policies.rb b/db/migrate/20210422142647_add_project_id_next_run_at_index_to_container_expiration_policies.rb new file mode 100644 index 00000000000..bd38b5660b4 --- /dev/null +++ b/db/migrate/20210422142647_add_project_id_next_run_at_index_to_container_expiration_policies.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddProjectIdNextRunAtIndexToContainerExpirationPolicies < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'idx_container_exp_policies_on_project_id_next_run_at' + + def up + add_concurrent_index :container_expiration_policies, [:project_id, :next_run_at], name: INDEX_NAME, where: 'enabled = true' + end + + def down + remove_concurrent_index :container_expiration_policies, [:project_id, :next_run_at], name: INDEX_NAME + end +end diff --git a/db/migrate/20210422181809_add_project_to_timelogs.rb b/db/migrate/20210422181809_add_project_to_timelogs.rb new file mode 100644 index 00000000000..1f98e440d15 --- /dev/null +++ b/db/migrate/20210422181809_add_project_to_timelogs.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddProjectToTimelogs < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :timelogs, :project_id, :integer + end + end + + def down + with_lock_retries do + remove_column :timelogs, :project_id + end + end +end diff --git a/db/migrate/20210422195929_create_elastic_reindexing_slices.rb b/db/migrate/20210422195929_create_elastic_reindexing_slices.rb new file mode 100644 index 00000000000..a535402186c --- /dev/null +++ b/db/migrate/20210422195929_create_elastic_reindexing_slices.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class CreateElasticReindexingSlices < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + class ReindexingSubtask < ActiveRecord::Base + self.table_name = 'elastic_reindexing_subtasks' + end + + class ReindexingSlice < ActiveRecord::Base + self.table_name = 'elastic_reindexing_slices' + end + + def up + unless table_exists?(:elastic_reindexing_slices) + create_table_with_constraints :elastic_reindexing_slices do |t| + t.timestamps_with_timezone null: false + t.references :elastic_reindexing_subtask, foreign_key: { on_delete: :cascade }, null: false, index: { name: 'idx_elastic_reindexing_slices_on_elastic_reindexing_subtask_id' } + t.integer :elastic_slice, null: false, limit: 2, default: 0 + t.integer :elastic_max_slice, null: false, limit: 2, default: 0 + t.integer :retry_attempt, null: false, limit: 2, default: 0 + t.text :elastic_task + + t.text_limit :elastic_task, 255 + end + end + + ReindexingSubtask.find_each do |subtask| + next if ReindexingSlice.where(elastic_reindexing_subtask_id: subtask.id).exists? + + ReindexingSlice.create( + elastic_reindexing_subtask_id: subtask.id, + elastic_task: subtask.elastic_task, + retry_attempt: 0 + ) + end + end + + def down + drop_table :elastic_reindexing_slices + end +end diff --git a/db/migrate/20210423054022_create_dast_site_profiles_pipelines.rb b/db/migrate/20210423054022_create_dast_site_profiles_pipelines.rb new file mode 100644 index 00000000000..bbdb4f02ab4 --- /dev/null +++ b/db/migrate/20210423054022_create_dast_site_profiles_pipelines.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateDastSiteProfilesPipelines < ActiveRecord::Migration[6.0] + def up + table_comment = { owner: 'group::dynamic analysis', description: 'Join table between DAST Site Profiles and CI Pipelines' } + + create_table :dast_site_profiles_pipelines, primary_key: [:dast_site_profile_id, :ci_pipeline_id], comment: table_comment.to_json do |t| + t.bigint :dast_site_profile_id, null: false + t.bigint :ci_pipeline_id, null: false + + t.index :ci_pipeline_id, unique: true, name: :index_dast_site_profiles_pipelines_on_ci_pipeline_id + end + end + + def down + drop_table :dast_site_profiles_pipelines + end +end diff --git a/db/migrate/20210423054537_add_dast_site_profile_id_fk_to_dast_site_profiles_pipelines.rb b/db/migrate/20210423054537_add_dast_site_profile_id_fk_to_dast_site_profiles_pipelines.rb new file mode 100644 index 00000000000..eb3a5168609 --- /dev/null +++ b/db/migrate/20210423054537_add_dast_site_profile_id_fk_to_dast_site_profiles_pipelines.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDastSiteProfileIdFkToDastSiteProfilesPipelines < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_site_profiles_pipelines, :dast_site_profiles, column: :dast_site_profile_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_site_profiles_pipelines, column: :dast_site_profile_id + end + end +end diff --git a/db/migrate/20210423054846_add_ci_pipeline_id_fk_to_dast_site_profiles_pipelines.rb b/db/migrate/20210423054846_add_ci_pipeline_id_fk_to_dast_site_profiles_pipelines.rb new file mode 100644 index 00000000000..ed2a7ff859c --- /dev/null +++ b/db/migrate/20210423054846_add_ci_pipeline_id_fk_to_dast_site_profiles_pipelines.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddCiPipelineIdFkToDastSiteProfilesPipelines < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_site_profiles_pipelines, :ci_pipelines, column: :ci_pipeline_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_site_profiles_pipelines, column: :ci_pipeline_id + end + end +end diff --git a/db/migrate/20210423155059_add_runner_registration_to_plan_limits.rb b/db/migrate/20210423155059_add_runner_registration_to_plan_limits.rb new file mode 100644 index 00000000000..5382e596d8c --- /dev/null +++ b/db/migrate/20210423155059_add_runner_registration_to_plan_limits.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddRunnerRegistrationToPlanLimits < ActiveRecord::Migration[6.0] + def change + add_column(:plan_limits, :ci_registered_group_runners, :integer, default: 1000, null: false) + add_column(:plan_limits, :ci_registered_project_runners, :integer, default: 1000, null: false) + end +end diff --git a/db/migrate/20210423164702_insert_runner_registration_plan_limits.rb b/db/migrate/20210423164702_insert_runner_registration_plan_limits.rb new file mode 100644 index 00000000000..36d13dfa120 --- /dev/null +++ b/db/migrate/20210423164702_insert_runner_registration_plan_limits.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class InsertRunnerRegistrationPlanLimits < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + create_or_update_plan_limit('ci_registered_group_runners', 'free', 50) + create_or_update_plan_limit('ci_registered_group_runners', 'bronze', 1000) + create_or_update_plan_limit('ci_registered_group_runners', 'silver', 1000) + create_or_update_plan_limit('ci_registered_group_runners', 'gold', 1000) + + create_or_update_plan_limit('ci_registered_project_runners', 'free', 50) + create_or_update_plan_limit('ci_registered_project_runners', 'bronze', 1000) + create_or_update_plan_limit('ci_registered_project_runners', 'silver', 1000) + create_or_update_plan_limit('ci_registered_project_runners', 'gold', 1000) + end + + def down + %w[group project].each do |scope| + create_or_update_plan_limit("ci_registered_#{scope}_runners", 'free', 1000) + create_or_update_plan_limit("ci_registered_#{scope}_runners", 'bronze', 1000) + create_or_update_plan_limit("ci_registered_#{scope}_runners", 'silver', 1000) + create_or_update_plan_limit("ci_registered_#{scope}_runners", 'gold', 1000) + end + end +end diff --git a/db/migrate/20210423171304_re_order_fk_source_project_id_in_merge_requests.rb b/db/migrate/20210423171304_re_order_fk_source_project_id_in_merge_requests.rb new file mode 100644 index 00000000000..ee9e444c792 --- /dev/null +++ b/db/migrate/20210423171304_re_order_fk_source_project_id_in_merge_requests.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ReOrderFkSourceProjectIdInMergeRequests < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + OLD_SOURCE_PROJECT_FK = 'fk_3308fe130c' + NEW_SOURCE_PROJECT_FK = 'fk_source_project' + + def up + add_concurrent_foreign_key :merge_requests, :projects, column: :source_project_id, on_delete: :nullify, name: NEW_SOURCE_PROJECT_FK + + remove_foreign_key_if_exists :merge_requests, column: :source_project_id, name: OLD_SOURCE_PROJECT_FK + end + + def down + add_concurrent_foreign_key :merge_requests, :projects, column: :source_project_id, on_delete: :nullify + + remove_foreign_key_if_exists :merge_requests, column: :source_project_id, name: NEW_SOURCE_PROJECT_FK + end +end diff --git a/db/migrate/20210424115725_swap_partitioned_web_hook_logs.rb b/db/migrate/20210424115725_swap_partitioned_web_hook_logs.rb new file mode 100644 index 00000000000..47b2f81cfae --- /dev/null +++ b/db/migrate/20210424115725_swap_partitioned_web_hook_logs.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class SwapPartitionedWebHookLogs < ActiveRecord::Migration[6.0] + include Gitlab::Database::PartitioningMigrationHelpers + + DOWNTIME = false + + def up + replace_with_partitioned_table :web_hook_logs + end + + def down + rollback_replace_with_partitioned_table :web_hook_logs + end +end diff --git a/db/migrate/20210424163400_add_project_id_fk_to_timelogs.rb b/db/migrate/20210424163400_add_project_id_fk_to_timelogs.rb new file mode 100644 index 00000000000..69542e7627d --- /dev/null +++ b/db/migrate/20210424163400_add_project_id_fk_to_timelogs.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddProjectIdFkToTimelogs < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_timelogs_on_project_id_and_spent_at' + + disable_ddl_transaction! + + def up + add_concurrent_index :timelogs, [:project_id, :spent_at], name: INDEX_NAME + add_concurrent_foreign_key :timelogs, :projects, column: :project_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :timelogs, column: :project_id + end + remove_concurrent_index_by_name :timelogs, INDEX_NAME + end +end diff --git a/db/migrate/20210426094524_initialize_conversion_of_ci_builds_to_bigint.rb b/db/migrate/20210426094524_initialize_conversion_of_ci_builds_to_bigint.rb new file mode 100644 index 00000000000..e2f82557387 --- /dev/null +++ b/db/migrate/20210426094524_initialize_conversion_of_ci_builds_to_bigint.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiBuildsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_builds + COLUMNS = %i(id stage_id) + TARGET_COLUMNS = COLUMNS.map { |col| "#{col}_convert_to_bigint" } + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/migrate/20210427045604_initialize_conversion_of_ci_build_trace_chunks_to_bigint.rb b/db/migrate/20210427045604_initialize_conversion_of_ci_build_trace_chunks_to_bigint.rb new file mode 100644 index 00000000000..ec3bb0b7e45 --- /dev/null +++ b/db/migrate/20210427045604_initialize_conversion_of_ci_build_trace_chunks_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiBuildTraceChunksToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_build_trace_chunks + COLUMNS = %i(build_id) + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/migrate/20210427062807_add_index_to_batched_migration_jobs_status.rb b/db/migrate/20210427062807_add_index_to_batched_migration_jobs_status.rb new file mode 100644 index 00000000000..c429094762e --- /dev/null +++ b/db/migrate/20210427062807_add_index_to_batched_migration_jobs_status.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToBatchedMigrationJobsStatus < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_batched_jobs_on_batched_migration_id_and_status' + + def up + add_concurrent_index :batched_background_migration_jobs, [:batched_background_migration_id, :status], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :batched_background_migration_jobs, INDEX_NAME + end +end diff --git a/db/migrate/20210427084924_initialize_conversion_of_ci_builds_runner_session_to_bigint.rb b/db/migrate/20210427084924_initialize_conversion_of_ci_builds_runner_session_to_bigint.rb new file mode 100644 index 00000000000..ffa653604df --- /dev/null +++ b/db/migrate/20210427084924_initialize_conversion_of_ci_builds_runner_session_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiBuildsRunnerSessionToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_builds_runner_session + COLUMNS = %i(build_id) + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/migrate/20210427094931_add_execution_order_index_to_batched_background_migration_jobs.rb b/db/migrate/20210427094931_add_execution_order_index_to_batched_background_migration_jobs.rb new file mode 100644 index 00000000000..3622dddd27f --- /dev/null +++ b/db/migrate/20210427094931_add_execution_order_index_to_batched_background_migration_jobs.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddExecutionOrderIndexToBatchedBackgroundMigrationJobs < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_migration_jobs_on_migration_id_and_finished_at' + + def up + add_concurrent_index :batched_background_migration_jobs, %i(batched_background_migration_id finished_at), name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :batched_background_migration_jobs, INDEX_NAME + end +end diff --git a/db/migrate/20210427125400_add_spamcheck_api_key_to_application_setting.rb b/db/migrate/20210427125400_add_spamcheck_api_key_to_application_setting.rb new file mode 100644 index 00000000000..9f411a61e5c --- /dev/null +++ b/db/migrate/20210427125400_add_spamcheck_api_key_to_application_setting.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddSpamcheckApiKeyToApplicationSetting < ActiveRecord::Migration[6.0] + def up + add_column :application_settings, :encrypted_spam_check_api_key, :binary + add_column :application_settings, :encrypted_spam_check_api_key_iv, :binary + end + + def down + remove_column :application_settings, :encrypted_spam_check_api_key + remove_column :application_settings, :encrypted_spam_check_api_key_iv + end +end diff --git a/db/migrate/20210427194958_add_description_roll_over_to_iterations_cadences.rb b/db/migrate/20210427194958_add_description_roll_over_to_iterations_cadences.rb new file mode 100644 index 00000000000..fbae2a14d2d --- /dev/null +++ b/db/migrate/20210427194958_add_description_roll_over_to_iterations_cadences.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDescriptionRollOverToIterationsCadences < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :iterations_cadences, :roll_over, :boolean, null: false, default: false + add_column :iterations_cadences, :description, :text # rubocop:disable Migration/AddLimitToTextColumns + end + end + + def down + with_lock_retries do + remove_column :iterations_cadences, :roll_over + remove_column :iterations_cadences, :description + end + end +end diff --git a/db/migrate/20210427200840_add_text_limit_to_iterations_cadences_description.rb b/db/migrate/20210427200840_add_text_limit_to_iterations_cadences_description.rb new file mode 100644 index 00000000000..a146f295de3 --- /dev/null +++ b/db/migrate/20210427200840_add_text_limit_to_iterations_cadences_description.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToIterationsCadencesDescription < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :iterations_cadences, :description, 5000 + end + + def down + remove_text_limit :iterations_cadences, :description + end +end diff --git a/db/migrate/20210428151144_update_invalid_web_hooks.rb b/db/migrate/20210428151144_update_invalid_web_hooks.rb new file mode 100644 index 00000000000..4f45e7aaa9b --- /dev/null +++ b/db/migrate/20210428151144_update_invalid_web_hooks.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UpdateInvalidWebHooks < ActiveRecord::Migration[6.0] + disable_ddl_transaction! + + class WebHook < ActiveRecord::Base + include EachBatch + + self.table_name = 'web_hooks' + end + + def up + WebHook.each_batch(of: 10_000, column: :id) do |relation| + relation.where(type: 'ProjectHook') + .where.not(project_id: nil) + .where.not(group_id: nil) + .update_all(group_id: nil) + end + end + + def down + # no-op + end +end diff --git a/db/migrate/20210428151238_validate_foreign_key_on_group_hooks.rb b/db/migrate/20210428151238_validate_foreign_key_on_group_hooks.rb new file mode 100644 index 00000000000..e7020665b25 --- /dev/null +++ b/db/migrate/20210428151238_validate_foreign_key_on_group_hooks.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class ValidateForeignKeyOnGroupHooks < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + CONSTRAINT_NAME = 'fk_rails_d35697648e' + + def up + validate_foreign_key :web_hooks, :group_id, name: CONSTRAINT_NAME + end + + def down + # no-op + end +end diff --git a/db/migrate/20210429024843_add_escalation_policies.rb b/db/migrate/20210429024843_add_escalation_policies.rb new file mode 100644 index 00000000000..63bd558acfb --- /dev/null +++ b/db/migrate/20210429024843_add_escalation_policies.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddEscalationPolicies < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + UNIQUE_INDEX_NAME = 'index_on_project_id_escalation_policy_name_unique' + + def up + create_table_with_constraints :incident_management_escalation_policies do |t| + t.references :project, index: false, null: false, foreign_key: { on_delete: :cascade } + t.text :name, null: false + t.text :description, null: true + + t.text_limit :name, 72 + t.text_limit :description, 160 + t.index [:project_id, :name], unique: true, name: UNIQUE_INDEX_NAME + end + end + + def down + drop_table :incident_management_escalation_policies + end +end diff --git a/db/migrate/20210429032320_add_escalation_rules.rb b/db/migrate/20210429032320_add_escalation_rules.rb new file mode 100644 index 00000000000..2297f7511a6 --- /dev/null +++ b/db/migrate/20210429032320_add_escalation_rules.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddEscalationRules < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + RULE_SCHEDULE_INDEX_NAME = 'index_on_oncall_schedule_escalation_rule' + UNIQUENESS_INDEX_NAME = 'index_on_policy_schedule_status_elapsed_time_escalation_rules' + + def change + create_table :incident_management_escalation_rules do |t| + t.belongs_to :policy, index: false, null: false, foreign_key: { on_delete: :cascade, to_table: :incident_management_escalation_policies } + t.belongs_to :oncall_schedule, index: { name: RULE_SCHEDULE_INDEX_NAME }, null: false, foreign_key: { on_delete: :cascade, to_table: :incident_management_oncall_schedules } + t.integer :status, null: false, limit: 2 + t.integer :elapsed_time_seconds, null: false, limit: 4 + + t.index [:policy_id, :oncall_schedule_id, :status, :elapsed_time_seconds], unique: true, name: UNIQUENESS_INDEX_NAME + end + end +end diff --git a/db/migrate/20210429131525_create_user_credit_card_validations.rb b/db/migrate/20210429131525_create_user_credit_card_validations.rb new file mode 100644 index 00000000000..8548274b29a --- /dev/null +++ b/db/migrate/20210429131525_create_user_credit_card_validations.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CreateUserCreditCardValidations < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + with_lock_retries do + create_table :user_credit_card_validations, id: false do |t| + t.references :user, foreign_key: { on_delete: :cascade }, index: false, primary_key: true, default: nil + t.datetime_with_timezone :credit_card_validated_at, null: false + end + end + end + + def down + with_lock_retries do + drop_table :user_credit_card_validations + end + end +end diff --git a/db/migrate/20210429181325_add_failure_tracking_to_web_hooks.rb b/db/migrate/20210429181325_add_failure_tracking_to_web_hooks.rb new file mode 100644 index 00000000000..4a34c2dd307 --- /dev/null +++ b/db/migrate/20210429181325_add_failure_tracking_to_web_hooks.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddFailureTrackingToWebHooks < ActiveRecord::Migration[6.0] + def change + change_table(:web_hooks, bulk: true) do |t| + t.integer :recent_failures, null: false, limit: 2, default: 0 + t.integer :backoff_count, null: false, limit: 2, default: 0 + t.column :disabled_until, :timestamptz + end + end +end diff --git a/db/migrate/20210429192653_add_generic_package_duplicate_settings_to_namespace_package_settings.rb b/db/migrate/20210429192653_add_generic_package_duplicate_settings_to_namespace_package_settings.rb new file mode 100644 index 00000000000..8c328eb52fc --- /dev/null +++ b/db/migrate/20210429192653_add_generic_package_duplicate_settings_to_namespace_package_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddGenericPackageDuplicateSettingsToNamespacePackageSettings < ActiveRecord::Migration[6.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210429193106_add_text_limit_to_namespace_package_settings_generic_duplicate_exception_regex + def change + add_column :namespace_package_settings, :generic_duplicates_allowed, :boolean, null: false, default: true + add_column :namespace_package_settings, :generic_duplicate_exception_regex, :text, null: false, default: '' + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210429193106_add_text_limit_to_namespace_package_settings_generic_duplicate_exception_regex.rb b/db/migrate/20210429193106_add_text_limit_to_namespace_package_settings_generic_duplicate_exception_regex.rb new file mode 100644 index 00000000000..5d02ad3e2f5 --- /dev/null +++ b/db/migrate/20210429193106_add_text_limit_to_namespace_package_settings_generic_duplicate_exception_regex.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToNamespacePackageSettingsGenericDuplicateExceptionRegex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :namespace_package_settings, :generic_duplicate_exception_regex, 255 + end + + def down + remove_text_limit :namespace_package_settings, :generic_duplicate_exception_regex + end +end diff --git a/db/migrate/20210430034712_add_alert_manager_token_to_clusters_integration_prometheus.rb b/db/migrate/20210430034712_add_alert_manager_token_to_clusters_integration_prometheus.rb new file mode 100644 index 00000000000..48ab860a63b --- /dev/null +++ b/db/migrate/20210430034712_add_alert_manager_token_to_clusters_integration_prometheus.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddAlertManagerTokenToClustersIntegrationPrometheus < ActiveRecord::Migration[6.0] + def change + change_table :clusters_integration_prometheus do |t| + t.text :encrypted_alert_manager_token + t.text :encrypted_alert_manager_token_iv + end + end +end diff --git a/db/migrate/20210430100947_add_elasticsearch_username_password_to_application_settings.rb b/db/migrate/20210430100947_add_elasticsearch_username_password_to_application_settings.rb new file mode 100644 index 00000000000..446ac93c75b --- /dev/null +++ b/db/migrate/20210430100947_add_elasticsearch_username_password_to_application_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddElasticsearchUsernamePasswordToApplicationSettings < ActiveRecord::Migration[6.0] + def change + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210505124816_add_text_limit_to_elasticsearch_username + add_column :application_settings, :elasticsearch_username, :text + # rubocop:enable Migration/AddLimitToTextColumns + + add_column :application_settings, :encrypted_elasticsearch_password, :binary + add_column :application_settings, :encrypted_elasticsearch_password_iv, :binary + end +end diff --git a/db/migrate/20210430122951_add_snapshot_namespace_id.rb b/db/migrate/20210430122951_add_snapshot_namespace_id.rb new file mode 100644 index 00000000000..9017bcdde53 --- /dev/null +++ b/db/migrate/20210430122951_add_snapshot_namespace_id.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddSnapshotNamespaceId < ActiveRecord::Migration[6.0] + def change + add_column :analytics_devops_adoption_snapshots, :namespace_id, :integer + end +end diff --git a/db/migrate/20210430124212_add_display_namespace_id_to_segments.rb b/db/migrate/20210430124212_add_display_namespace_id_to_segments.rb new file mode 100644 index 00000000000..43be5c719fb --- /dev/null +++ b/db/migrate/20210430124212_add_display_namespace_id_to_segments.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDisplayNamespaceIdToSegments < ActiveRecord::Migration[6.0] + def change + add_column :analytics_devops_adoption_segments, :display_namespace_id, :integer + end +end diff --git a/db/migrate/20210430124630_add_devops_adoption_indexes.rb b/db/migrate/20210430124630_add_devops_adoption_indexes.rb new file mode 100644 index 00000000000..4531e6b5e4c --- /dev/null +++ b/db/migrate/20210430124630_add_devops_adoption_indexes.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionIndexes < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + SEGMENTS_INDEX_NAME = 'idx_devops_adoption_segments_namespaces_pair' + SNAPSHOT_END_TIME_INDEX_NAME = 'idx_devops_adoption_segments_namespace_end_time' + SNAPSHOT_RECORDED_AT_INDEX_NAME = 'idx_devops_adoption_segments_namespace_recorded_at' + + def up + add_concurrent_index :analytics_devops_adoption_snapshots, [:namespace_id, :end_time], + name: SNAPSHOT_END_TIME_INDEX_NAME + add_concurrent_index :analytics_devops_adoption_snapshots, [:namespace_id, :recorded_at], + name: SNAPSHOT_RECORDED_AT_INDEX_NAME + add_concurrent_index :analytics_devops_adoption_segments, [:display_namespace_id, :namespace_id], + unique: true, name: SEGMENTS_INDEX_NAME + + add_concurrent_foreign_key :analytics_devops_adoption_snapshots, :namespaces, column: :namespace_id + add_concurrent_foreign_key :analytics_devops_adoption_segments, :namespaces, column: :display_namespace_id + end + + def down + remove_foreign_key :analytics_devops_adoption_segments, :namespaces, column: :display_namespace_id + remove_foreign_key :analytics_devops_adoption_snapshots, :namespaces, column: :namespace_id + + remove_concurrent_index_by_name :analytics_devops_adoption_segments, SEGMENTS_INDEX_NAME + remove_concurrent_index_by_name :analytics_devops_adoption_snapshots, SNAPSHOT_RECORDED_AT_INDEX_NAME + remove_concurrent_index_by_name :analytics_devops_adoption_snapshots, SNAPSHOT_END_TIME_INDEX_NAME + end +end diff --git a/db/migrate/20210430154631_add_slice_multiplier_and_max_slices_to_elastic_reindexing_task.rb b/db/migrate/20210430154631_add_slice_multiplier_and_max_slices_to_elastic_reindexing_task.rb new file mode 100644 index 00000000000..be022c1b973 --- /dev/null +++ b/db/migrate/20210430154631_add_slice_multiplier_and_max_slices_to_elastic_reindexing_task.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +class AddSliceMultiplierAndMaxSlicesToElasticReindexingTask < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DEFAULT_MAX_TOTAL_SLICES_RUNNING = 60 + DEFAULT_SLICE_MULTIPLIER = 2 + + def change + add_column :elastic_reindexing_tasks, :max_slices_running, :integer, + limit: 2, + default: DEFAULT_MAX_TOTAL_SLICES_RUNNING, + null: false + add_column :elastic_reindexing_tasks, :slice_multiplier, :integer, + limit: 2, + default: DEFAULT_SLICE_MULTIPLIER, + null: false + end +end diff --git a/db/migrate/20210503105022_create_project_value_streams.rb b/db/migrate/20210503105022_create_project_value_streams.rb new file mode 100644 index 00000000000..775ab03ad4b --- /dev/null +++ b/db/migrate/20210503105022_create_project_value_streams.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CreateProjectValueStreams < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_analytics_ca_project_value_streams_on_project_id_and_name' + + def up + create_table_with_constraints :analytics_cycle_analytics_project_value_streams do |t| + t.timestamps_with_timezone + t.references(:project, + null: false, + index: false, + foreign_key: { to_table: :projects, on_delete: :cascade } + ) + t.text :name, null: false + t.index [:project_id, :name], unique: true, name: INDEX_NAME + t.text_limit :name, 100 + end + end + + def down + with_lock_retries do + drop_table :analytics_cycle_analytics_project_value_streams + end + end +end diff --git a/db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb b/db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb new file mode 100644 index 00000000000..d888ab4943c --- /dev/null +++ b/db/migrate/20210503105845_add_project_value_stream_id_to_project_stages.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class AddProjectValueStreamIdToProjectStages < ActiveRecord::Migration[6.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_analytics_ca_project_stages_on_value_stream_id' + + class ProjectValueStream < ActiveRecord::Base + self.table_name = 'analytics_cycle_analytics_project_stages' + + include EachBatch + end + + def up + ProjectValueStream.reset_column_information + # The table was never used, there is no user-facing code that modifies the table, it should be empty. + # Since there is no functionality present that depends on this data, it's safe to delete the rows. + ProjectValueStream.each_batch(of: 100) do |relation| + relation.delete_all + end + + transaction do + add_reference :analytics_cycle_analytics_project_stages, :project_value_stream, null: false, index: { name: INDEX_NAME }, foreign_key: { on_delete: :cascade, to_table: :analytics_cycle_analytics_project_value_streams }, type: :bigint # rubocop: disable Migration/AddReference, Rails/NotNullColumn + end + end + + def down + remove_reference :analytics_cycle_analytics_project_stages, :project_value_stream + end +end diff --git a/db/migrate/20210503131747_add_web_hook_calls_to_plan_limits.rb b/db/migrate/20210503131747_add_web_hook_calls_to_plan_limits.rb new file mode 100644 index 00000000000..cb23c9391ea --- /dev/null +++ b/db/migrate/20210503131747_add_web_hook_calls_to_plan_limits.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddWebHookCallsToPlanLimits < ActiveRecord::Migration[6.0] + def change + add_column :plan_limits, :web_hook_calls, :integer, null: false, default: 0 + end +end diff --git a/db/migrate/20210504085144_add_index_on_web_hook_project_id_recent_failures.rb b/db/migrate/20210504085144_add_index_on_web_hook_project_id_recent_failures.rb new file mode 100644 index 00000000000..898a0ccd1c5 --- /dev/null +++ b/db/migrate/20210504085144_add_index_on_web_hook_project_id_recent_failures.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexOnWebHookProjectIdRecentFailures < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_web_hooks_on_project_id_recent_failures' + + disable_ddl_transaction! + + def up + add_concurrent_index(:web_hooks, [:project_id, :recent_failures], name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:web_hooks, INDEX_NAME) + end +end diff --git a/db/migrate/20210504135823_add_floc_application_settings.rb b/db/migrate/20210504135823_add_floc_application_settings.rb new file mode 100644 index 00000000000..a5e3aad6b8c --- /dev/null +++ b/db/migrate/20210504135823_add_floc_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddFlocApplicationSettings < ActiveRecord::Migration[6.0] + def change + add_column :application_settings, :floc_enabled, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb b/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb new file mode 100644 index 00000000000..5868325e701 --- /dev/null +++ b/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CreateClustersIntegrationElasticstack < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def change + create_table_with_constraints :clusters_integration_elasticstack, id: false do |t| + t.timestamps_with_timezone null: false + t.references :cluster, primary_key: true, default: nil, index: false, foreign_key: { on_delete: :cascade } + t.boolean :enabled, null: false, default: false + t.text :chart_version + t.text_limit :chart_version, 10 + end + end +end diff --git a/db/migrate/20210504164429_create_partial_indexes_for_pending_and_running_builds.rb b/db/migrate/20210504164429_create_partial_indexes_for_pending_and_running_builds.rb new file mode 100644 index 00000000000..af403faa278 --- /dev/null +++ b/db/migrate/20210504164429_create_partial_indexes_for_pending_and_running_builds.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CreatePartialIndexesForPendingAndRunningBuilds < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_PENDING = 'index_ci_builds_runner_id_pending' + INDEX_RUNNING = 'index_ci_builds_runner_id_running' + + def up + add_concurrent_index :ci_builds, :runner_id, where: "status = 'pending' AND type = 'Ci::Build'", name: INDEX_PENDING + add_concurrent_index :ci_builds, :runner_id, where: "status = 'running' AND type = 'Ci::Build'", name: INDEX_RUNNING + end + + def down + remove_concurrent_index_by_name :ci_builds, INDEX_PENDING + remove_concurrent_index_by_name :ci_builds, INDEX_RUNNING + end +end diff --git a/db/migrate/20210505124816_add_text_limit_to_elasticsearch_username.rb b/db/migrate/20210505124816_add_text_limit_to_elasticsearch_username.rb new file mode 100644 index 00000000000..324b9193efb --- /dev/null +++ b/db/migrate/20210505124816_add_text_limit_to_elasticsearch_username.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToElasticsearchUsername < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :elasticsearch_username, 255 + end + + def down + remove_text_limit :application_settings, :elasticsearch_username + end +end diff --git a/db/migrate/20210507191949_add_remove_on_issue_close_to_labels.rb b/db/migrate/20210507191949_add_remove_on_issue_close_to_labels.rb new file mode 100644 index 00000000000..107388fe533 --- /dev/null +++ b/db/migrate/20210507191949_add_remove_on_issue_close_to_labels.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddRemoveOnIssueCloseToLabels < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :labels, :remove_on_close, :boolean, null: false, default: false + end + end + + def down + with_lock_retries do + remove_column :labels, :remove_on_close, :boolean + end + end +end diff --git a/db/migrate/20210510191551_add_body_to_findings_evidences_request.rb b/db/migrate/20210510191551_add_body_to_findings_evidences_request.rb new file mode 100644 index 00000000000..9b0054dbd22 --- /dev/null +++ b/db/migrate/20210510191551_add_body_to_findings_evidences_request.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddBodyToFindingsEvidencesRequest < ActiveRecord::Migration[6.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210510191552_add_limit_to_findings_evidences_request_body.rb + def change + add_column :vulnerability_finding_evidence_requests, :body, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210510191552_add_limit_to_findings_evidences_request_body.rb b/db/migrate/20210510191552_add_limit_to_findings_evidences_request_body.rb new file mode 100644 index 00000000000..84c8acdb10d --- /dev/null +++ b/db/migrate/20210510191552_add_limit_to_findings_evidences_request_body.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddLimitToFindingsEvidencesRequestBody < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :vulnerability_finding_evidence_requests, :body, 2048 + end + + def down + remove_text_limit :vulnerability_finding_evidence_requests, :body + end +end diff --git a/db/migrate/20210511104929_add_epic_board_recent_visits_table.rb b/db/migrate/20210511104929_add_epic_board_recent_visits_table.rb new file mode 100644 index 00000000000..9822276f9c4 --- /dev/null +++ b/db/migrate/20210511104929_add_epic_board_recent_visits_table.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddEpicBoardRecentVisitsTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + unless table_exists?(:boards_epic_board_recent_visits) + create_table :boards_epic_board_recent_visits do |t| + t.references :user, index: true, null: false, foreign_key: { on_delete: :cascade } + t.references :epic_board, index: true, foreign_key: { to_table: :boards_epic_boards, on_delete: :cascade }, null: false + t.references :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade }, null: false + t.timestamps_with_timezone null: false + end + end + end + end + + def down + with_lock_retries do + drop_table :boards_epic_board_recent_visits + end + end +end diff --git a/db/migrate/20210511104930_add_index_to_epic_board_recent_visits.rb b/db/migrate/20210511104930_add_index_to_epic_board_recent_visits.rb new file mode 100644 index 00000000000..1341886c50c --- /dev/null +++ b/db/migrate/20210511104930_add_index_to_epic_board_recent_visits.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddIndexToEpicBoardRecentVisits < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_epic_board_recent_visits_on_user_group_and_board' + + disable_ddl_transaction! + + def up + add_concurrent_index :boards_epic_board_recent_visits, + [:user_id, :group_id, :epic_board_id], + name: INDEX_NAME, + unique: true + end + + def down + remove_concurrent_index_by_name :boards_epic_board_recent_visits, INDEX_NAME + end +end diff --git a/db/migrate/20210512183309_add_body_to_findings_evidences_response.rb b/db/migrate/20210512183309_add_body_to_findings_evidences_response.rb new file mode 100644 index 00000000000..6884d339b9c --- /dev/null +++ b/db/migrate/20210512183309_add_body_to_findings_evidences_response.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddBodyToFindingsEvidencesResponse < ActiveRecord::Migration[6.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210512183310_add_limit_to_findings_evidences_response_body.rb + def change + add_column :vulnerability_finding_evidence_responses, :body, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210512183310_add_limit_to_findings_evidences_response_body.rb b/db/migrate/20210512183310_add_limit_to_findings_evidences_response_body.rb new file mode 100644 index 00000000000..bdd15163809 --- /dev/null +++ b/db/migrate/20210512183310_add_limit_to_findings_evidences_response_body.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddLimitToFindingsEvidencesResponseBody < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :vulnerability_finding_evidence_responses, :body, 2048 + end + + def down + remove_text_limit :vulnerability_finding_evidence_responses, :body + end +end diff --git a/db/migrate/20210513093418_add_draft_column_to_merge_requests.rb b/db/migrate/20210513093418_add_draft_column_to_merge_requests.rb new file mode 100644 index 00000000000..67e2cc0eea0 --- /dev/null +++ b/db/migrate/20210513093418_add_draft_column_to_merge_requests.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddDraftColumnToMergeRequests < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :merge_requests, :draft, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :merge_requests, :draft + end + end +end |