diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /db/migrate | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'db/migrate')
99 files changed, 1684 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/20190325080727_truncate_user_fullname.rb b/db/migrate/20190325080727_truncate_user_fullname.rb index e5f88671eef..29255d173d8 100644 --- a/db/migrate/20190325080727_truncate_user_fullname.rb +++ b/db/migrate/20190325080727_truncate_user_fullname.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable Migration/UpdateLargeTable class TruncateUserFullname < ActiveRecord::Migration[5.0] include Gitlab::Database::MigrationHelpers 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/20190828110802_add_not_null_constraints_to_prometheus_metrics_y_label_and_unit.rb b/db/migrate/20190828110802_add_not_null_constraints_to_prometheus_metrics_y_label_and_unit.rb index 6f3650ca966..1b238907af6 100644 --- a/db/migrate/20190828110802_add_not_null_constraints_to_prometheus_metrics_y_label_and_unit.rb +++ b/db/migrate/20190828110802_add_not_null_constraints_to_prometheus_metrics_y_label_and_unit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddNotNullConstraintsToPrometheusMetricsYLabelAndUnit < ActiveRecord::Migration[5.2] DOWNTIME = false diff --git a/db/migrate/20190828172831_create_package_tag.rb b/db/migrate/20190828172831_create_package_tag.rb index 3d26b7ce602..a70b71db51d 100644 --- a/db/migrate/20190828172831_create_package_tag.rb +++ b/db/migrate/20190828172831_create_package_tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # frozen_string_literal: true . class CreatePackageTag < ActiveRecord::Migration[5.2] 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/20191003195218_add_pendo_enabled_to_application_settings.rb b/db/migrate/20191003195218_add_pendo_enabled_to_application_settings.rb index 29ae831d4f4..2d937327ca1 100644 --- a/db/migrate/20191003195218_add_pendo_enabled_to_application_settings.rb +++ b/db/migrate/20191003195218_add_pendo_enabled_to_application_settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPendoEnabledToApplicationSettings < ActiveRecord::Migration[5.2] include Gitlab::Database::MigrationHelpers diff --git a/db/migrate/20191003195620_add_pendo_url_to_application_settings.rb b/db/migrate/20191003195620_add_pendo_url_to_application_settings.rb index 6763cb5544c..cbeb1ef5186 100644 --- a/db/migrate/20191003195620_add_pendo_url_to_application_settings.rb +++ b/db/migrate/20191003195620_add_pendo_url_to_application_settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPendoUrlToApplicationSettings < ActiveRecord::Migration[5.2] include Gitlab::Database::MigrationHelpers 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/20191120200015_add_index_to_grafana_integrations.rb b/db/migrate/20191120200015_add_index_to_grafana_integrations.rb index 87292c86e97..c67f6850baf 100644 --- a/db/migrate/20191120200015_add_index_to_grafana_integrations.rb +++ b/db/migrate/20191120200015_add_index_to_grafana_integrations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddIndexToGrafanaIntegrations < ActiveRecord::Migration[5.2] include Gitlab::Database::MigrationHelpers 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/20200229171700_create_custom_emojis.rb b/db/migrate/20200229171700_create_custom_emojis.rb index 1a60d7c8a63..f0574831f33 100644 --- a/db/migrate/20200229171700_create_custom_emojis.rb +++ b/db/migrate/20200229171700_create_custom_emojis.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateCustomEmojis < ActiveRecord::Migration[5.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false 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/20201004163918_remove_project_id_and_id_index_from_vulnerabilities_table.rb b/db/migrate/20201004163918_remove_project_id_and_id_index_from_vulnerabilities_table.rb index 7a59e706bf3..73028b6b795 100644 --- a/db/migrate/20201004163918_remove_project_id_and_id_index_from_vulnerabilities_table.rb +++ b/db/migrate/20201004163918_remove_project_id_and_id_index_from_vulnerabilities_table.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveProjectIdAndIdIndexFromVulnerabilitiesTable < ActiveRecord::Migration[6.0] include Gitlab::Database::MigrationHelpers diff --git a/db/migrate/20201027101010_create_user_follow_users.rb b/db/migrate/20201027101010_create_user_follow_users.rb new file mode 100644 index 00000000000..7c1f831f3b2 --- /dev/null +++ b/db/migrate/20201027101010_create_user_follow_users.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CreateUserFollowUsers < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + execute <<~SQL + CREATE TABLE user_follow_users ( + follower_id integer not null references users (id) on delete cascade, + followee_id integer not null references users (id) on delete cascade, + PRIMARY KEY (follower_id, followee_id) + ); + CREATE INDEX ON user_follow_users (followee_id); + SQL + end + end + + def down + drop_table :user_follow_users + end +end diff --git a/db/migrate/20201108134919_add_finding_fingerprint_table.rb b/db/migrate/20201108134919_add_finding_fingerprint_table.rb new file mode 100644 index 00000000000..dd8ffe8e8aa --- /dev/null +++ b/db/migrate/20201108134919_add_finding_fingerprint_table.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class AddFindingFingerprintTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + FINGERPRINT_IDX = :idx_vuln_fingerprints_on_occurrences_id_and_fingerprint + UNIQ_IDX = :idx_vuln_fingerprints_uniqueness + + def up + with_lock_retries do + create_table :vulnerability_finding_fingerprints do |t| + t.references :finding, + index: true, + null: false, + foreign_key: { to_table: :vulnerability_occurrences, column: :finding_id, on_delete: :cascade } + + t.timestamps_with_timezone null: false + + t.integer :algorithm_type, null: false + t.binary :fingerprint_sha256, null: false + + t.index %i[finding_id fingerprint_sha256], + name: FINGERPRINT_IDX, + unique: true # only one link should exist between occurrence and the fingerprint + + t.index %i[finding_id algorithm_type fingerprint_sha256], + name: UNIQ_IDX, + unique: true # these should be unique + end + end + end + + def down + with_lock_retries do + drop_table :vulnerability_finding_fingerprints + end + end +end diff --git a/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb b/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb index 157f0de0821..e944cee24e4 100644 --- a/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb +++ b/db/migrate/20201109080646_create_vulnerability_findings_remediations_join_table.rb @@ -3,6 +3,7 @@ class CreateVulnerabilityFindingsRemediationsJoinTable < ActiveRecord::Migration[6.0] DOWNTIME = false + # rubocop:disable Migration/CreateTableWithForeignKeys def change create_table :vulnerability_findings_remediations do |t| t.references :vulnerability_occurrence, index: false, foreign_key: { on_delete: :cascade } @@ -13,4 +14,5 @@ class CreateVulnerabilityFindingsRemediationsJoinTable < ActiveRecord::Migration t.index [:vulnerability_occurrence_id, :vulnerability_remediation_id], unique: true, name: 'index_vulnerability_findings_remediations_on_unique_keys' end end + # rubocop:enable Migration/CreateTableWithForeignKeys end diff --git a/db/migrate/20201120092000_add_kroki_formats_to_application_settings_table.rb b/db/migrate/20201120092000_add_kroki_formats_to_application_settings_table.rb new file mode 100644 index 00000000000..a059099dbc4 --- /dev/null +++ b/db/migrate/20201120092000_add_kroki_formats_to_application_settings_table.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddKrokiFormatsToApplicationSettingsTable < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + change_table :application_settings do |t| + t.jsonb :kroki_formats, null: false, default: {} + end + 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/20201204111400_create_packages_debian_project_component_files.rb b/db/migrate/20201204111400_create_packages_debian_project_component_files.rb new file mode 100644 index 00000000000..74ee1e9c4cf --- /dev/null +++ b/db/migrate/20201204111400_create_packages_debian_project_component_files.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class CreatePackagesDebianProjectComponentFiles < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_ARCHITECTURE = 'idx_packages_debian_project_component_files_on_architecture_id' + + disable_ddl_transaction! + + def up + with_lock_retries do + unless table_exists?(:packages_debian_project_component_files) + create_table :packages_debian_project_component_files do |t| + t.timestamps_with_timezone + t.references :component, + foreign_key: { to_table: :packages_debian_project_components, on_delete: :restrict }, + null: false, + index: true + t.references :architecture, + foreign_key: { to_table: :packages_debian_project_architectures, on_delete: :restrict }, + index: { name: INDEX_ARCHITECTURE } + t.integer :size, null: false + t.integer :file_type, limit: 2, null: false + t.integer :compression_type, limit: 2 + t.integer :file_store, limit: 2, default: 1, null: false + t.text :file, null: false + t.binary :file_md5, null: false + t.binary :file_sha256, null: false + end + end + end + + add_text_limit :packages_debian_project_component_files, :file, 255 + end + + def down + drop_table :packages_debian_project_component_files + end +end diff --git a/db/migrate/20201204111500_create_packages_debian_group_component_files.rb b/db/migrate/20201204111500_create_packages_debian_group_component_files.rb new file mode 100644 index 00000000000..2592d5b108a --- /dev/null +++ b/db/migrate/20201204111500_create_packages_debian_group_component_files.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class CreatePackagesDebianGroupComponentFiles < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_ARCHITECTURE = 'idx_packages_debian_group_component_files_on_architecture_id' + + disable_ddl_transaction! + + def up + with_lock_retries do + unless table_exists?(:packages_debian_group_component_files) + create_table :packages_debian_group_component_files do |t| + t.timestamps_with_timezone + t.references :component, + foreign_key: { to_table: :packages_debian_group_components, on_delete: :restrict }, + null: false, + index: true + t.references :architecture, + foreign_key: { to_table: :packages_debian_group_architectures, on_delete: :restrict }, + index: { name: INDEX_ARCHITECTURE } + t.integer :size, null: false + t.integer :file_type, limit: 2, null: false + t.integer :compression_type, limit: 2 + t.integer :file_store, limit: 2, default: 1, null: false + t.text :file, null: false + t.binary :file_md5, null: false + t.binary :file_sha256, null: false + end + end + end + + add_text_limit :packages_debian_group_component_files, :file, 255 + end + + def down + drop_table :packages_debian_group_component_files + end +end diff --git a/db/migrate/20201204111600_create_packages_debian_publications.rb b/db/migrate/20201204111600_create_packages_debian_publications.rb new file mode 100644 index 00000000000..2fd26c2c367 --- /dev/null +++ b/db/migrate/20201204111600_create_packages_debian_publications.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class CreatePackagesDebianPublications < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :packages_debian_publications do |t| + t.references :package, + index: { unique: true }, + null: false, + foreign_key: { to_table: :packages_packages, on_delete: :cascade } + t.references :distribution, + null: false, + foreign_key: { to_table: :packages_debian_project_distributions, on_delete: :cascade } + end + end +end diff --git a/db/migrate/20201214000000_change_mr_allow_maintainer_to_push_default.rb b/db/migrate/20201214000000_change_mr_allow_maintainer_to_push_default.rb index 0d97d54f3e4..47eec16807b 100644 --- a/db/migrate/20201214000000_change_mr_allow_maintainer_to_push_default.rb +++ b/db/migrate/20201214000000_change_mr_allow_maintainer_to_push_default.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ChangeMrAllowMaintainerToPushDefault < ActiveRecord::Migration[6.0] include Gitlab::Database::MigrationHelpers diff --git a/db/migrate/20201221225303_add_service_desk_reply_to_is_not_null_index_on_issues.rb b/db/migrate/20201221225303_add_service_desk_reply_to_is_not_null_index_on_issues.rb new file mode 100644 index 00000000000..fb5429af458 --- /dev/null +++ b/db/migrate/20201221225303_add_service_desk_reply_to_is_not_null_index_on_issues.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddServiceDeskReplyToIsNotNullIndexOnIssues < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'idx_on_issues_where_service_desk_reply_to_is_not_null' + + disable_ddl_transaction! + + def up + add_concurrent_index(:issues, [:id], name: INDEX_NAME, where: 'service_desk_reply_to IS NOT NULL') + end + + def down + remove_concurrent_index_by_name(:issues, INDEX_NAME) + 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/20210106225424_add_keep_latest_artifacts_to_application_settings.rb b/db/migrate/20210106225424_add_keep_latest_artifacts_to_application_settings.rb new file mode 100644 index 00000000000..884159ddedb --- /dev/null +++ b/db/migrate/20210106225424_add_keep_latest_artifacts_to_application_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddKeepLatestArtifactsToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + # This is named keep_latest_artifact for consistency with the project level setting but + # turning it on keeps all (multiple) artifacts on the latest pipeline per ref + add_column :application_settings, :keep_latest_artifact, :boolean, default: true, null: false + 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/20210119153801_add_proxy_settings_to_jira_tracker_data.rb b/db/migrate/20210119153801_add_proxy_settings_to_jira_tracker_data.rb new file mode 100644 index 00000000000..237ea25554d --- /dev/null +++ b/db/migrate/20210119153801_add_proxy_settings_to_jira_tracker_data.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddProxySettingsToJiraTrackerData < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :jira_tracker_data, :encrypted_proxy_address, :text + add_column :jira_tracker_data, :encrypted_proxy_address_iv, :text + add_column :jira_tracker_data, :encrypted_proxy_port, :text + add_column :jira_tracker_data, :encrypted_proxy_port_iv, :text + add_column :jira_tracker_data, :encrypted_proxy_username, :text + add_column :jira_tracker_data, :encrypted_proxy_username_iv, :text + add_column :jira_tracker_data, :encrypted_proxy_password, :text + add_column :jira_tracker_data, :encrypted_proxy_password_iv, :text + 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/20210120180956_extend_index_on_ci_builds_metadata.rb b/db/migrate/20210120180956_extend_index_on_ci_builds_metadata.rb new file mode 100644 index 00000000000..421a2fac1ae --- /dev/null +++ b/db/migrate/20210120180956_extend_index_on_ci_builds_metadata.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class ExtendIndexOnCiBuildsMetadata < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + OLD_INDEX = :index_ci_builds_metadata_on_build_id_and_interruptible + NEW_INDEX = :index_ci_builds_metadata_on_build_id_and_id_and_interruptible + + TABLE = :ci_builds_metadata + + def up + create_covering_index(TABLE, NEW_INDEX) + + remove_concurrent_index_by_name TABLE, OLD_INDEX + end + + def down + add_concurrent_index TABLE, :build_id, where: 'interruptible = true', name: OLD_INDEX + + remove_concurrent_index_by_name TABLE, NEW_INDEX + end + + private + + def create_covering_index(table, name) + return if index_exists_by_name?(table, name) + + disable_statement_timeout do + execute <<~SQL + CREATE INDEX CONCURRENTLY #{name} + ON #{table} (build_id) INCLUDE (id) + WHERE interruptible = true + SQL + end + 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/20210121100038_add_devops_adoption_group_segment.rb b/db/migrate/20210121100038_add_devops_adoption_group_segment.rb new file mode 100644 index 00000000000..619657e7f56 --- /dev/null +++ b/db/migrate/20210121100038_add_devops_adoption_group_segment.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionGroupSegment < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_column :analytics_devops_adoption_segments, :namespace_id, :integer, if_not_exists: true + add_concurrent_index :analytics_devops_adoption_segments, :namespace_id, unique: true + end + + def down + remove_column :analytics_devops_adoption_segments, :namespace_id + end +end diff --git a/db/migrate/20210121121102_optional_devops_adoption_segment_name.rb b/db/migrate/20210121121102_optional_devops_adoption_segment_name.rb new file mode 100644 index 00000000000..d7fda093cfc --- /dev/null +++ b/db/migrate/20210121121102_optional_devops_adoption_segment_name.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class OptionalDevopsAdoptionSegmentName < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_analytics_devops_adoption_segments_on_name' + + def up + change_column_null :analytics_devops_adoption_segments, :name, true + remove_concurrent_index_by_name :analytics_devops_adoption_segments, INDEX_NAME + end + + def down + transaction do + execute "DELETE FROM analytics_devops_adoption_segments WHERE name IS NULL" + change_column_null :analytics_devops_adoption_segments, :name, false + end + add_concurrent_index :analytics_devops_adoption_segments, :name, unique: true, name: INDEX_NAME + 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/20210125105410_add_devops_adoption_segment_namespace_fk.rb b/db/migrate/20210125105410_add_devops_adoption_segment_namespace_fk.rb new file mode 100644 index 00000000000..c7c18ae69d0 --- /dev/null +++ b/db/migrate/20210125105410_add_devops_adoption_segment_namespace_fk.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddDevopsAdoptionSegmentNamespaceFk < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :analytics_devops_adoption_segments, :namespaces, column: :namespace_id + end + + def down + remove_foreign_key_if_exists :analytics_devops_adoption_segments, :namespaces, column: :namespace_id + 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/20210126233608_add_rubygems_max_file_size_to_plan_limits.rb b/db/migrate/20210126233608_add_rubygems_max_file_size_to_plan_limits.rb new file mode 100644 index 00000000000..e0e7e773d17 --- /dev/null +++ b/db/migrate/20210126233608_add_rubygems_max_file_size_to_plan_limits.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddRubygemsMaxFileSizeToPlanLimits < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :plan_limits, :rubygems_max_file_size, :bigint, default: 3.gigabytes, null: false + 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/20210128101707_add_prevent_merge_without_jira_issue_to_project_settings.rb b/db/migrate/20210128101707_add_prevent_merge_without_jira_issue_to_project_settings.rb new file mode 100644 index 00000000000..18f186294f1 --- /dev/null +++ b/db/migrate/20210128101707_add_prevent_merge_without_jira_issue_to_project_settings.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddPreventMergeWithoutJiraIssueToProjectSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + def up + with_lock_retries do + add_column :project_settings, :prevent_merge_without_jira_issue, :boolean, null: false, default: false + end + end + + def down + with_lock_retries do + remove_column :project_settings, :prevent_merge_without_jira_issue + end + 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/20210128152830_create_ci_namespace_monthly_usage.rb b/db/migrate/20210128152830_create_ci_namespace_monthly_usage.rb new file mode 100644 index 00000000000..d6ee057a56b --- /dev/null +++ b/db/migrate/20210128152830_create_ci_namespace_monthly_usage.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class CreateCiNamespaceMonthlyUsage < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + create_table :ci_namespace_monthly_usages, if_not_exists: true do |t| + t.references :namespace, index: false, null: false + t.date :date, null: false + t.integer :additional_amount_available, null: false, default: 0 + t.decimal :amount_used, null: false, default: 0.0, precision: 18, scale: 2 + + t.index [:namespace_id, :date], unique: true + end + end + + add_check_constraint :ci_namespace_monthly_usages, "(date = date_trunc('month', date))", 'ci_namespace_monthly_usages_year_month_constraint' + end + + def down + with_lock_retries do + drop_table :ci_namespace_monthly_usages + end + 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 diff --git a/db/migrate/20210203221631_create_packages_rubygems_metadata.rb b/db/migrate/20210203221631_create_packages_rubygems_metadata.rb new file mode 100644 index 00000000000..f4ad5abf7e5 --- /dev/null +++ b/db/migrate/20210203221631_create_packages_rubygems_metadata.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +class CreatePackagesRubygemsMetadata < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + create_table_with_constraints :packages_rubygems_metadata, id: false do |t| + t.timestamps_with_timezone + t.references :package, primary_key: true, index: false, default: nil, null: false, foreign_key: { to_table: :packages_packages, on_delete: :cascade }, type: :bigint + t.text :authors + t.text :files + t.text :summary + + t.text :description + t.text :email + t.text :homepage + t.text :licenses + t.text :metadata + + t.text :author + t.text :bindir + t.text :cert_chain + t.text :executables + t.text :extensions + t.text :extra_rdoc_files + t.text :platform + t.text :post_install_message + t.text :rdoc_options + t.text :require_paths + t.text :required_ruby_version + t.text :required_rubygems_version + t.text :requirements + t.text :rubygems_version + t.text :signing_key + + t.text_limit :authors, 255 + t.text_limit :files, 255 + t.text_limit :summary, 1024 + + t.text_limit :description, 1024 + t.text_limit :email, 255 + t.text_limit :homepage, 255 + t.text_limit :licenses, 255 + t.text_limit :metadata, 255 + + t.text_limit :author, 255 + t.text_limit :bindir, 255 + t.text_limit :cert_chain, 255 + t.text_limit :executables, 255 + t.text_limit :extensions, 255 + t.text_limit :extra_rdoc_files, 255 + t.text_limit :platform, 255 + t.text_limit :post_install_message, 255 + t.text_limit :rdoc_options, 255 + t.text_limit :require_paths, 255 + t.text_limit :required_ruby_version, 255 + t.text_limit :required_rubygems_version, 255 + t.text_limit :requirements, 255 + t.text_limit :rubygems_version, 255 + t.text_limit :signing_key, 255 + end + end + + def down + drop_table :packages_rubygems_metadata + end +end diff --git a/db/migrate/20210203222620_add_expired_index_to_composer_cache_files.rb b/db/migrate/20210203222620_add_expired_index_to_composer_cache_files.rb new file mode 100644 index 00000000000..9c6a27812a5 --- /dev/null +++ b/db/migrate/20210203222620_add_expired_index_to_composer_cache_files.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddExpiredIndexToComposerCacheFiles < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'composer_cache_files_index_on_deleted_at' + + def up + add_concurrent_index :packages_composer_cache_files, [:delete_at, :id], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :packages_composer_cache_files, INDEX_NAME + end +end diff --git a/db/migrate/20210203223551_add_orphan_index_to_composer_cache_files.rb b/db/migrate/20210203223551_add_orphan_index_to_composer_cache_files.rb new file mode 100644 index 00000000000..e2853977e5f --- /dev/null +++ b/db/migrate/20210203223551_add_orphan_index_to_composer_cache_files.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddOrphanIndexToComposerCacheFiles < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_composer_cache_files_where_namespace_id_is_null' + + def up + add_concurrent_index :packages_composer_cache_files, :id, name: INDEX_NAME, where: 'namespace_id IS NULL' + end + + def down + remove_concurrent_index_by_name :packages_composer_cache_files, INDEX_NAME + end +end diff --git a/db/migrate/20210204152257_add_status_to_packages_packages.rb b/db/migrate/20210204152257_add_status_to_packages_packages.rb new file mode 100644 index 00000000000..4fd441048c6 --- /dev/null +++ b/db/migrate/20210204152257_add_status_to_packages_packages.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddStatusToPackagesPackages < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :packages_packages, :status, :smallint, default: 0, null: false + end +end diff --git a/db/migrate/20210204212850_add_group_id_to_ci_daily_build_group_report_results.rb b/db/migrate/20210204212850_add_group_id_to_ci_daily_build_group_report_results.rb new file mode 100644 index 00000000000..ba0464f5ad6 --- /dev/null +++ b/db/migrate/20210204212850_add_group_id_to_ci_daily_build_group_report_results.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddGroupIdToCiDailyBuildGroupReportResults < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column(:ci_daily_build_group_report_results, :group_id, :bigint) + end +end diff --git a/db/migrate/20210205084357_create_ci_project_monthly_usage.rb b/db/migrate/20210205084357_create_ci_project_monthly_usage.rb new file mode 100644 index 00000000000..c91bfa5ee1c --- /dev/null +++ b/db/migrate/20210205084357_create_ci_project_monthly_usage.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CreateCiProjectMonthlyUsage < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + create_table :ci_project_monthly_usages, if_not_exists: true do |t| + t.references :project, foreign_key: { on_delete: :cascade }, index: false, null: false + t.date :date, null: false + t.decimal :amount_used, null: false, default: 0.0, precision: 18, scale: 2 + + t.index [:project_id, :date], unique: true + end + end + + add_check_constraint :ci_project_monthly_usages, "(date = date_trunc('month', date))", 'ci_project_monthly_usages_year_month_constraint' + end + + def down + with_lock_retries do + drop_table :ci_project_monthly_usages + end + end +end diff --git a/db/migrate/20210205143926_remove_namespace_id_foreign_key_on_namespace_onboarding_actions.rb b/db/migrate/20210205143926_remove_namespace_id_foreign_key_on_namespace_onboarding_actions.rb new file mode 100644 index 00000000000..6fe66430dd0 --- /dev/null +++ b/db/migrate/20210205143926_remove_namespace_id_foreign_key_on_namespace_onboarding_actions.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveNamespaceIdForeignKeyOnNamespaceOnboardingActions < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + remove_foreign_key :namespace_onboarding_actions, :namespaces + end + end + + def down + with_lock_retries do + add_foreign_key :namespace_onboarding_actions, :namespaces, on_delete: :cascade + end + end +end diff --git a/db/migrate/20210205213915_remove_foreign_keys_from_alerts_service_data.rb b/db/migrate/20210205213915_remove_foreign_keys_from_alerts_service_data.rb new file mode 100644 index 00000000000..1d539f783b4 --- /dev/null +++ b/db/migrate/20210205213915_remove_foreign_keys_from_alerts_service_data.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RemoveForeignKeysFromAlertsServiceData < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + remove_foreign_key_if_exists :alerts_service_data, column: :service_id + end + end + + def down + with_lock_retries do + add_foreign_key :alerts_service_data, :services, column: :service_id, on_delete: :cascade + end + end +end diff --git a/db/migrate/20210208125050_add_status_expires_at_to_user_statuses.rb b/db/migrate/20210208125050_add_status_expires_at_to_user_statuses.rb new file mode 100644 index 00000000000..3ec1f6014a8 --- /dev/null +++ b/db/migrate/20210208125050_add_status_expires_at_to_user_statuses.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddStatusExpiresAtToUserStatuses < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column(:user_statuses, :clear_status_at, :datetime_with_timezone, null: true) + end + end + + def down + with_lock_retries do + remove_column(:user_statuses, :clear_status_at) + end + end +end diff --git a/db/migrate/20210208125248_add_index_on_user_statuses_status_expires_at.rb b/db/migrate/20210208125248_add_index_on_user_statuses_status_expires_at.rb new file mode 100644 index 00000000000..98f3449c2e8 --- /dev/null +++ b/db/migrate/20210208125248_add_index_on_user_statuses_status_expires_at.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexOnUserStatusesStatusExpiresAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_user_statuses_on_clear_status_at_not_null' + + disable_ddl_transaction! + + def up + add_concurrent_index(:user_statuses, :clear_status_at, name: INDEX_NAME, where: 'clear_status_at IS NOT NULL') + end + + def down + remove_concurrent_index_by_name(:user_statuses, INDEX_NAME) + end +end diff --git a/db/migrate/20210208144134_add_index_group_id_to_ci_daily_build_group_report_results.rb b/db/migrate/20210208144134_add_index_group_id_to_ci_daily_build_group_report_results.rb new file mode 100644 index 00000000000..422d8174043 --- /dev/null +++ b/db/migrate/20210208144134_add_index_group_id_to_ci_daily_build_group_report_results.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddIndexGroupIdToCiDailyBuildGroupReportResults < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_ci_daily_build_group_report_results_on_group_id' + + disable_ddl_transaction! + + def up + add_concurrent_index(:ci_daily_build_group_report_results, :group_id, name: INDEX_NAME) + add_concurrent_foreign_key(:ci_daily_build_group_report_results, :namespaces, column: :group_id) + end + + def down + remove_foreign_key_if_exists(:ci_daily_build_group_report_results, column: :group_id) + remove_concurrent_index_by_name(:ci_daily_build_group_report_results, INDEX_NAME) + end +end diff --git a/db/migrate/20210208161207_add_notes_create_limit_to_application_settings.rb b/db/migrate/20210208161207_add_notes_create_limit_to_application_settings.rb new file mode 100644 index 00000000000..4468da77e6c --- /dev/null +++ b/db/migrate/20210208161207_add_notes_create_limit_to_application_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddNotesCreateLimitToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :notes_create_limit, :integer, default: 300, null: false + end +end diff --git a/db/migrate/20210209160510_create_security_orchestration_policy_configurations.rb b/db/migrate/20210209160510_create_security_orchestration_policy_configurations.rb new file mode 100644 index 00000000000..896593c803f --- /dev/null +++ b/db/migrate/20210209160510_create_security_orchestration_policy_configurations.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class CreateSecurityOrchestrationPolicyConfigurations < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_PREFIX = 'index_sop_configs_' + + def up + table_comment = { owner: 'group::container security', description: 'Configuration used to store relationship between project and security policy repository' } + + create_table_with_constraints :security_orchestration_policy_configurations, comment: table_comment.to_json do |t| + t.references :project, null: false, foreign_key: { to_table: :projects, on_delete: :cascade }, index: { name: INDEX_PREFIX + 'on_project_id', unique: true } + t.references :security_policy_management_project, null: false, foreign_key: { to_table: :projects, on_delete: :restrict }, index: { name: INDEX_PREFIX + 'on_security_policy_management_project_id', unique: true } + + t.timestamps_with_timezone + end + end + + def down + with_lock_retries do + drop_table :security_orchestration_policy_configurations, force: :cascade + end + end +end diff --git a/db/migrate/20210209171525_add_status_index_to_packages_packages.rb b/db/migrate/20210209171525_add_status_index_to_packages_packages.rb new file mode 100644 index 00000000000..cb956165d6e --- /dev/null +++ b/db/migrate/20210209171525_add_status_index_to_packages_packages.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddStatusIndexToPackagesPackages < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_packages_packages_on_project_id_and_status' + + def up + add_concurrent_index :packages_packages, [:project_id, :status], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :packages_packages, name: INDEX_NAME + end +end diff --git a/db/migrate/20210210210232_add_notes_create_limit_allowlist_to_application_settings.rb b/db/migrate/20210210210232_add_notes_create_limit_allowlist_to_application_settings.rb new file mode 100644 index 00000000000..56feed3688c --- /dev/null +++ b/db/migrate/20210210210232_add_notes_create_limit_allowlist_to_application_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddNotesCreateLimitAllowlistToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :notes_create_limit_allowlist, :text, array: true, default: [], null: false + end +end diff --git a/db/migrate/20210211195543_add_created_by_user_for_cluster_agent_token.rb b/db/migrate/20210211195543_add_created_by_user_for_cluster_agent_token.rb new file mode 100644 index 00000000000..94dc8192037 --- /dev/null +++ b/db/migrate/20210211195543_add_created_by_user_for_cluster_agent_token.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddCreatedByUserForClusterAgentToken < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_cluster_agent_tokens_on_created_by_user_id' + + disable_ddl_transaction! + + def up + unless column_exists?(:cluster_agent_tokens, :created_by_user_id) + add_column :cluster_agent_tokens, :created_by_user_id, :bigint + end + + add_concurrent_index :cluster_agent_tokens, :created_by_user_id, name: INDEX_NAME + add_concurrent_foreign_key :cluster_agent_tokens, :users, column: :created_by_user_id, on_delete: :nullify + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :cluster_agent_tokens, :users, column: :created_by_user_id + end + + remove_concurrent_index_by_name :cluster_agent_tokens, INDEX_NAME + remove_column :cluster_agent_tokens, :created_by_user_id + end +end diff --git a/db/migrate/20210216135504_add_created_by_to_cluster_agent.rb b/db/migrate/20210216135504_add_created_by_to_cluster_agent.rb new file mode 100644 index 00000000000..fd679a1c525 --- /dev/null +++ b/db/migrate/20210216135504_add_created_by_to_cluster_agent.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class AddCreatedByToClusterAgent < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_cluster_agents_on_created_by_user_id' + + disable_ddl_transaction! + + def up + unless column_exists?(:cluster_agents, :created_by_user_id) + with_lock_retries do + add_column :cluster_agents, :created_by_user_id, :bigint + end + end + + add_concurrent_index :cluster_agents, :created_by_user_id, name: INDEX_NAME + add_concurrent_foreign_key :cluster_agents, :users, column: :created_by_user_id, on_delete: :nullify + end + + def down + with_lock_retries do + remove_column :cluster_agents, :created_by_user_id + end + end +end |