diff options
Diffstat (limited to 'db/migrate')
56 files changed, 921 insertions, 16 deletions
diff --git a/db/migrate/20190225152525_add_auto_dev_ops_enabled_to_namespaces.rb b/db/migrate/20190225152525_add_auto_dev_ops_enabled_to_namespaces.rb index 93e7a84fb02..e4757b6bada 100644 --- a/db/migrate/20190225152525_add_auto_dev_ops_enabled_to_namespaces.rb +++ b/db/migrate/20190225152525_add_auto_dev_ops_enabled_to_namespaces.rb @@ -4,6 +4,6 @@ class AddAutoDevOpsEnabledToNamespaces < ActiveRecord::Migration[5.0] DOWNTIME = false def change - add_column :namespaces, :auto_devops_enabled, :boolean + add_column :namespaces, :auto_devops_enabled, :boolean # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20190606014128_add_last_ci_minutes_notification_at_to_namespaces.rb b/db/migrate/20190606014128_add_last_ci_minutes_notification_at_to_namespaces.rb index c264a23cda0..53b2e9f01fe 100644 --- a/db/migrate/20190606014128_add_last_ci_minutes_notification_at_to_namespaces.rb +++ b/db/migrate/20190606014128_add_last_ci_minutes_notification_at_to_namespaces.rb @@ -7,6 +7,6 @@ class AddLastCiMinutesNotificationAtToNamespaces < ActiveRecord::Migration[5.1] DOWNTIME = false def change - add_column :namespaces, :last_ci_minutes_notification_at, :datetime_with_timezone + add_column :namespaces, :last_ci_minutes_notification_at, :datetime_with_timezone # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20190621022810_add_last_ci_minutes_usage_notification_level_to_namespaces.rb b/db/migrate/20190621022810_add_last_ci_minutes_usage_notification_level_to_namespaces.rb index 1611340284c..02e06703acc 100644 --- a/db/migrate/20190621022810_add_last_ci_minutes_usage_notification_level_to_namespaces.rb +++ b/db/migrate/20190621022810_add_last_ci_minutes_usage_notification_level_to_namespaces.rb @@ -4,6 +4,6 @@ class AddLastCiMinutesUsageNotificationLevelToNamespaces < ActiveRecord::Migrati DOWNTIME = false def change - add_column :namespaces, :last_ci_minutes_usage_notification_level, :integer + add_column :namespaces, :last_ci_minutes_usage_notification_level, :integer # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20190626175626_add_group_creation_level_to_namespaces.rb b/db/migrate/20190626175626_add_group_creation_level_to_namespaces.rb index 3b75c92e518..6fcadc0c82c 100644 --- a/db/migrate/20190626175626_add_group_creation_level_to_namespaces.rb +++ b/db/migrate/20190626175626_add_group_creation_level_to_namespaces.rb @@ -6,7 +6,7 @@ class AddGroupCreationLevelToNamespaces < ActiveRecord::Migration[5.1] DOWNTIME = false def up - add_column(:namespaces, :subgroup_creation_level, :integer) + add_column(:namespaces, :subgroup_creation_level, :integer) # rubocop:disable Migration/AddColumnsToWideTables change_column_default(:namespaces, :subgroup_creation_level, ::Gitlab::Access::MAINTAINER_SUBGROUP_ACCESS) diff --git a/db/migrate/20190715215549_add_group_emails_disabled.rb b/db/migrate/20190715215549_add_group_emails_disabled.rb index d3fd4d2d923..63a815cb880 100644 --- a/db/migrate/20190715215549_add_group_emails_disabled.rb +++ b/db/migrate/20190715215549_add_group_emails_disabled.rb @@ -4,6 +4,6 @@ class AddGroupEmailsDisabled < ActiveRecord::Migration[5.2] DOWNTIME = false def change - add_column :namespaces, :emails_disabled, :boolean + add_column :namespaces, :emails_disabled, :boolean # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20190911115109_add_namespaces_max_pages_size.rb b/db/migrate/20190911115109_add_namespaces_max_pages_size.rb index c14dfa74a5a..d3054714188 100644 --- a/db/migrate/20190911115109_add_namespaces_max_pages_size.rb +++ b/db/migrate/20190911115109_add_namespaces_max_pages_size.rb @@ -4,6 +4,6 @@ class AddNamespacesMaxPagesSize < ActiveRecord::Migration[5.2] DOWNTIME = false def change - add_column :namespaces, :max_pages_size, :integer + add_column :namespaces, :max_pages_size, :integer # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20190911115222_add_namespaces_max_artifacts_size.rb b/db/migrate/20190911115222_add_namespaces_max_artifacts_size.rb index 60c594c47a6..bec81d6c7e1 100644 --- a/db/migrate/20190911115222_add_namespaces_max_artifacts_size.rb +++ b/db/migrate/20190911115222_add_namespaces_max_artifacts_size.rb @@ -4,6 +4,6 @@ class AddNamespacesMaxArtifactsSize < ActiveRecord::Migration[5.2] DOWNTIME = false def change - add_column :namespaces, :max_artifacts_size, :integer + add_column :namespaces, :max_artifacts_size, :integer # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20191114132259_add_mentions_disabled_to_namespaces.rb b/db/migrate/20191114132259_add_mentions_disabled_to_namespaces.rb index dbd69568ef2..a67d032795d 100644 --- a/db/migrate/20191114132259_add_mentions_disabled_to_namespaces.rb +++ b/db/migrate/20191114132259_add_mentions_disabled_to_namespaces.rb @@ -4,6 +4,6 @@ class AddMentionsDisabledToNamespaces < ActiveRecord::Migration[5.2] DOWNTIME = false def change - add_column :namespaces, :mentions_disabled, :boolean + add_column :namespaces, :mentions_disabled, :boolean # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb b/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb index 6eb650e6b6a..56a30b02290 100644 --- a/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb +++ b/db/migrate/20200207062728_add_default_branch_protection_to_namespaces.rb @@ -7,7 +7,7 @@ class AddDefaultBranchProtectionToNamespaces < ActiveRecord::Migration[6.0] def up with_lock_retries do - add_column :namespaces, :default_branch_protection, :integer, limit: 2 + add_column :namespaces, :default_branch_protection, :integer, limit: 2 # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200304124406_add_unlock_membership_to_ldap_of_groups.rb b/db/migrate/20200304124406_add_unlock_membership_to_ldap_of_groups.rb index 2aa58c92c3e..19e6573af9b 100644 --- a/db/migrate/20200304124406_add_unlock_membership_to_ldap_of_groups.rb +++ b/db/migrate/20200304124406_add_unlock_membership_to_ldap_of_groups.rb @@ -7,7 +7,7 @@ class AddUnlockMembershipToLdapOfGroups < ActiveRecord::Migration[5.2] def up with_lock_retries do - add_column(:namespaces, :unlock_membership_to_ldap, :boolean) + add_column(:namespaces, :unlock_membership_to_ldap, :boolean) # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200323075043_add_max_personal_access_token_lifetime_to_namespaces.rb b/db/migrate/20200323075043_add_max_personal_access_token_lifetime_to_namespaces.rb index 907c832ce46..7388d6bbc13 100644 --- a/db/migrate/20200323075043_add_max_personal_access_token_lifetime_to_namespaces.rb +++ b/db/migrate/20200323075043_add_max_personal_access_token_lifetime_to_namespaces.rb @@ -7,7 +7,7 @@ class AddMaxPersonalAccessTokenLifetimeToNamespaces < ActiveRecord::Migration[6. def up with_lock_retries do - add_column :namespaces, :max_personal_access_token_lifetime, :integer + add_column :namespaces, :max_personal_access_token_lifetime, :integer # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200407120000_add_push_rule_id_to_groups.rb b/db/migrate/20200407120000_add_push_rule_id_to_groups.rb index 4b4e99052aa..738f0a4c605 100644 --- a/db/migrate/20200407120000_add_push_rule_id_to_groups.rb +++ b/db/migrate/20200407120000_add_push_rule_id_to_groups.rb @@ -7,7 +7,7 @@ class AddPushRuleIdToGroups < ActiveRecord::Migration[6.0] def up with_lock_retries do - add_column :namespaces, :push_rule_id, :bigint + add_column :namespaces, :push_rule_id, :bigint # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200424102023_add_shared_runners_enabled_and_override_to_namespaces.rb b/db/migrate/20200424102023_add_shared_runners_enabled_and_override_to_namespaces.rb index 2555a50be44..1adc421b9af 100644 --- a/db/migrate/20200424102023_add_shared_runners_enabled_and_override_to_namespaces.rb +++ b/db/migrate/20200424102023_add_shared_runners_enabled_and_override_to_namespaces.rb @@ -7,8 +7,8 @@ class AddSharedRunnersEnabledAndOverrideToNamespaces < ActiveRecord::Migration[6 def up with_lock_retries do - add_column :namespaces, :shared_runners_enabled, :boolean, default: true, null: false - add_column :namespaces, :allow_descendants_override_disabled_shared_runners, :boolean, default: false, null: false + add_column :namespaces, :shared_runners_enabled, :boolean, default: true, null: false # rubocop:disable Migration/AddColumnsToWideTables + add_column :namespaces, :allow_descendants_override_disabled_shared_runners, :boolean, default: false, null: false # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200609012539_add_traversal_ids_to_namespaces.rb b/db/migrate/20200609012539_add_traversal_ids_to_namespaces.rb index d7f282b69f8..3041d7a8e58 100644 --- a/db/migrate/20200609012539_add_traversal_ids_to_namespaces.rb +++ b/db/migrate/20200609012539_add_traversal_ids_to_namespaces.rb @@ -7,7 +7,7 @@ class AddTraversalIdsToNamespaces < ActiveRecord::Migration[6.0] def up with_lock_retries do - add_column :namespaces, :traversal_ids, :integer, array: true, default: [], null: false + add_column :namespaces, :traversal_ids, :integer, array: true, default: [], null: false # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20200701190523_add_delayed_project_removal_to_namespaces.rb b/db/migrate/20200701190523_add_delayed_project_removal_to_namespaces.rb index 2d5bbc1cba1..fcc08723520 100644 --- a/db/migrate/20200701190523_add_delayed_project_removal_to_namespaces.rb +++ b/db/migrate/20200701190523_add_delayed_project_removal_to_namespaces.rb @@ -7,7 +7,7 @@ class AddDelayedProjectRemovalToNamespaces < ActiveRecord::Migration[6.0] def up with_lock_retries do - add_column :namespaces, :delayed_project_removal, :boolean, default: false, null: false + add_column :namespaces, :delayed_project_removal, :boolean, default: false, null: false # rubocop:disable Migration/AddColumnsToWideTables end end diff --git a/db/migrate/20201120144823_create_tokens_with_iv.rb b/db/migrate/20201120144823_create_tokens_with_iv.rb new file mode 100644 index 00000000000..f8dc75513fb --- /dev/null +++ b/db/migrate/20201120144823_create_tokens_with_iv.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateTokensWithIv < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :token_with_ivs do |t| + t.binary :hashed_token, null: false + t.binary :hashed_plaintext_token, null: false + t.binary :iv, null: false + + t.index :hashed_token, name: 'index_token_with_ivs_on_hashed_token', unique: true, using: :btree + t.index :hashed_plaintext_token, name: 'index_token_with_ivs_on_hashed_plaintext_token', unique: true, using: :btree + end + end +end diff --git a/db/migrate/20201127104228_add_index_to_security_scans_on_created_at_and_id.rb b/db/migrate/20201127104228_add_index_to_security_scans_on_created_at_and_id.rb new file mode 100644 index 00000000000..c9bbe8ab77d --- /dev/null +++ b/db/migrate/20201127104228_add_index_to_security_scans_on_created_at_and_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexToSecurityScansOnCreatedAtAndId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_security_scans_on_date_created_at_and_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_scans, "date(timezone('UTC', created_at)), id", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name(:security_scans, INDEX_NAME) + end +end diff --git a/db/migrate/20201204111200_create_packages_debian_project_components.rb b/db/migrate/20201204111200_create_packages_debian_project_components.rb new file mode 100644 index 00000000000..76946967357 --- /dev/null +++ b/db/migrate/20201204111200_create_packages_debian_project_components.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class CreatePackagesDebianProjectComponents < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + UNIQUE_NAME = 'uniq_pkgs_deb_proj_components_on_distribution_id_and_name' + + disable_ddl_transaction! + + def up + unless table_exists?(:packages_debian_project_components) + create_table :packages_debian_project_components do |t| + t.timestamps_with_timezone + t.references :distribution, + foreign_key: { to_table: :packages_debian_project_distributions, on_delete: :cascade }, + null: false, + index: false + t.text :name, null: false + + t.index %w(distribution_id name), + name: UNIQUE_NAME, + unique: true, + using: :btree + end + end + + add_text_limit :packages_debian_project_components, :name, 255 + end + + def down + drop_table :packages_debian_project_components + end +end diff --git a/db/migrate/20201204111300_create_packages_debian_group_components.rb b/db/migrate/20201204111300_create_packages_debian_group_components.rb new file mode 100644 index 00000000000..c69f8d10c2b --- /dev/null +++ b/db/migrate/20201204111300_create_packages_debian_group_components.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class CreatePackagesDebianGroupComponents < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + UNIQUE_NAME = 'uniq_pkgs_deb_grp_components_on_distribution_id_and_name' + + disable_ddl_transaction! + + def up + unless table_exists?(:packages_debian_group_components) + create_table :packages_debian_group_components do |t| + t.timestamps_with_timezone + t.references :distribution, + foreign_key: { to_table: :packages_debian_group_distributions, on_delete: :cascade }, + null: false, + index: false + t.text :name, null: false + + t.index %w(distribution_id name), + name: UNIQUE_NAME, + unique: true, + using: :btree + end + end + + add_text_limit :packages_debian_group_components, :name, 255 + end + + def down + drop_table :packages_debian_group_components + end +end diff --git a/db/migrate/20210105052034_rename_asset_proxy_whitelist_on_application_settings.rb b/db/migrate/20210105052034_rename_asset_proxy_whitelist_on_application_settings.rb new file mode 100644 index 00000000000..cdfbd368070 --- /dev/null +++ b/db/migrate/20210105052034_rename_asset_proxy_whitelist_on_application_settings.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RenameAssetProxyWhitelistOnApplicationSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers::V2 + + DOWNTIME = false + + disable_ddl_transaction! + + def up + rename_column_concurrently :application_settings, + :asset_proxy_whitelist, + :asset_proxy_allowlist + end + + def down + undo_rename_column_concurrently :application_settings, + :asset_proxy_whitelist, + :asset_proxy_allowlist + end +end diff --git a/db/migrate/20210105153342_add_entity_columns_to_vulnerability_occurrences.rb b/db/migrate/20210105153342_add_entity_columns_to_vulnerability_occurrences.rb new file mode 100644 index 00000000000..3b5ffff7645 --- /dev/null +++ b/db/migrate/20210105153342_add_entity_columns_to_vulnerability_occurrences.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddEntityColumnsToVulnerabilityOccurrences < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20200501000002_add_text_limit_to_sprints_extended_title + def change + add_column :vulnerability_occurrences, :description, :text + add_column :vulnerability_occurrences, :message, :text + add_column :vulnerability_occurrences, :solution, :text + add_column :vulnerability_occurrences, :cve, :text + add_column :vulnerability_occurrences, :location, :jsonb + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210105154321_add_text_limit_to_vulnerability_occurrences_entity_columns.rb b/db/migrate/20210105154321_add_text_limit_to_vulnerability_occurrences_entity_columns.rb new file mode 100644 index 00000000000..c2e138303d8 --- /dev/null +++ b/db/migrate/20210105154321_add_text_limit_to_vulnerability_occurrences_entity_columns.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddTextLimitToVulnerabilityOccurrencesEntityColumns < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :vulnerability_occurrences, :description, 15000 + add_text_limit :vulnerability_occurrences, :message, 3000 + add_text_limit :vulnerability_occurrences, :solution, 7000 + add_text_limit :vulnerability_occurrences, :cve, 48400 + end + + def down + remove_text_limit :vulnerability_occurrences, :description + remove_text_limit :vulnerability_occurrences, :message + remove_text_limit :vulnerability_occurrences, :solution + remove_text_limit :vulnerability_occurrences, :cve + end +end diff --git a/db/migrate/20210106155209_add_merge_request_diff_commit_trailers.rb b/db/migrate/20210106155209_add_merge_request_diff_commit_trailers.rb new file mode 100644 index 00000000000..906efa58bcd --- /dev/null +++ b/db/migrate/20210106155209_add_merge_request_diff_commit_trailers.rb @@ -0,0 +1,22 @@ +# 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 AddMergeRequestDiffCommitTrailers < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :merge_request_diff_commits, :trailers, :jsonb, default: {}, null: false + end + end + + def down + with_lock_retries do + remove_column :merge_request_diff_commits, :trailers + end + end +end diff --git a/db/migrate/20210107105306_add_diff_type_to_merge_request_diffs.rb b/db/migrate/20210107105306_add_diff_type_to_merge_request_diffs.rb new file mode 100644 index 00000000000..0b9b5e93054 --- /dev/null +++ b/db/migrate/20210107105306_add_diff_type_to_merge_request_diffs.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class AddDiffTypeToMergeRequestDiffs < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + UNIQUE_INDEX_NAME = 'index_merge_request_diffs_on_unique_merge_request_id' + + def up + unless column_exists?(:merge_request_diffs, :diff_type) + with_lock_retries do + add_column :merge_request_diffs, :diff_type, :integer, null: false, limit: 2, default: 1 + end + end + + add_concurrent_index :merge_request_diffs, :merge_request_id, unique: true, where: 'diff_type = 2', name: UNIQUE_INDEX_NAME + end + + def down + remove_concurrent_index_by_name(:merge_request_diffs, UNIQUE_INDEX_NAME) + + if column_exists?(:merge_request_diffs, :diff_type) + with_lock_retries do + remove_column :merge_request_diffs, :diff_type + end + end + end +end diff --git a/db/migrate/20210107154615_add_merge_request_context_commit_trailers.rb b/db/migrate/20210107154615_add_merge_request_context_commit_trailers.rb new file mode 100644 index 00000000000..e7bd7c2ea56 --- /dev/null +++ b/db/migrate/20210107154615_add_merge_request_context_commit_trailers.rb @@ -0,0 +1,12 @@ +# 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 AddMergeRequestContextCommitTrailers < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :merge_request_context_commits, :trailers, :jsonb, default: {}, null: false + end +end diff --git a/db/migrate/20210111051045_create_dast_profiles.rb b/db/migrate/20210111051045_create_dast_profiles.rb new file mode 100644 index 00000000000..f2667e1222e --- /dev/null +++ b/db/migrate/20210111051045_create_dast_profiles.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class CreateDastProfiles < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + table_comment = { owner: 'group::dynamic analysis', description: 'Profile used to run a DAST on-demand scan' } + + create_table_with_constraints :dast_profiles, comment: table_comment.to_json do |t| # rubocop:disable Migration/AddLimitToTextColumns + t.references :project, null: false, foreign_key: false, index: false + t.references :dast_site_profile, null: false, foreign_key: { on_delete: :cascade } + t.references :dast_scanner_profile, null: false, foreign_key: { on_delete: :cascade } + + t.timestamps_with_timezone + + # rubocop:disable Migration/AddLimitToTextColumns + t.text :name, null: false + t.text :description, null: false + # rubocop:enable Migration/AddLimitToTextColumns + + t.index [:project_id, :name], unique: true + + t.text_limit :name, 255 + t.text_limit :description, 255 + end + end + + def down + with_lock_retries do + drop_table :dast_profiles + end + end +end diff --git a/db/migrate/20210111053308_add_project_fk_for_dast_profile.rb b/db/migrate/20210111053308_add_project_fk_for_dast_profile.rb new file mode 100644 index 00000000000..5dc057b5f70 --- /dev/null +++ b/db/migrate/20210111053308_add_project_fk_for_dast_profile.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddProjectFkForDastProfile < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :dast_profiles, :projects, column: :project_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :dast_profiles, column: :project_id + end + end +end diff --git a/db/migrate/20210111075104_add_temporary_index_on_security_findings_scan_id.rb b/db/migrate/20210111075104_add_temporary_index_on_security_findings_scan_id.rb new file mode 100644 index 00000000000..a8f4e130f07 --- /dev/null +++ b/db/migrate/20210111075104_add_temporary_index_on_security_findings_scan_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddTemporaryIndexOnSecurityFindingsScanId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'tmp_index_on_security_findings_scan_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_findings, :scan_id, where: 'uuid is null', name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end +end diff --git a/db/migrate/20210112202949_create_composer_cache_file.rb b/db/migrate/20210112202949_create_composer_cache_file.rb new file mode 100644 index 00000000000..b1c2a1608dd --- /dev/null +++ b/db/migrate/20210112202949_create_composer_cache_file.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class CreateComposerCacheFile < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + # rubocop:disable Migration/AddLimitToTextColumns + create_table_with_constraints :packages_composer_cache_files do |t| + t.timestamps_with_timezone + + # record can be deleted after `delete_at` + t.datetime_with_timezone :delete_at + + # which namespace it belongs to + t.integer :namespace_id, null: true + + # file storage related fields + t.integer :file_store, limit: 2, null: false, default: 1 + t.text :file, null: false + t.binary :file_sha256, null: false + + t.index [:namespace_id, :file_sha256], name: "index_packages_composer_cache_namespace_and_sha", using: :btree, unique: true + t.foreign_key :namespaces, column: :namespace_id, on_delete: :nullify + + t.text_limit :file, 255 + end + end + + def down + drop_table :packages_composer_cache_files + end +end diff --git a/db/migrate/20210113224909_add_pipeline_configuration_full_path_to_compliance_pipeline.rb b/db/migrate/20210113224909_add_pipeline_configuration_full_path_to_compliance_pipeline.rb new file mode 100644 index 00000000000..408d0579031 --- /dev/null +++ b/db/migrate/20210113224909_add_pipeline_configuration_full_path_to_compliance_pipeline.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddPipelineConfigurationFullPathToCompliancePipeline < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210119162812_add_text_limit_to_compliance_pipeline_configuration_full_path.rb + def up + add_column :compliance_management_frameworks, :pipeline_configuration_full_path, :text + end + # rubocop:enable Migration/AddLimitToTextColumns + + def down + remove_column :compliance_management_frameworks, :pipeline_configuration_full_path + end +end diff --git a/db/migrate/20210113231532_add_converted_at_to_experiment_subjects.rb b/db/migrate/20210113231532_add_converted_at_to_experiment_subjects.rb new file mode 100644 index 00000000000..25571b25af9 --- /dev/null +++ b/db/migrate/20210113231532_add_converted_at_to_experiment_subjects.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddConvertedAtToExperimentSubjects < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :experiment_subjects, :converted_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20210113231546_add_context_to_experiment_subjects.rb b/db/migrate/20210113231546_add_context_to_experiment_subjects.rb new file mode 100644 index 00000000000..7fac45e9952 --- /dev/null +++ b/db/migrate/20210113231546_add_context_to_experiment_subjects.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddContextToExperimentSubjects < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :experiment_subjects, :context, :jsonb, default: {}, null: false + end +end diff --git a/db/migrate/20210114142443_add_indexes_to_onboarding_progresses.rb b/db/migrate/20210114142443_add_indexes_to_onboarding_progresses.rb new file mode 100644 index 00000000000..39964047e7f --- /dev/null +++ b/db/migrate/20210114142443_add_indexes_to_onboarding_progresses.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class AddIndexesToOnboardingProgresses < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + CREATE_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_create_track' + VERIFY_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_verify_track' + TRIAL_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_trial_track' + TEAM_TRACK_INDEX_NAME = 'index_onboarding_progresses_for_team_track' + + disable_ddl_transaction! + + def up + add_concurrent_index :onboarding_progresses, :created_at, where: 'git_write_at IS NULL', name: CREATE_TRACK_INDEX_NAME + add_concurrent_index :onboarding_progresses, :git_write_at, where: 'git_write_at IS NOT NULL AND pipeline_created_at IS NULL', name: VERIFY_TRACK_INDEX_NAME + add_concurrent_index :onboarding_progresses, 'GREATEST(git_write_at, pipeline_created_at)', where: 'git_write_at IS NOT NULL AND pipeline_created_at IS NOT NULL AND trial_started_at IS NULL', name: TRIAL_TRACK_INDEX_NAME + add_concurrent_index :onboarding_progresses, 'GREATEST(git_write_at, pipeline_created_at, trial_started_at)', where: 'git_write_at IS NOT NULL AND pipeline_created_at IS NOT NULL AND trial_started_at IS NOT NULL AND user_added_at IS NULL', name: TEAM_TRACK_INDEX_NAME + end + + def down + remove_concurrent_index_by_name :onboarding_progresses, CREATE_TRACK_INDEX_NAME + remove_concurrent_index_by_name :onboarding_progresses, VERIFY_TRACK_INDEX_NAME + remove_concurrent_index_by_name :onboarding_progresses, TRIAL_TRACK_INDEX_NAME + remove_concurrent_index_by_name :onboarding_progresses, TEAM_TRACK_INDEX_NAME + end +end diff --git a/db/migrate/20210115090452_create_group_repository_storage_move.rb b/db/migrate/20210115090452_create_group_repository_storage_move.rb new file mode 100644 index 00000000000..bd168dce5ac --- /dev/null +++ b/db/migrate/20210115090452_create_group_repository_storage_move.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class CreateGroupRepositoryStorageMove < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless table_exists?(:group_repository_storage_moves) + with_lock_retries do + create_table :group_repository_storage_moves do |t| + t.timestamps_with_timezone + t.references :group, references: :namespace, column: :group_id, index: true, null: false + t.integer :state, limit: 2, default: 1, null: false + t.text :source_storage_name, null: false + t.text :destination_storage_name, null: false + + t.foreign_key :namespaces, column: :group_id, on_delete: :cascade + end + end + end + + add_text_limit(:group_repository_storage_moves, :source_storage_name, 255, constraint_name: 'group_repository_storage_moves_source_storage_name') + add_text_limit(:group_repository_storage_moves, :destination_storage_name, 255, constraint_name: 'group_repository_storage_moves_destination_storage_name') + end + + def down + with_lock_retries do + drop_table :group_repository_storage_moves + end + end +end diff --git a/db/migrate/20210117210226_add_has_external_issue_tracker_trigger.rb b/db/migrate/20210117210226_add_has_external_issue_tracker_trigger.rb new file mode 100644 index 00000000000..20fe0ee0fd1 --- /dev/null +++ b/db/migrate/20210117210226_add_has_external_issue_tracker_trigger.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +class AddHasExternalIssueTrackerTrigger < ActiveRecord::Migration[6.0] + include Gitlab::Database::SchemaHelpers + + DOWNTIME = false + FUNCTION_NAME = 'set_has_external_issue_tracker' + TRIGGER_ON_INSERT_NAME = 'trigger_has_external_issue_tracker_on_insert' + TRIGGER_ON_UPDATE_NAME = 'trigger_has_external_issue_tracker_on_update' + TRIGGER_ON_DELETE_NAME = 'trigger_has_external_issue_tracker_on_delete' + + def up + create_trigger_function(FUNCTION_NAME, replace: true) do + <<~SQL + UPDATE projects SET has_external_issue_tracker = ( + EXISTS + ( + SELECT 1 + FROM services + WHERE project_id = COALESCE(NEW.project_id, OLD.project_id) + AND active = TRUE + AND category = 'issue_tracker' + ) + ) + WHERE projects.id = COALESCE(NEW.project_id, OLD.project_id); + RETURN NULL; + SQL + end + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_ON_INSERT_NAME} + AFTER INSERT ON services + FOR EACH ROW + WHEN (NEW.category = 'issue_tracker' AND NEW.active = TRUE AND NEW.project_id IS NOT NULL) + EXECUTE FUNCTION #{FUNCTION_NAME}(); + SQL + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_ON_UPDATE_NAME} + AFTER UPDATE ON services + FOR EACH ROW + WHEN (NEW.category = 'issue_tracker' AND OLD.active != NEW.active AND NEW.project_id IS NOT NULL) + EXECUTE FUNCTION #{FUNCTION_NAME}(); + SQL + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_ON_DELETE_NAME} + AFTER DELETE ON services + FOR EACH ROW + WHEN (OLD.category = 'issue_tracker' AND OLD.active = TRUE AND OLD.project_id IS NOT NULL) + EXECUTE FUNCTION #{FUNCTION_NAME}(); + SQL + end + + def down + drop_trigger(:services, TRIGGER_ON_INSERT_NAME) + drop_trigger(:services, TRIGGER_ON_UPDATE_NAME) + drop_trigger(:services, TRIGGER_ON_DELETE_NAME) + drop_function(FUNCTION_NAME) + end +end diff --git a/db/migrate/20210118111307_add_enforce_ssh_key_expiration_to_application_settings.rb b/db/migrate/20210118111307_add_enforce_ssh_key_expiration_to_application_settings.rb new file mode 100644 index 00000000000..fd1ed4f207b --- /dev/null +++ b/db/migrate/20210118111307_add_enforce_ssh_key_expiration_to_application_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddEnforceSshKeyExpirationToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :enforce_ssh_key_expiration, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210119162812_add_text_limit_to_compliance_pipeline_configuration_full_path.rb b/db/migrate/20210119162812_add_text_limit_to_compliance_pipeline_configuration_full_path.rb new file mode 100644 index 00000000000..2958dc8d0ec --- /dev/null +++ b/db/migrate/20210119162812_add_text_limit_to_compliance_pipeline_configuration_full_path.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTextLimitToCompliancePipelineConfigurationFullPath < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :compliance_management_frameworks, :pipeline_configuration_full_path, 255 + end + + def down + remove_text_limit :compliance_management_frameworks, :pipeline_configuration_full_path + end +end diff --git a/db/migrate/20210120221743_delete_oauth_applications_tmp_index.rb b/db/migrate/20210120221743_delete_oauth_applications_tmp_index.rb new file mode 100644 index 00000000000..d29e63ba5da --- /dev/null +++ b/db/migrate/20210120221743_delete_oauth_applications_tmp_index.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DeleteOauthApplicationsTmpIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'tmp_index_oauth_applications_on_id_where_trusted' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :oauth_applications, INDEX_NAME + end + + def down + add_concurrent_index :oauth_applications, :id, where: 'trusted = true', name: INDEX_NAME + end +end diff --git a/db/migrate/20210121093618_remove_repository_read_only_to_groups.rb b/db/migrate/20210121093618_remove_repository_read_only_to_groups.rb new file mode 100644 index 00000000000..0b353ba5d88 --- /dev/null +++ b/db/migrate/20210121093618_remove_repository_read_only_to_groups.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class RemoveRepositoryReadOnlyToGroups < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + if column_exists?(:namespaces, :repository_read_only) + with_lock_retries do + remove_column :namespaces, :repository_read_only # rubocop:disable Migration/RemoveColumn + end + end + end + + def down + unless column_exists?(:namespaces, :repository_read_only) + with_lock_retries do + add_column :namespaces, :repository_read_only, :boolean, default: false, null: false # rubocop:disable Migration/AddColumnsToWideTables + end + end + end +end diff --git a/db/migrate/20210122073805_add_repository_read_only_to_namespace_settings.rb b/db/migrate/20210122073805_add_repository_read_only_to_namespace_settings.rb new file mode 100644 index 00000000000..f6479bdb3a4 --- /dev/null +++ b/db/migrate/20210122073805_add_repository_read_only_to_namespace_settings.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddRepositoryReadOnlyToNamespaceSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :namespace_settings, :repository_read_only, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :namespace_settings, :repository_read_only + end + end +end diff --git a/db/migrate/20210122153259_add_state_to_merge_request_reviewers.rb b/db/migrate/20210122153259_add_state_to_merge_request_reviewers.rb new file mode 100644 index 00000000000..dd0c98615f7 --- /dev/null +++ b/db/migrate/20210122153259_add_state_to_merge_request_reviewers.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddStateToMergeRequestReviewers < ActiveRecord::Migration[6.0] + DOWNTIME = false + + REVIEW_DEFAULT_STATE = 0 + + def change + add_column :merge_request_reviewers, :state, :smallint, default: REVIEW_DEFAULT_STATE, null: false + end +end diff --git a/db/migrate/20210122155158_add_pipeline_step_to_bulk_imports_failures.rb b/db/migrate/20210122155158_add_pipeline_step_to_bulk_imports_failures.rb new file mode 100644 index 00000000000..749e0b16eaf --- /dev/null +++ b/db/migrate/20210122155158_add_pipeline_step_to_bulk_imports_failures.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddPipelineStepToBulkImportsFailures < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless column_exists?(:bulk_import_failures, :pipeline_step, :text) + with_lock_retries do + add_column :bulk_import_failures, :pipeline_step, :text + end + end + + add_text_limit :bulk_import_failures, :pipeline_step, 255 + end + + def down + with_lock_retries do + remove_column :bulk_import_failures, :pipeline_step + end + end +end diff --git a/db/migrate/20210126030249_add_security_dashboard_access_level_into_project_features.rb b/db/migrate/20210126030249_add_security_dashboard_access_level_into_project_features.rb new file mode 100644 index 00000000000..cd325747282 --- /dev/null +++ b/db/migrate/20210126030249_add_security_dashboard_access_level_into_project_features.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddSecurityDashboardAccessLevelIntoProjectFeatures < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + PRIVATE_ACCESS_LEVEL = 10 + + def up + with_lock_retries do + add_column :project_features, :security_and_compliance_access_level, :integer, default: PRIVATE_ACCESS_LEVEL, null: false + end + end + + def down + with_lock_retries do + remove_column :project_features, :security_and_compliance_access_level + end + end +end diff --git a/db/migrate/20210126091713_add_unique_index_services_project_id_and_type.rb b/db/migrate/20210126091713_add_unique_index_services_project_id_and_type.rb new file mode 100644 index 00000000000..272dca70a8b --- /dev/null +++ b/db/migrate/20210126091713_add_unique_index_services_project_id_and_type.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddUniqueIndexServicesProjectIdAndType < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_services_on_project_id_and_type_unique' + + def up + add_concurrent_index :services, [:project_id, :type], name: INDEX_NAME, unique: true + end + + def down + remove_concurrent_index_by_name :services, name: INDEX_NAME + end +end diff --git a/db/migrate/20210126092102_remove_index_services_project_id_and_type.rb b/db/migrate/20210126092102_remove_index_services_project_id_and_type.rb new file mode 100644 index 00000000000..49780d03b7b --- /dev/null +++ b/db/migrate/20210126092102_remove_index_services_project_id_and_type.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveIndexServicesProjectIdAndType < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_services_on_project_id_and_type' + + # Replaced by the index added in 20210126091713_add_unique_index_services_project_id_and_type.rb + def up + remove_concurrent_index_by_name :services, name: INDEX_NAME + end + + def down + add_concurrent_index :services, [:project_id, :type], name: INDEX_NAME + end +end diff --git a/db/migrate/20210127052226_add_subgroup_events_to_web_hooks.rb b/db/migrate/20210127052226_add_subgroup_events_to_web_hooks.rb new file mode 100644 index 00000000000..fe2b2ef412d --- /dev/null +++ b/db/migrate/20210127052226_add_subgroup_events_to_web_hooks.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddSubgroupEventsToWebHooks < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :web_hooks, :subgroup_events, :boolean, null: false, default: false + end +end diff --git a/db/migrate/20210127143025_add_oldest_merge_requests_index.rb b/db/migrate/20210127143025_add_oldest_merge_requests_index.rb new file mode 100644 index 00000000000..c25e12d89af --- /dev/null +++ b/db/migrate/20210127143025_add_oldest_merge_requests_index.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddOldestMergeRequestsIndex < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + # replaced by db/migrate/20210201140434_add_oldest_merge_requests_index_again.rb + end + + def down + # replaced by db/migrate/20210201140434_add_oldest_merge_requests_index_again.rb + end +end diff --git a/db/migrate/20210128044930_add_git_two_factor_session_expiry_to_application_settings.rb b/db/migrate/20210128044930_add_git_two_factor_session_expiry_to_application_settings.rb new file mode 100644 index 00000000000..77a1dd2131b --- /dev/null +++ b/db/migrate/20210128044930_add_git_two_factor_session_expiry_to_application_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddGitTwoFactorSessionExpiryToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :git_two_factor_session_expiry, :integer, default: 15, null: false + end +end diff --git a/db/migrate/20210128114526_add_auto_delete_at_to_environments.rb b/db/migrate/20210128114526_add_auto_delete_at_to_environments.rb new file mode 100644 index 00000000000..8f89c2f2ad0 --- /dev/null +++ b/db/migrate/20210128114526_add_auto_delete_at_to_environments.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddAutoDeleteAtToEnvironments < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :environments, :auto_delete_at, :datetime_with_timezone + end + end + + def down + with_lock_retries do + remove_column :environments, :auto_delete_at + end + end +end diff --git a/db/migrate/20210128140157_add_content_type_to_dependency_proxy_manifests.rb b/db/migrate/20210128140157_add_content_type_to_dependency_proxy_manifests.rb new file mode 100644 index 00000000000..d016e3c20e2 --- /dev/null +++ b/db/migrate/20210128140157_add_content_type_to_dependency_proxy_manifests.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AddContentTypeToDependencyProxyManifests < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20210128140232_add_text_limit_to_dependency_proxy_manifests_content_type.rb + def change + add_column :dependency_proxy_manifests, :content_type, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210128140232_add_text_limit_to_dependency_proxy_manifests_content_type.rb b/db/migrate/20210128140232_add_text_limit_to_dependency_proxy_manifests_content_type.rb new file mode 100644 index 00000000000..035e4795ce0 --- /dev/null +++ b/db/migrate/20210128140232_add_text_limit_to_dependency_proxy_manifests_content_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddTextLimitToDependencyProxyManifestsContentType < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :dependency_proxy_manifests, :content_type, 255 + end + + def down + remove_text_limit :dependency_proxy_manifests, :content_type + end +end diff --git a/db/migrate/20210129225244_add_index_to_oncall_shfts_on_starts_at_and_ends_at.rb b/db/migrate/20210129225244_add_index_to_oncall_shfts_on_starts_at_and_ends_at.rb new file mode 100644 index 00000000000..8285aceb24a --- /dev/null +++ b/db/migrate/20210129225244_add_index_to_oncall_shfts_on_starts_at_and_ends_at.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddIndexToOncallShftsOnStartsAtAndEndsAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + NEW_NAME = 'index_oncall_shifts_on_rotation_id_and_starts_at_and_ends_at' + OLD_NAME = 'index_incident_management_oncall_shifts_on_rotation_id' + + def up + add_concurrent_index :incident_management_oncall_shifts, %i[rotation_id starts_at ends_at], name: NEW_NAME + + remove_concurrent_index_by_name :incident_management_oncall_shifts, OLD_NAME + end + + def down + add_concurrent_index :incident_management_oncall_shifts, :rotation_id, name: OLD_NAME + + remove_concurrent_index_by_name :incident_management_oncall_shifts, NEW_NAME + end +end diff --git a/db/migrate/20210201140434_add_oldest_merge_requests_index_again.rb b/db/migrate/20210201140434_add_oldest_merge_requests_index_again.rb new file mode 100644 index 00000000000..a3fed9e576a --- /dev/null +++ b/db/migrate/20210201140434_add_oldest_merge_requests_index_again.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +class AddOldestMergeRequestsIndexAgain < ActiveRecord::Migration[6.0] + include Gitlab::Database::SchemaHelpers + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + INDEX = 'index_on_merge_requests_for_latest_diffs' + + def up + execute "DROP INDEX CONCURRENTLY #{INDEX}" if invalid_index? + + return if index_exists_by_name?('merge_requests', INDEX) + + begin + disable_statement_timeout do + execute "CREATE INDEX CONCURRENTLY #{INDEX} ON merge_requests " \ + 'USING btree (target_project_id) INCLUDE (id, latest_merge_request_diff_id)' + end + rescue ActiveRecord::StatementInvalid => ex + # Due to https://github.com/lfittl/pg_query/issues/184, if the CREATE + # INDEX statement fails, we trigger a separate error due to the Gem not + # supporting the INCLUDE syntax. + # + # To work around this, we raise a custom error instead, as these won't + # have a query context injected. + raise "The index #{INDEX} couldn't be added: #{ex.message}" + end + + create_comment( + 'INDEX', + INDEX, + 'Index used to efficiently obtain the oldest merge request for a commit SHA' + ) + end + + def down + return unless index_exists_by_name?('merge_requests', INDEX) + + disable_statement_timeout do + execute "DROP INDEX CONCURRENTLY #{INDEX}" + end + end + + def invalid_index? + result = execute(<<~SQL) + SELECT pg_class.relname + FROM pg_class, pg_index + WHERE pg_index.indisvalid = false + AND pg_index.indexrelid = pg_class.oid + AND pg_class.relname = '#{INDEX}'; + SQL + + result.values.any? + end +end diff --git a/db/migrate/20210203002331_drop_backup_label_index.rb b/db/migrate/20210203002331_drop_backup_label_index.rb new file mode 100644 index 00000000000..430d2d0fb79 --- /dev/null +++ b/db/migrate/20210203002331_drop_backup_label_index.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class DropBackupLabelIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'backup_labels_project_id_title_idx' + + def up + remove_concurrent_index_by_name(:backup_labels, name: INDEX_NAME) + end + + def down + add_concurrent_index :backup_labels, [:project_id, :title], name: INDEX_NAME, unique: true, where: 'group_id = NULL::integer' + end +end diff --git a/db/migrate/20210203092540_remove_has_external_wiki_constraint.rb b/db/migrate/20210203092540_remove_has_external_wiki_constraint.rb new file mode 100644 index 00000000000..80b0cc11685 --- /dev/null +++ b/db/migrate/20210203092540_remove_has_external_wiki_constraint.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveHasExternalWikiConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + # This reverts the following migration: add_not_null_constraint :projects, :has_external_wiki, validate: false + if check_not_null_constraint_exists?(:projects, :has_external_wiki) + remove_not_null_constraint :projects, :has_external_wiki + end + end + + def down + # no-op + end +end diff --git a/db/migrate/20210203092549_restore_has_external_wiki_default_value.rb b/db/migrate/20210203092549_restore_has_external_wiki_default_value.rb new file mode 100644 index 00000000000..37111b370a5 --- /dev/null +++ b/db/migrate/20210203092549_restore_has_external_wiki_default_value.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class RestoreHasExternalWikiDefaultValue < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class TmpProject < ActiveRecord::Base + self.table_name = 'projects' + end + + # This reverts the following migration: change_column_default(:projects, :has_external_wiki, from: nil, to: false) + # We only change the column when the current default value is false + def up + # Find out the current default value + column = TmpProject.columns.find { |c| c.name == 'has_external_wiki' } + return unless column + + if column.default == 'false' + with_lock_retries do + change_column_default(:projects, :has_external_wiki, from: false, to: nil) + end + end + end + + def down + # no-op + end +end |