diff options
Diffstat (limited to 'db/migrate')
63 files changed, 1160 insertions, 7 deletions
diff --git a/db/migrate/20210331000934_add_config_to_ci_runners.rb b/db/migrate/20210331000934_add_config_to_ci_runners.rb new file mode 100644 index 00000000000..e9a5fadc613 --- /dev/null +++ b/db/migrate/20210331000934_add_config_to_ci_runners.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddConfigToCiRunners < ActiveRecord::Migration[6.0] + def change + add_column :ci_runners, :config, :jsonb, default: {}, null: false + end +end diff --git a/db/migrate/20210430121522_initialize_conversion_of_ci_build_trace_sections_to_bigint.rb b/db/migrate/20210430121522_initialize_conversion_of_ci_build_trace_sections_to_bigint.rb new file mode 100644 index 00000000000..c51ae67ebee --- /dev/null +++ b/db/migrate/20210430121522_initialize_conversion_of_ci_build_trace_sections_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiBuildTraceSectionsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_build_trace_sections + COLUMN = :build_id + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMN, primary_key: COLUMN) + end + + def down + revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMN) + end +end diff --git a/db/migrate/20210504143128_add_verification_state_and_started_at_to_mr_diff_details_table.rb b/db/migrate/20210504143128_add_verification_state_and_started_at_to_mr_diff_details_table.rb new file mode 100644 index 00000000000..7999ea14a12 --- /dev/null +++ b/db/migrate/20210504143128_add_verification_state_and_started_at_to_mr_diff_details_table.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddVerificationStateAndStartedAtToMrDiffDetailsTable < ActiveRecord::Migration[6.0] + def change + change_table(:merge_request_diff_details) do |t| + t.integer :verification_state, default: 0, limit: 2, null: false + t.column :verification_started_at, :datetime_with_timezone + end + end +end diff --git a/db/migrate/20210505070612_create_packages_debian_group_distribution_keys.rb b/db/migrate/20210505070612_create_packages_debian_group_distribution_keys.rb new file mode 100644 index 00000000000..1e79b4e29b0 --- /dev/null +++ b/db/migrate/20210505070612_create_packages_debian_group_distribution_keys.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class CreatePackagesDebianGroupDistributionKeys < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_DISTRIBUTION = 'idx_pkgs_debian_group_distribution_keys_on_distribution_id' + + disable_ddl_transaction! + + def up + create_table_with_constraints :packages_debian_group_distribution_keys do |t| + t.timestamps_with_timezone + t.references :distribution, + foreign_key: { to_table: :packages_debian_group_distributions, on_delete: :cascade }, + index: { name: INDEX_DISTRIBUTION }, + null: false + + t.text :encrypted_private_key, null: false + t.text :encrypted_private_key_iv, null: false + t.text :encrypted_passphrase, null: false + t.text :encrypted_passphrase_iv, null: false + t.text :public_key, null: false + t.text :fingerprint, null: false + + t.text_limit :public_key, 512.kilobytes + t.text_limit :fingerprint, 255 + end + end + + def down + with_lock_retries do + drop_table :packages_debian_group_distribution_keys + end + end +end diff --git a/db/migrate/20210505070812_create_packages_debian_project_distribution_keys.rb b/db/migrate/20210505070812_create_packages_debian_project_distribution_keys.rb new file mode 100644 index 00000000000..f5ec01ec0d6 --- /dev/null +++ b/db/migrate/20210505070812_create_packages_debian_project_distribution_keys.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class CreatePackagesDebianProjectDistributionKeys < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_DISTRIBUTION = 'idx_pkgs_debian_project_distribution_keys_on_distribution_id' + + disable_ddl_transaction! + + def up + create_table_with_constraints :packages_debian_project_distribution_keys do |t| + t.timestamps_with_timezone + t.references :distribution, + foreign_key: { to_table: :packages_debian_project_distributions, on_delete: :cascade }, + index: { name: INDEX_DISTRIBUTION }, + null: false + + t.text :encrypted_private_key, null: false + t.text :encrypted_private_key_iv, null: false + t.text :encrypted_passphrase, null: false + t.text :encrypted_passphrase_iv, null: false + t.text :public_key, null: false + t.text :fingerprint, null: false + + t.text_limit :public_key, 512.kilobytes + t.text_limit :fingerprint, 255 + end + end + + def down + with_lock_retries do + drop_table :packages_debian_project_distribution_keys + end + end +end diff --git a/db/migrate/20210505170152_add_verification_indexes_to_merge_request_diff_details_table.rb b/db/migrate/20210505170152_add_verification_indexes_to_merge_request_diff_details_table.rb new file mode 100644 index 00000000000..e85a28e3fa7 --- /dev/null +++ b/db/migrate/20210505170152_add_verification_indexes_to_merge_request_diff_details_table.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class AddVerificationIndexesToMergeRequestDiffDetailsTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + VERIFICATION_STATE_INDEX_NAME = "index_merge_request_diff_details_on_verification_state" + PENDING_VERIFICATION_INDEX_NAME = "index_merge_request_diff_details_pending_verification" + FAILED_VERIFICATION_INDEX_NAME = "index_merge_request_diff_details_failed_verification" + NEEDS_VERIFICATION_INDEX_NAME = "index_merge_request_diff_details_needs_verification" + + disable_ddl_transaction! + + def up + add_concurrent_index :merge_request_diff_details, :verification_state, name: VERIFICATION_STATE_INDEX_NAME + add_concurrent_index :merge_request_diff_details, :verified_at, where: "(verification_state = 0)", order: { verified_at: 'ASC NULLS FIRST' }, name: PENDING_VERIFICATION_INDEX_NAME + add_concurrent_index :merge_request_diff_details, :verification_retry_at, where: "(verification_state = 3)", order: { verification_retry_at: 'ASC NULLS FIRST' }, name: FAILED_VERIFICATION_INDEX_NAME + add_concurrent_index :merge_request_diff_details, :verification_state, where: "(verification_state = 0 OR verification_state = 3)", name: NEEDS_VERIFICATION_INDEX_NAME + end + + def down + remove_concurrent_index_by_name :merge_request_diff_details, VERIFICATION_STATE_INDEX_NAME + remove_concurrent_index_by_name :merge_request_diff_details, PENDING_VERIFICATION_INDEX_NAME + remove_concurrent_index_by_name :merge_request_diff_details, FAILED_VERIFICATION_INDEX_NAME + remove_concurrent_index_by_name :merge_request_diff_details, NEEDS_VERIFICATION_INDEX_NAME + end +end diff --git a/db/migrate/20210506150833_create_vulnerability_finding_evidence_headers.rb b/db/migrate/20210506150833_create_vulnerability_finding_evidence_headers.rb new file mode 100644 index 00000000000..0e584303e51 --- /dev/null +++ b/db/migrate/20210506150833_create_vulnerability_finding_evidence_headers.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingEvidenceHeaders < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table_with_constraints :vulnerability_finding_evidence_headers do |t| + t.timestamps_with_timezone null: false + + t.references :vulnerability_finding_evidence_request, index: { name: 'finding_evidence_header_on_finding_evidence_request_id' }, null: true, foreign_key: { on_delete: :cascade } + t.references :vulnerability_finding_evidence_response, index: { name: 'finding_evidence_header_on_finding_evidence_response_id' }, null: true, foreign_key: { on_delete: :cascade } + t.text :name, null: false + t.text :value, null: false + + t.text_limit :name, 255 + t.text_limit :value, 8192 + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_evidence_headers + end + 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 index 107388fe533..131edb20164 100644 --- a/db/migrate/20210507191949_add_remove_on_issue_close_to_labels.rb +++ b/db/migrate/20210507191949_add_remove_on_issue_close_to_labels.rb @@ -1,17 +1,11 @@ # frozen_string_literal: true class AddRemoveOnIssueCloseToLabels < ActiveRecord::Migration[6.0] - include Gitlab::Database::MigrationHelpers + # This migration was reverted in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62056 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/20210510083845_add_sha_to_status_check_response.rb b/db/migrate/20210510083845_add_sha_to_status_check_response.rb new file mode 100644 index 00000000000..202f5ca00c1 --- /dev/null +++ b/db/migrate/20210510083845_add_sha_to_status_check_response.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddShaToStatusCheckResponse < ActiveRecord::Migration[6.0] + def up + execute('DELETE FROM status_check_responses') + + add_column :status_check_responses, :sha, :binary, null: false # rubocop:disable Rails/NotNullColumn + end + + def down + remove_column :status_check_responses, :sha + end +end diff --git a/db/migrate/20210511165250_add_foreign_key_to_lfs_objects_projects.rb b/db/migrate/20210511165250_add_foreign_key_to_lfs_objects_projects.rb new file mode 100644 index 00000000000..4163499a553 --- /dev/null +++ b/db/migrate/20210511165250_add_foreign_key_to_lfs_objects_projects.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddForeignKeyToLfsObjectsProjects < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :lfs_objects_projects, :lfs_objects, column: :lfs_object_id, on_delete: :restrict, validate: false + add_concurrent_foreign_key :lfs_objects_projects, :projects, column: :project_id, on_delete: :cascade, validate: false + end + + def down + with_lock_retries do + remove_foreign_key :lfs_objects_projects, column: :lfs_object_id + remove_foreign_key :lfs_objects_projects, column: :project_id + end + end +end diff --git a/db/migrate/20210512120122_add_pending_builds_table.rb b/db/migrate/20210512120122_add_pending_builds_table.rb new file mode 100644 index 00000000000..38e13d43b38 --- /dev/null +++ b/db/migrate/20210512120122_add_pending_builds_table.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddPendingBuildsTable < ActiveRecord::Migration[6.0] + def up + create_table :ci_pending_builds do |t| + t.references :build, index: { unique: true }, null: false, foreign_key: { to_table: :ci_builds, on_delete: :cascade } + t.references :project, index: true, null: false, foreign_key: { on_delete: :cascade } + t.datetime_with_timezone :created_at, null: false, default: -> { 'NOW()' } + end + end + + def down + drop_table :ci_pending_builds + end +end diff --git a/db/migrate/20210517130723_make_snapshot_segment_id_optional.rb b/db/migrate/20210517130723_make_snapshot_segment_id_optional.rb new file mode 100644 index 00000000000..a05be71a243 --- /dev/null +++ b/db/migrate/20210517130723_make_snapshot_segment_id_optional.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class MakeSnapshotSegmentIdOptional < ActiveRecord::Migration[6.0] + def up + change_column_null(:analytics_devops_adoption_snapshots, :segment_id, true) + end + + def down + change_column_null(:analytics_devops_adoption_snapshots, :segment_id, false) + end +end diff --git a/db/migrate/20210517144856_require_snapshot_namespace.rb b/db/migrate/20210517144856_require_snapshot_namespace.rb new file mode 100644 index 00000000000..ec25c13383f --- /dev/null +++ b/db/migrate/20210517144856_require_snapshot_namespace.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require Rails.root.join('db', 'post_migrate', '20210430134202_copy_adoption_snapshot_namespace.rb') + +class RequireSnapshotNamespace < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + CopyAdoptionSnapshotNamespace.new.up + + add_not_null_constraint(:analytics_devops_adoption_snapshots, :namespace_id) + end + + def down + remove_not_null_constraint(:analytics_devops_adoption_snapshots, :namespace_id) + end +end diff --git a/db/migrate/20210517221612_add_default_value_to_merge_requests_author_approval_on_projects.rb b/db/migrate/20210517221612_add_default_value_to_merge_requests_author_approval_on_projects.rb new file mode 100644 index 00000000000..1c017a366c8 --- /dev/null +++ b/db/migrate/20210517221612_add_default_value_to_merge_requests_author_approval_on_projects.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddDefaultValueToMergeRequestsAuthorApprovalOnProjects < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + change_column_default :projects, :merge_requests_author_approval, false + end + end + + def down + with_lock_retries do + change_column_default :projects, :merge_requests_author_approval, nil + end + end +end diff --git a/db/migrate/20210519132109_initialize_conversion_of_ci_builds_metadata_to_bigint.rb b/db/migrate/20210519132109_initialize_conversion_of_ci_builds_metadata_to_bigint.rb new file mode 100644 index 00000000000..7ff0276b4b5 --- /dev/null +++ b/db/migrate/20210519132109_initialize_conversion_of_ci_builds_metadata_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiBuildsMetadataToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_builds_metadata + COLUMN = :build_id + + def up + initialize_conversion_of_integer_to_bigint(TABLE, COLUMN) + end + + def down + revert_initialize_conversion_of_integer_to_bigint(TABLE, COLUMN) + end +end diff --git a/db/migrate/20210520102039_group_protected_environments_add_column.rb b/db/migrate/20210520102039_group_protected_environments_add_column.rb new file mode 100644 index 00000000000..642e22c5f48 --- /dev/null +++ b/db/migrate/20210520102039_group_protected_environments_add_column.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class GroupProtectedEnvironmentsAddColumn < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + add_column :protected_environments, :group_id, :bigint + change_column_null :protected_environments, :project_id, true + end + + def down + change_column_null :protected_environments, :project_id, false + remove_column :protected_environments, :group_id + end +end diff --git a/db/migrate/20210520133032_initialize_conversion_of_taggings_to_bigint.rb b/db/migrate/20210520133032_initialize_conversion_of_taggings_to_bigint.rb new file mode 100644 index 00000000000..e154c25b082 --- /dev/null +++ b/db/migrate/20210520133032_initialize_conversion_of_taggings_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfTaggingsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :taggings + COLUMNS = %i(id taggable_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/20210520133440_backfill_taggings_for_bigint_conversion.rb b/db/migrate/20210520133440_backfill_taggings_for_bigint_conversion.rb new file mode 100644 index 00000000000..63ac308e4be --- /dev/null +++ b/db/migrate/20210520133440_backfill_taggings_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillTaggingsForBigintConversion < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :taggings + COLUMNS = %i(id taggable_id) + + def up + backfill_conversion_of_integer_to_bigint TABLE, COLUMNS, batch_size: 15000, sub_batch_size: 100 + end + + def down + revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMNS + end +end diff --git a/db/migrate/20210521073920_drop_devops_adoption_namespace_uniqueness.rb b/db/migrate/20210521073920_drop_devops_adoption_namespace_uniqueness.rb new file mode 100644 index 00000000000..d255ce844e2 --- /dev/null +++ b/db/migrate/20210521073920_drop_devops_adoption_namespace_uniqueness.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class DropDevopsAdoptionNamespaceUniqueness < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_analytics_devops_adoption_segments_on_namespace_id' + NEW_INDEX_NAME = 'idx_analytics_devops_adoption_segments_on_namespace_id' + + def up + add_concurrent_index :analytics_devops_adoption_segments, :namespace_id, name: NEW_INDEX_NAME + remove_concurrent_index_by_name :analytics_devops_adoption_segments, INDEX_NAME + end + + def down + # Clean up duplicated records + execute "DELETE FROM analytics_devops_adoption_segments WHERE id NOT IN (SELECT MIN(id) FROM analytics_devops_adoption_segments GROUP BY namespace_id)" + + add_concurrent_index :analytics_devops_adoption_segments, :namespace_id, name: INDEX_NAME, unique: true + remove_concurrent_index_by_name :analytics_devops_adoption_segments, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20210525085158_initialize_conversion_of_deployments_to_bigint.rb b/db/migrate/20210525085158_initialize_conversion_of_deployments_to_bigint.rb new file mode 100644 index 00000000000..70775eb3bb5 --- /dev/null +++ b/db/migrate/20210525085158_initialize_conversion_of_deployments_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfDeploymentsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :deployments + COLUMNS = %i(deployable_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/20210525085325_backfill_deployments_for_bigint_conversion.rb b/db/migrate/20210525085325_backfill_deployments_for_bigint_conversion.rb new file mode 100644 index 00000000000..6de89cadef8 --- /dev/null +++ b/db/migrate/20210525085325_backfill_deployments_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillDeploymentsForBigintConversion < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :deployments + COLUMNS = %i(deployable_id) + + def up + backfill_conversion_of_integer_to_bigint TABLE, COLUMNS + end + + def down + revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMNS + end +end diff --git a/db/migrate/20210525100539_initialize_conversion_of_geo_job_artifact_deleted_events_to_bigint.rb b/db/migrate/20210525100539_initialize_conversion_of_geo_job_artifact_deleted_events_to_bigint.rb new file mode 100644 index 00000000000..3e8bcf1851a --- /dev/null +++ b/db/migrate/20210525100539_initialize_conversion_of_geo_job_artifact_deleted_events_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfGeoJobArtifactDeletedEventsToBigint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :geo_job_artifact_deleted_events + COLUMNS = %i(job_artifact_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/20210525100603_backfill_geo_job_artifact_deleted_events_for_bigint_conversion.rb b/db/migrate/20210525100603_backfill_geo_job_artifact_deleted_events_for_bigint_conversion.rb new file mode 100644 index 00000000000..eab79a33006 --- /dev/null +++ b/db/migrate/20210525100603_backfill_geo_job_artifact_deleted_events_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillGeoJobArtifactDeletedEventsForBigintConversion < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + TABLE = :geo_job_artifact_deleted_events + COLUMNS = %i(job_artifact_id) + + def up + backfill_conversion_of_integer_to_bigint TABLE, COLUMNS + end + + def down + revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMNS + end +end diff --git a/db/migrate/20210525184900_add_latest_pipeline_id_into_vulnerability_statistics_table.rb b/db/migrate/20210525184900_add_latest_pipeline_id_into_vulnerability_statistics_table.rb new file mode 100644 index 00000000000..508ad92f9e5 --- /dev/null +++ b/db/migrate/20210525184900_add_latest_pipeline_id_into_vulnerability_statistics_table.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddLatestPipelineIdIntoVulnerabilityStatisticsTable < ActiveRecord::Migration[6.0] + def change + add_column :vulnerability_statistics, :latest_pipeline_id, :bigint + end +end diff --git a/db/migrate/20210526135911_create_ci_minutes_additional_packs.rb b/db/migrate/20210526135911_create_ci_minutes_additional_packs.rb new file mode 100644 index 00000000000..3464268a77f --- /dev/null +++ b/db/migrate/20210526135911_create_ci_minutes_additional_packs.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class CreateCiMinutesAdditionalPacks < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + create_table_with_constraints :ci_minutes_additional_packs, if_not_exists: true do |t| + t.timestamps_with_timezone + + t.references :namespace, index: false, null: false, foreign_key: { on_delete: :cascade } + t.date :expires_at, null: true + t.integer :number_of_minutes, null: false + t.text :purchase_xid, null: true + t.text_limit :purchase_xid, 32 + + t.index [:namespace_id, :purchase_xid], name: 'index_ci_minutes_additional_packs_on_namespace_id_purchase_xid' + end + end + + def down + with_lock_retries do + drop_table :ci_minutes_additional_packs + end + end +end diff --git a/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb b/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb new file mode 100644 index 00000000000..b9cefe456b8 --- /dev/null +++ b/db/migrate/20210526155257_rename_sync_security_report_approval_rules_sidekiq_queue.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RenameSyncSecurityReportApprovalRulesSidekiqQueue < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + sidekiq_queue_migrate 'sync_security_reports_to_report_approval_rules', to: 'ci_sync_reports_to_report_approval_rules' + end + + def down + sidekiq_queue_migrate 'ci_sync_reports_to_report_approval_rules', to: 'sync_security_reports_to_report_approval_rules' + end +end diff --git a/db/migrate/20210526181820_add_index_to_vulnerability_statistics_on_latest_pipeline_id.rb b/db/migrate/20210526181820_add_index_to_vulnerability_statistics_on_latest_pipeline_id.rb new file mode 100644 index 00000000000..dd11b1e6f11 --- /dev/null +++ b/db/migrate/20210526181820_add_index_to_vulnerability_statistics_on_latest_pipeline_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToVulnerabilityStatisticsOnLatestPipelineId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_vulnerability_statistics_on_latest_pipeline_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerability_statistics, :latest_pipeline_id, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerability_statistics, INDEX_NAME + end +end diff --git a/db/migrate/20210526181821_add_foreign_key_for_latest_pipeline_id_to_ci_pipelines.rb b/db/migrate/20210526181821_add_foreign_key_for_latest_pipeline_id_to_ci_pipelines.rb new file mode 100644 index 00000000000..adcac5e2637 --- /dev/null +++ b/db/migrate/20210526181821_add_foreign_key_for_latest_pipeline_id_to_ci_pipelines.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddForeignKeyForLatestPipelineIdToCiPipelines < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :vulnerability_statistics, :ci_pipelines, column: :latest_pipeline_id, on_delete: :nullify + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :vulnerability_statistics, :ci_pipelines + end + end +end diff --git a/db/migrate/20210526190259_add_ci_daily_pipeline_schedule_triggers_to_plan_limits.rb b/db/migrate/20210526190259_add_ci_daily_pipeline_schedule_triggers_to_plan_limits.rb new file mode 100644 index 00000000000..074bec31160 --- /dev/null +++ b/db/migrate/20210526190259_add_ci_daily_pipeline_schedule_triggers_to_plan_limits.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddCiDailyPipelineScheduleTriggersToPlanLimits < ActiveRecord::Migration[6.0] + def change + add_column(:plan_limits, :ci_daily_pipeline_schedule_triggers, :integer, default: 0, null: false) + end +end diff --git a/db/migrate/20210526190553_insert_ci_daily_pipeline_schedule_triggers_plan_limits.rb b/db/migrate/20210526190553_insert_ci_daily_pipeline_schedule_triggers_plan_limits.rb new file mode 100644 index 00000000000..fe0969c15fb --- /dev/null +++ b/db/migrate/20210526190553_insert_ci_daily_pipeline_schedule_triggers_plan_limits.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class InsertCiDailyPipelineScheduleTriggersPlanLimits < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + EVERY_5_MINUTES = (1.day.in_minutes / 5).to_i + EVERY_HOUR = 1.day.in_hours.to_i + + def up + return unless Gitlab.com? + + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'free', EVERY_HOUR) + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'bronze', EVERY_5_MINUTES) + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'silver', EVERY_5_MINUTES) + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'gold', EVERY_5_MINUTES) + end + + def down + return unless Gitlab.com? + + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'free', 0) + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'bronze', 0) + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'silver', 0) + create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', 'gold', 0) + end +end diff --git a/db/migrate/20210527065005_add_index_for_cadence_iterations_automation.rb b/db/migrate/20210527065005_add_index_for_cadence_iterations_automation.rb new file mode 100644 index 00000000000..62ccdb6a4fd --- /dev/null +++ b/db/migrate/20210527065005_add_index_for_cadence_iterations_automation.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexForCadenceIterationsAutomation < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'cadence_create_iterations_automation' + + disable_ddl_transaction! + + def up + # no-op + end + + def down + # no-op + end +end diff --git a/db/migrate/20210527130524_rename_experiment_subjects_group_id_to_namespace_id.rb b/db/migrate/20210527130524_rename_experiment_subjects_group_id_to_namespace_id.rb new file mode 100644 index 00000000000..5f60a7f25c2 --- /dev/null +++ b/db/migrate/20210527130524_rename_experiment_subjects_group_id_to_namespace_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class RenameExperimentSubjectsGroupIdToNamespaceId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers::V2 + + disable_ddl_transaction! + + def up + rename_column_concurrently :experiment_subjects, :group_id, :namespace_id + end + + def down + undo_rename_column_concurrently :experiment_subjects, :group_id, :namespace_id + end +end diff --git a/db/migrate/20210527133919_add_diff_max_lines_to_application_settings.rb b/db/migrate/20210527133919_add_diff_max_lines_to_application_settings.rb new file mode 100644 index 00000000000..9c1cd94dbaa --- /dev/null +++ b/db/migrate/20210527133919_add_diff_max_lines_to_application_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddDiffMaxLinesToApplicationSettings < ActiveRecord::Migration[6.0] + def change + add_column(:application_settings, + :diff_max_lines, + :integer, + default: 50000, + null: false) + end +end diff --git a/db/migrate/20210527134019_add_diff_max_files_to_application_settings.rb b/db/migrate/20210527134019_add_diff_max_files_to_application_settings.rb new file mode 100644 index 00000000000..60b1f74cfd0 --- /dev/null +++ b/db/migrate/20210527134019_add_diff_max_files_to_application_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddDiffMaxFilesToApplicationSettings < ActiveRecord::Migration[6.0] + def change + add_column(:application_settings, + :diff_max_files, + :integer, + default: 1000, + null: false) + end +end diff --git a/db/migrate/20210527185542_add_prevent_sharing_groups_outside_hierarchy_to_namespace_settings.rb b/db/migrate/20210527185542_add_prevent_sharing_groups_outside_hierarchy_to_namespace_settings.rb new file mode 100644 index 00000000000..8fb489ac537 --- /dev/null +++ b/db/migrate/20210527185542_add_prevent_sharing_groups_outside_hierarchy_to_namespace_settings.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddPreventSharingGroupsOutsideHierarchyToNamespaceSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :namespace_settings, :prevent_sharing_groups_outside_hierarchy, :boolean, null: false, default: false + end + end + + def down + with_lock_retries do + remove_column :namespace_settings, :prevent_sharing_groups_outside_hierarchy + end + end +end diff --git a/db/migrate/20210527194558_create_ci_job_token_project_scope_links.rb b/db/migrate/20210527194558_create_ci_job_token_project_scope_links.rb new file mode 100644 index 00000000000..aaa94b9a231 --- /dev/null +++ b/db/migrate/20210527194558_create_ci_job_token_project_scope_links.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CreateCiJobTokenProjectScopeLinks < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + create_table :ci_job_token_project_scope_links, if_not_exists: true do |t| + t.belongs_to :source_project, index: false, null: false, foreign_key: { to_table: :projects, on_delete: :cascade } + t.belongs_to :target_project, null: false, foreign_key: { to_table: :projects, on_delete: :cascade } + t.belongs_to :added_by, foreign_key: { to_table: :users, on_delete: :nullify } + t.datetime_with_timezone :created_at, null: false + + t.index [:source_project_id, :target_project_id], unique: true, name: 'i_ci_job_token_project_scope_links_on_source_and_target_project' + end + end + end + + def down + with_lock_retries do + drop_table :ci_job_token_project_scope_links, if_exists: true + end + end +end diff --git a/db/migrate/20210529164247_change_iterations_title_uniqueness_index.rb b/db/migrate/20210529164247_change_iterations_title_uniqueness_index.rb new file mode 100644 index 00000000000..47e7e2c757d --- /dev/null +++ b/db/migrate/20210529164247_change_iterations_title_uniqueness_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class ChangeIterationsTitleUniquenessIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_sprints_on_iterations_cadence_id_and_title' + OLD_INDEX_NAME = 'index_sprints_on_group_id_and_title' + + disable_ddl_transaction! + + def up + add_concurrent_index :sprints, [:iterations_cadence_id, :title], name: INDEX_NAME, unique: true + remove_concurrent_index_by_name :sprints, OLD_INDEX_NAME + end + + def down + # noop + # rollback would not work as we can have duplicate records once the unique `index_sprints_on_group_id_and_title` index is removed + end +end diff --git a/db/migrate/20210531053916_rename_instance_statistics_measurements.rb b/db/migrate/20210531053916_rename_instance_statistics_measurements.rb new file mode 100644 index 00000000000..9fd459b1275 --- /dev/null +++ b/db/migrate/20210531053916_rename_instance_statistics_measurements.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class RenameInstanceStatisticsMeasurements < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + rename_table_safely(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements) + end + + def down + undo_rename_table_safely(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements) + end +end diff --git a/db/migrate/20210531070452_default_enforce_ssh_key_expiration.rb b/db/migrate/20210531070452_default_enforce_ssh_key_expiration.rb new file mode 100644 index 00000000000..8ddbb528962 --- /dev/null +++ b/db/migrate/20210531070452_default_enforce_ssh_key_expiration.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class DefaultEnforceSshKeyExpiration < ActiveRecord::Migration[6.0] + def change + change_column_default(:application_settings, :enforce_ssh_key_expiration, from: false, to: true) + end +end diff --git a/db/migrate/20210531071107_enable_enforce_ssh_key_expiration.rb b/db/migrate/20210531071107_enable_enforce_ssh_key_expiration.rb new file mode 100644 index 00000000000..c164183fbf8 --- /dev/null +++ b/db/migrate/20210531071107_enable_enforce_ssh_key_expiration.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class EnableEnforceSshKeyExpiration < ActiveRecord::Migration[6.0] + class ApplicationSetting < ActiveRecord::Base + self.table_name = 'application_settings' + end + + def up + ApplicationSetting.reset_column_information + + ApplicationSetting.where.not(enforce_ssh_key_expiration: true).each do |application_setting| + application_setting.update!(enforce_ssh_key_expiration: true) + end + end +end diff --git a/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb b/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb new file mode 100644 index 00000000000..611619e496c --- /dev/null +++ b/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class GroupProtectedEnvironmentsAddIndexAndConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_protected_environments_on_group_id_and_name' + + disable_ddl_transaction! + + def up + add_concurrent_index :protected_environments, [:group_id, :name], unique: true, + name: INDEX_NAME, where: 'group_id IS NOT NULL' + add_concurrent_foreign_key :protected_environments, :namespaces, column: :group_id, on_delete: :cascade + + add_check_constraint :protected_environments, + "((project_id IS NULL) != (group_id IS NULL))", + :protected_environments_project_or_group_existence + end + + def down + remove_group_protected_environments! + + remove_check_constraint :protected_environments, :protected_environments_project_or_group_existence + remove_foreign_key_if_exists :protected_environments, column: :group_id + remove_concurrent_index_by_name :protected_environments, name: INDEX_NAME + end + + private + + def remove_group_protected_environments! + execute <<-SQL + DELETE FROM protected_environments WHERE group_id IS NOT NULL + SQL + end +end diff --git a/db/migrate/20210601123341_add_running_builds_table.rb b/db/migrate/20210601123341_add_running_builds_table.rb new file mode 100644 index 00000000000..4093619d2c3 --- /dev/null +++ b/db/migrate/20210601123341_add_running_builds_table.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddRunningBuildsTable < ActiveRecord::Migration[6.0] + def up + create_table :ci_running_builds do |t| + t.references :build, index: { unique: true }, null: false, foreign_key: { to_table: :ci_builds, on_delete: :cascade } + t.references :project, index: true, null: false, foreign_key: { on_delete: :cascade } + t.references :runner, index: true, null: false, foreign_key: { to_table: :ci_runners, on_delete: :cascade } + t.datetime_with_timezone :created_at, null: false, default: -> { 'NOW()' } + t.integer :runner_type, limit: 2, null: false + end + end + + def down + drop_table :ci_running_builds + end +end diff --git a/db/migrate/20210601125410_add_runners_created_at_index.rb b/db/migrate/20210601125410_add_runners_created_at_index.rb new file mode 100644 index 00000000000..6a6be6d8480 --- /dev/null +++ b/db/migrate/20210601125410_add_runners_created_at_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddRunnersCreatedAtIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_runners, [:created_at, :id], order: { id: :desc }, name: 'index_ci_runners_on_created_at_and_id_desc' + add_concurrent_index :ci_runners, [:created_at, :id], order: { created_at: :desc, id: :desc }, name: 'index_ci_runners_on_created_at_desc_and_id_desc' + end + + def down + remove_concurrent_index :ci_runners, [:created_at, :id], order: { id: :desc }, name: 'index_ci_runners_on_created_at_and_id_desc' + remove_concurrent_index :ci_runners, [:created_at, :id], order: { created_at: :desc, id: :desc }, name: 'index_ci_runners_on_created_at_desc_and_id_desc' + end +end diff --git a/db/migrate/20210601131742_update_web_hook_calls_limit.rb b/db/migrate/20210601131742_update_web_hook_calls_limit.rb new file mode 100644 index 00000000000..6af0facd17d --- /dev/null +++ b/db/migrate/20210601131742_update_web_hook_calls_limit.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class UpdateWebHookCallsLimit < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + return unless Gitlab.com? + + create_or_update_plan_limit('web_hook_calls', 'free', 120) + end + + def down + return unless Gitlab.com? + + create_or_update_plan_limit('web_hook_calls', 'free', 0) + end +end diff --git a/db/migrate/20210601133459_replace_runners_contacted_at_index.rb b/db/migrate/20210601133459_replace_runners_contacted_at_index.rb new file mode 100644 index 00000000000..a0a933721f0 --- /dev/null +++ b/db/migrate/20210601133459_replace_runners_contacted_at_index.rb @@ -0,0 +1,26 @@ +# 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 ReplaceRunnersContactedAtIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_ci_runners_on_contacted_at' + + def up + add_concurrent_index :ci_runners, [:contacted_at, :id], order: { id: :desc }, name: 'index_ci_runners_on_contacted_at_and_id_desc', using: 'btree' + add_concurrent_index :ci_runners, [:contacted_at, :id], order: { contacted_at: :desc, id: :desc }, name: 'index_ci_runners_on_contacted_at_desc_and_id_desc', using: 'btree' + + remove_concurrent_index_by_name :ci_runners, OLD_INDEX_NAME + end + + def down + remove_concurrent_index_by_name :ci_runners, 'index_ci_runners_on_contacted_at_and_id_desc' + remove_concurrent_index_by_name :ci_runners, 'index_ci_runners_on_contacted_at_desc_and_id_desc' + + add_concurrent_index :ci_runners, :contacted_at, name: OLD_INDEX_NAME, using: 'btree' + end +end diff --git a/db/migrate/20210602122213_add_upcoming_reconciliations.rb b/db/migrate/20210602122213_add_upcoming_reconciliations.rb new file mode 100644 index 00000000000..90d0013b357 --- /dev/null +++ b/db/migrate/20210602122213_add_upcoming_reconciliations.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddUpcomingReconciliations < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + create_table :upcoming_reconciliations do |t| + t.references :namespace, index: { unique: true }, null: true, foreign_key: { on_delete: :cascade } + t.date :next_reconciliation_date, null: false + t.date :display_alert_from, null: false + + t.timestamps_with_timezone + end + end + end + + def down + with_lock_retries do + drop_table :upcoming_reconciliations + end + end +end diff --git a/db/migrate/20210602122233_add_runners_description_index.rb b/db/migrate/20210602122233_add_runners_description_index.rb new file mode 100644 index 00000000000..ae779e62f0f --- /dev/null +++ b/db/migrate/20210602122233_add_runners_description_index.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddRunnersDescriptionIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'index_ci_runners_on_description_trigram' + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_runners, :description, name: INDEX_NAME, using: :gin, opclass: { description: :gin_trgm_ops } + end + + def down + remove_concurrent_index_by_name :ci_runners, INDEX_NAME + end +end diff --git a/db/migrate/20210603140302_add_pronouns_to_user_details.rb b/db/migrate/20210603140302_add_pronouns_to_user_details.rb new file mode 100644 index 00000000000..f28d45bdf6f --- /dev/null +++ b/db/migrate/20210603140302_add_pronouns_to_user_details.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddPronounsToUserDetails < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210607050531_add_text_limit_to_user_details_pronouns + with_lock_retries do + add_column :user_details, :pronouns, :text, null: true + end + # rubocop:enable Migration/AddLimitToTextColumns + end + + def down + with_lock_retries do + remove_column :user_details, :pronouns + end + end +end diff --git a/db/migrate/20210603222333_remove_builds_email_service_from_services.rb b/db/migrate/20210603222333_remove_builds_email_service_from_services.rb new file mode 100644 index 00000000000..791b8b659af --- /dev/null +++ b/db/migrate/20210603222333_remove_builds_email_service_from_services.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveBuildsEmailServiceFromServices < ActiveRecord::Migration[6.1] + def up + execute("DELETE from services WHERE type = 'BuildsEmailService'") + end + + def down + # no-op + end +end diff --git a/db/migrate/20210604082145_create_external_status_checks_table.rb b/db/migrate/20210604082145_create_external_status_checks_table.rb new file mode 100644 index 00000000000..c1ad3df6c9e --- /dev/null +++ b/db/migrate/20210604082145_create_external_status_checks_table.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class CreateExternalStatusChecksTable < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + def up + create_table_with_constraints :external_status_checks, if_not_exists: true do |t| + t.references :project, foreign_key: { on_delete: :cascade }, null: false, index: false + t.timestamps_with_timezone + t.text :external_url, null: false + t.text_limit :external_url, 255 + t.text :name, null: false + t.text_limit :name, 255 + + t.index([:project_id, :name], + unique: true, + name: 'idx_on_external_status_checks_project_id_name') + t.index([:project_id, :external_url], + unique: true, + name: 'idx_on_external_status_checks_project_id_external_url') + end + + create_table :external_status_checks_protected_branches do |t| + t.bigint :external_status_check_id, null: false + t.bigint :protected_branch_id, null: false + + t.index :external_status_check_id, name: 'index_esc_protected_branches_on_external_status_check_id' + t.index :protected_branch_id, name: 'index_esc_protected_branches_on_protected_branch_id' + end + end + + def down + with_lock_retries do + drop_table :external_status_checks_protected_branches, force: :cascade, if_exists: true + end + + with_lock_retries do + drop_table :external_status_checks, force: :cascade, if_exists: true + end + end +end diff --git a/db/migrate/20210604085600_rename_status_check_responses_approval_rule.rb b/db/migrate/20210604085600_rename_status_check_responses_approval_rule.rb new file mode 100644 index 00000000000..a12aef9455d --- /dev/null +++ b/db/migrate/20210604085600_rename_status_check_responses_approval_rule.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true +class RenameStatusCheckResponsesApprovalRule < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + execute('DELETE FROM status_check_responses') + + unless column_exists?(:status_check_responses, :external_status_check_id) + add_column :status_check_responses, :external_status_check_id, :bigint, null: false # rubocop:disable Rails/NotNullColumn + end + + add_concurrent_foreign_key :status_check_responses, :external_status_checks, column: :external_status_check_id, on_delete: :cascade + add_concurrent_foreign_key :status_check_responses, :merge_requests, column: :merge_request_id, on_delete: :cascade + + add_concurrent_index :status_check_responses, :external_status_check_id + + # Setting this to true so that we can remove the column in a future release once the column has been removed. It has been ignored in 14.0 + change_column_null :status_check_responses, :external_approval_rule_id, true + + with_lock_retries do + remove_foreign_key :status_check_responses, :external_approval_rules + end + end + + def down + change_column_null :status_check_responses, :external_approval_rule_id, false + with_lock_retries do + add_foreign_key :status_check_responses, :external_approval_rules + end + remove_column :status_check_responses, :external_status_check_id + end +end diff --git a/db/migrate/20210607050531_add_text_limit_to_user_details_pronouns.rb b/db/migrate/20210607050531_add_text_limit_to_user_details_pronouns.rb new file mode 100644 index 00000000000..41c543e5deb --- /dev/null +++ b/db/migrate/20210607050531_add_text_limit_to_user_details_pronouns.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTextLimitToUserDetailsPronouns < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_text_limit :user_details, :pronouns, 50 + end + + def down + remove_text_limit :user_details, :pronouns + end +end diff --git a/db/migrate/20210607080044_remove_temporary_index_on_security_findings_scan_id.rb b/db/migrate/20210607080044_remove_temporary_index_on_security_findings_scan_id.rb new file mode 100644 index 00000000000..5357059f475 --- /dev/null +++ b/db/migrate/20210607080044_remove_temporary_index_on_security_findings_scan_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveTemporaryIndexOnSecurityFindingsScanId < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'tmp_index_on_security_findings_scan_id' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end + + def down + add_concurrent_index :security_findings, :scan_id, where: 'uuid is null', name: INDEX_NAME + end +end diff --git a/db/migrate/20210607154719_add_job_token_scope_enabled_to_ci_cd_settings.rb b/db/migrate/20210607154719_add_job_token_scope_enabled_to_ci_cd_settings.rb new file mode 100644 index 00000000000..20b9e8d95ee --- /dev/null +++ b/db/migrate/20210607154719_add_job_token_scope_enabled_to_ci_cd_settings.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddJobTokenScopeEnabledToCiCdSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :project_ci_cd_settings, :job_token_scope_enabled, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :project_ci_cd_settings, :job_token_scope_enabled + end + end +end diff --git a/db/migrate/20210608072312_initialize_conversion_of_ci_stages_to_bigint.rb b/db/migrate/20210608072312_initialize_conversion_of_ci_stages_to_bigint.rb new file mode 100644 index 00000000000..490a7f2e960 --- /dev/null +++ b/db/migrate/20210608072312_initialize_conversion_of_ci_stages_to_bigint.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class InitializeConversionOfCiStagesToBigint < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_stages + COLUMNS = %i(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/20210608072346_backfill_ci_stages_for_bigint_conversion.rb b/db/migrate/20210608072346_backfill_ci_stages_for_bigint_conversion.rb new file mode 100644 index 00000000000..6376305c784 --- /dev/null +++ b/db/migrate/20210608072346_backfill_ci_stages_for_bigint_conversion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class BackfillCiStagesForBigintConversion < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + TABLE = :ci_stages + COLUMNS = %i(id) + + def up + backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end + + def down + revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS) + end +end diff --git a/db/migrate/20210609013512_add_unique_index_for_batched_background_migrations.rb b/db/migrate/20210609013512_add_unique_index_for_batched_background_migrations.rb new file mode 100644 index 00000000000..28214aedce6 --- /dev/null +++ b/db/migrate/20210609013512_add_unique_index_for_batched_background_migrations.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddUniqueIndexForBatchedBackgroundMigrations < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + TABLE_NAME = :batched_background_migrations + INDEX_NAME = 'index_batched_background_migrations_on_unique_configuration' + REDUNDANT_INDEX_NAME = 'index_batched_migrations_on_job_table_and_column_name' + + def up + add_concurrent_index TABLE_NAME, + %i[job_class_name table_name column_name job_arguments], + unique: true, + name: INDEX_NAME + + remove_concurrent_index_by_name TABLE_NAME, REDUNDANT_INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, + %i[job_class_name table_name column_name], + name: REDUNDANT_INDEX_NAME + + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end +end diff --git a/db/migrate/20210609090856_add_expiry_id_ssh_key_notification_index.rb b/db/migrate/20210609090856_add_expiry_id_ssh_key_notification_index.rb new file mode 100644 index 00000000000..406bbe2095f --- /dev/null +++ b/db/migrate/20210609090856_add_expiry_id_ssh_key_notification_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddExpiryIdSshKeyNotificationIndex < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_keys_on_expires_at_and_id' + + def up + add_concurrent_index :keys, + "date(timezone('UTC', expires_at)), id", + where: 'expiry_notification_delivered_at IS NULL', + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :keys, INDEX_NAME + end +end diff --git a/db/migrate/20210609192728_add_status_check_foreign_key_to_external_status_check_id.rb b/db/migrate/20210609192728_add_status_check_foreign_key_to_external_status_check_id.rb new file mode 100644 index 00000000000..461d5838aed --- /dev/null +++ b/db/migrate/20210609192728_add_status_check_foreign_key_to_external_status_check_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddStatusCheckForeignKeyToExternalStatusCheckId < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :external_status_checks_protected_branches, :external_status_checks, column: :external_status_check_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :external_status_checks_protected_branches, column: :external_status_check_id + end + end +end diff --git a/db/migrate/20210609193101_add_status_check_foreign_key_to_protected_branch_id.rb b/db/migrate/20210609193101_add_status_check_foreign_key_to_protected_branch_id.rb new file mode 100644 index 00000000000..6eeee60ec3a --- /dev/null +++ b/db/migrate/20210609193101_add_status_check_foreign_key_to_protected_branch_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddStatusCheckForeignKeyToProtectedBranchId < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :external_status_checks_protected_branches, :protected_branches, column: :protected_branch_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :external_status_checks_protected_branches, column: :protected_branch_id + end + end +end diff --git a/db/migrate/20210610102410_add_protected_attribute_to_pending_builds.rb b/db/migrate/20210610102410_add_protected_attribute_to_pending_builds.rb new file mode 100644 index 00000000000..026fa0d7043 --- /dev/null +++ b/db/migrate/20210610102410_add_protected_attribute_to_pending_builds.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1] + def change + add_column :ci_pending_builds, :protected, :boolean, null: false, default: false + end +end diff --git a/db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb b/db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb new file mode 100644 index 00000000000..ecd8bac22be --- /dev/null +++ b/db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class RebuildIndexForCadenceIterationsAutomation < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INDEX_NAME = 'cadence_create_iterations_automation' + + disable_ddl_transaction! + + def up + return if index_exists_and_is_valid? + + remove_concurrent_index_by_name :iterations_cadences, INDEX_NAME + + disable_statement_timeout do + execute( + <<-SQL + CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON iterations_cadences + USING BTREE(automatic, duration_in_weeks, (DATE ((COALESCE("iterations_cadences"."last_run_date", DATE('01-01-1970')) + "iterations_cadences"."duration_in_weeks" * INTERVAL '1 week')))) + WHERE duration_in_weeks IS NOT NULL + SQL + ) + end + end + + def down + remove_concurrent_index_by_name :iterations_cadences, INDEX_NAME + end + + def index_exists_and_is_valid? + execute( + <<-SQL + SELECT identifier + FROM postgres_indexes + WHERE identifier LIKE '%#{INDEX_NAME}' AND valid_index=TRUE + SQL + ).any? + end +end diff --git a/db/migrate/20210614131002_add_detection_method_to_vulnerabilities_finding.rb b/db/migrate/20210614131002_add_detection_method_to_vulnerabilities_finding.rb new file mode 100644 index 00000000000..cc37c5f1020 --- /dev/null +++ b/db/migrate/20210614131002_add_detection_method_to_vulnerabilities_finding.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddDetectionMethodToVulnerabilitiesFinding < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + def up + with_lock_retries do + add_column :vulnerability_occurrences, :detection_method, :smallint, null: false, default: 0 + end + end + + def down + with_lock_retries do + remove_column :vulnerability_occurrences, :detection_method + end + end +end |