diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /db/migrate | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'db/migrate')
65 files changed, 1321 insertions, 0 deletions
diff --git a/db/migrate/20200816133024_add_cve_id_request_project_setting.rb b/db/migrate/20200816133024_add_cve_id_request_project_setting.rb new file mode 100644 index 00000000000..c4fe86845eb --- /dev/null +++ b/db/migrate/20200816133024_add_cve_id_request_project_setting.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddCveIdRequestProjectSetting < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + add_column :project_settings, :cve_id_request_enabled, :boolean, default: true, null: false + end + + def down + remove_column :project_settings, :cve_id_request_enabled + end +end diff --git a/db/migrate/20201209163113_recreate_index_issue_email_participants_on_issue_id_and_email.rb b/db/migrate/20201209163113_recreate_index_issue_email_participants_on_issue_id_and_email.rb new file mode 100644 index 00000000000..9cbf68fd63a --- /dev/null +++ b/db/migrate/20201209163113_recreate_index_issue_email_participants_on_issue_id_and_email.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class RecreateIndexIssueEmailParticipantsOnIssueIdAndEmail < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_issue_email_participants_on_issue_id_and_email' + NEW_INDEX_NAME = 'index_issue_email_participants_on_issue_id_and_lower_email' + + def up + # This table is currently empty, so no need to worry about unique index violations + add_concurrent_index :issue_email_participants, 'issue_id, lower(email)', unique: true, name: NEW_INDEX_NAME + remove_concurrent_index_by_name :issue_email_participants, OLD_INDEX_NAME + end + + def down + add_concurrent_index :issue_email_participants, [:issue_id, :email], unique: true, name: OLD_INDEX_NAME + remove_concurrent_index_by_name :issue_email_participants, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20201228110136_create_iterations_cadence.rb b/db/migrate/20201228110136_create_iterations_cadence.rb new file mode 100644 index 00000000000..95601ab4b29 --- /dev/null +++ b/db/migrate/20201228110136_create_iterations_cadence.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CreateIterationsCadence < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table_with_constraints :iterations_cadences do |t| + t.references :group, null: false, foreign_key: { to_table: :namespaces, on_delete: :cascade } + t.timestamps_with_timezone null: false + t.date :start_date, null: false + t.date :last_run_date + t.integer :duration_in_weeks + t.integer :iterations_in_advance + t.boolean :active, default: true, null: false + t.boolean :automatic, default: true, null: false + t.text :title, null: false + + t.text_limit :title, 255 + end + end + + def down + drop_table :iterations_cadences if table_exists?(:iterations_cadences) + end +end diff --git a/db/migrate/20201228110238_add_iterations_cadence_to_sprints.rb b/db/migrate/20201228110238_add_iterations_cadence_to_sprints.rb new file mode 100644 index 00000000000..9d9026a265b --- /dev/null +++ b/db/migrate/20201228110238_add_iterations_cadence_to_sprints.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddIterationsCadenceToSprints < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_sprints_iterations_cadence_id' + + def up + add_column :sprints, :iterations_cadence_id, :integer unless column_exists?(:sprints, :iterations_cadence_id) + + add_concurrent_index :sprints, :iterations_cadence_id, name: INDEX_NAME + add_concurrent_foreign_key :sprints, :iterations_cadences, column: :iterations_cadence_id, on_delete: :cascade + end + + def down + remove_column :sprints, :iterations_cadence_id if column_exists?(:sprints, :iterations_cadence_id) + end +end diff --git a/db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb b/db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb new file mode 100644 index 00000000000..5238192e1d1 --- /dev/null +++ b/db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +# This migration aligns an existing database schema with what we actually expect +# and fixes inconsistencies with index names and similar issues. +# +# This is intended for GitLab.com, but can be run on any instance. +class RenameIndexesOnGitLabCom < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + rename_index_if_exists :ldap_group_links, 'ldap_groups_pkey', 'ldap_group_links_pkey' + + # Removes unique constraint, add unique index instead + replace_unique_constraint_with_index :emails, :email, 'emails_email_key', 'index_emails_on_email' + replace_unique_constraint_with_index :users, :confirmation_token, 'users_confirmation_token_key', 'index_users_on_confirmation_token' + replace_unique_constraint_with_index :users, :reset_password_token, 'users_reset_password_token_key', 'index_users_on_reset_password_token' + replace_unique_constraint_with_index :users, :email, 'users_email_key', 'index_users_on_email' + + upgrade_to_primary_key(:schema_migrations, :version, 'schema_migrations_version_key', 'schema_migrations_pkey') + end + + def down + # no-op + end + + private + + def replace_unique_constraint_with_index(table, columns, old_name, new_name) + return unless index_exists_by_name?(table, old_name) + + add_concurrent_index table, columns, unique: true, name: new_name + execute "ALTER TABLE #{quote_table_name(table)} DROP CONSTRAINT #{quote_table_name(old_name)}" + end + + def rename_index_if_exists(table, old_name, new_name) + return unless index_exists_by_name?(table, old_name) + return if index_exists_by_name?(table, new_name) + + with_lock_retries do + rename_index table, old_name, new_name + end + end + + def upgrade_to_primary_key(table, column, old_name, new_name) + return unless index_exists_by_name?(table, old_name) + return if index_exists_by_name?(table, new_name) + + return if primary_key(table) + + execute "ALTER TABLE #{quote_table_name(table)} ADD CONSTRAINT #{new_name} PRIMARY KEY (#{column})" + execute "ALTER TABLE #{quote_table_name(table)} DROP CONSTRAINT #{old_name}" + end +end diff --git a/db/migrate/20210127152613_add_iterations_cadence_date_range_constraint.rb b/db/migrate/20210127152613_add_iterations_cadence_date_range_constraint.rb new file mode 100644 index 00000000000..95ecd167076 --- /dev/null +++ b/db/migrate/20210127152613_add_iterations_cadence_date_range_constraint.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class AddIterationsCadenceDateRangeConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + execute <<~SQL + ALTER TABLE sprints + ADD CONSTRAINT iteration_start_and_due_date_iterations_cadence_id_constraint + EXCLUDE USING gist + ( iterations_cadence_id WITH =, + daterange(start_date, due_date, '[]') WITH && + ) + WHERE (group_id IS NOT NULL) + SQL + end + end + + def down + with_lock_retries do + execute <<~SQL + ALTER TABLE sprints + DROP CONSTRAINT IF EXISTS iteration_start_and_due_date_iterations_cadence_id_constraint + SQL + end + end +end diff --git a/db/migrate/20210127202613_remove_iteration_group_date_range_constraint.rb b/db/migrate/20210127202613_remove_iteration_group_date_range_constraint.rb new file mode 100644 index 00000000000..e6c5eb1b411 --- /dev/null +++ b/db/migrate/20210127202613_remove_iteration_group_date_range_constraint.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class RemoveIterationGroupDateRangeConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + execute <<~SQL + ALTER TABLE sprints + DROP CONSTRAINT IF EXISTS iteration_start_and_due_daterange_group_id_constraint + SQL + end + end + + def down + with_lock_retries do + execute <<~SQL + ALTER TABLE sprints + ADD CONSTRAINT iteration_start_and_due_daterange_group_id_constraint + EXCLUDE USING gist + ( group_id WITH =, + daterange(start_date, due_date, '[]') WITH && + ) + WHERE (group_id IS NOT NULL) + SQL + end + end +end diff --git a/db/migrate/20210128172149_create_background_migration_tracking_tables.rb b/db/migrate/20210128172149_create_background_migration_tracking_tables.rb new file mode 100644 index 00000000000..767bd8737a3 --- /dev/null +++ b/db/migrate/20210128172149_create_background_migration_tracking_tables.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +class CreateBackgroundMigrationTrackingTables < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table_with_constraints :batched_background_migrations do |t| + t.timestamps_with_timezone + t.bigint :min_value, null: false, default: 1 + t.bigint :max_value, null: false + t.integer :batch_size, null: false + t.integer :sub_batch_size, null: false + t.integer :interval, limit: 2, null: false + t.integer :status, limit: 2, null: false, default: 0 + t.text :job_class_name, null: false + t.text :batch_class_name, null: false, + default: 'Gitlab::Database::BackgroundMigration::PrimaryKeyBatchingStrategy' + t.text :table_name, null: false + t.text :column_name, null: false + t.jsonb :job_arguments, null: false, default: '[]' + + t.text_limit :job_class_name, 100 + t.text_limit :batch_class_name, 100 + t.text_limit :table_name, 63 + t.text_limit :column_name, 63 + + t.check_constraint :check_positive_min_value, 'min_value > 0' + t.check_constraint :check_max_value_in_range, 'max_value >= min_value' + + t.check_constraint :check_positive_sub_batch_size, 'sub_batch_size > 0' + t.check_constraint :check_batch_size_in_range, 'batch_size >= sub_batch_size' + + t.index %i[job_class_name table_name column_name], name: :index_batched_migrations_on_job_table_and_column_name + end + + create_table :batched_background_migration_jobs do |t| + t.timestamps_with_timezone + t.datetime_with_timezone :started_at + t.datetime_with_timezone :finished_at + t.references :batched_background_migration, null: false, index: false, foreign_key: { on_delete: :cascade } + t.bigint :min_value, null: false + t.bigint :max_value, null: false + t.integer :batch_size, null: false + t.integer :sub_batch_size, null: false + t.integer :status, limit: 2, null: false, default: 0 + t.integer :attempts, limit: 2, null: false, default: 0 + + t.index [:batched_background_migration_id, :id], name: :index_batched_jobs_by_batched_migration_id_and_id + end + end + + def down + drop_table :batched_background_migration_jobs + + drop_table :batched_background_migrations + end +end diff --git a/db/migrate/20210201034649_add_active_periods_to_on_call_rotations.rb b/db/migrate/20210201034649_add_active_periods_to_on_call_rotations.rb new file mode 100644 index 00000000000..714187f60e0 --- /dev/null +++ b/db/migrate/20210201034649_add_active_periods_to_on_call_rotations.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddActivePeriodsToOnCallRotations < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :incident_management_oncall_rotations, :active_period_start, :time, null: true + add_column :incident_management_oncall_rotations, :active_period_end, :time, null: true + end +end diff --git a/db/migrate/20210205134213_add_creator_id_to_custom_emoji.rb b/db/migrate/20210205134213_add_creator_id_to_custom_emoji.rb new file mode 100644 index 00000000000..c01335767a8 --- /dev/null +++ b/db/migrate/20210205134213_add_creator_id_to_custom_emoji.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddCreatorIdToCustomEmoji < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + # Custom Emoji is at the moment behind a default-disabled feature flag. It + # will be unlikely there are any records in this table, but to able to + # ensure a not-null constraint delete any existing rows. + # Roll-out issue: https://gitlab.com/gitlab-org/gitlab/-/issues/231317 + execute 'DELETE FROM custom_emoji' + + add_reference :custom_emoji, # rubocop:disable Migration/AddReference + :creator, + index: true, + null: false, # rubocop:disable Rails/NotNullColumn + foreign_key: false # FK is added in 20210219100137 + end + + def down + remove_reference :custom_emoji, :creator + end +end diff --git a/db/migrate/20210208103243_add_issue_created_at_to_onboarding_progress.rb b/db/migrate/20210208103243_add_issue_created_at_to_onboarding_progress.rb new file mode 100644 index 00000000000..e8318ecd929 --- /dev/null +++ b/db/migrate/20210208103243_add_issue_created_at_to_onboarding_progress.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddIssueCreatedAtToOnboardingProgress < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :onboarding_progresses, :issue_created_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20210208200914_add_ends_at_to_oncall_rotations.rb b/db/migrate/20210208200914_add_ends_at_to_oncall_rotations.rb new file mode 100644 index 00000000000..5cd179c9a80 --- /dev/null +++ b/db/migrate/20210208200914_add_ends_at_to_oncall_rotations.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddEndsAtToOncallRotations < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :incident_management_oncall_rotations, :ends_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20210209110019_create_external_approval_rules.rb b/db/migrate/20210209110019_create_external_approval_rules.rb new file mode 100644 index 00000000000..5d6780ec412 --- /dev/null +++ b/db/migrate/20210209110019_create_external_approval_rules.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class CreateExternalApprovalRules < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + + def up + create_table_with_constraints :external_approval_rules, if_not_exists: true do |t| + t.references :project, foreign_key: { on_delete: :cascade }, null: false, index: false + t.timestamps_with_timezone + t.text :external_url, null: false + t.text_limit :external_url, 255 + t.text :name, null: false + t.text_limit :name, 255 + + t.index([:project_id, :name], + unique: true, + name: 'idx_on_external_approval_rules_project_id_name') + t.index([:project_id, :external_url], + unique: true, + name: 'idx_on_external_approval_rules_project_id_external_url') + end + + create_table :external_approval_rules_protected_branches do |t| + t.bigint :external_approval_rule_id, null: false, index: { name: 'idx_eaprpb_external_approval_rule_id' } + t.bigint :protected_branch_id, null: false + t.index([:protected_branch_id, :external_approval_rule_id], + unique: true, + name: 'idx_protected_branch_id_external_approval_rule_id') + end + end + + def down + with_lock_retries do + drop_table :external_approval_rules_protected_branches, force: :cascade, if_exists: true + end + + with_lock_retries do + drop_table :external_approval_rules, force: :cascade, if_exists: true + end + end +end diff --git a/db/migrate/20210209232508_add_markdown_surround_selection_to_user_preferences.rb b/db/migrate/20210209232508_add_markdown_surround_selection_to_user_preferences.rb new file mode 100644 index 00000000000..c4063a55d18 --- /dev/null +++ b/db/migrate/20210209232508_add_markdown_surround_selection_to_user_preferences.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddMarkdownSurroundSelectionToUserPreferences < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + add_column :user_preferences, :markdown_surround_selection, :boolean, default: true, null: false + end + end + + def down + with_lock_retries do + remove_column :user_preferences, :markdown_surround_selection, :boolean + end + end +end diff --git a/db/migrate/20210212153934_make_the_geo_oauth_application_trusted_by_default.rb b/db/migrate/20210212153934_make_the_geo_oauth_application_trusted_by_default.rb new file mode 100644 index 00000000000..ab0343887e4 --- /dev/null +++ b/db/migrate/20210212153934_make_the_geo_oauth_application_trusted_by_default.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class MakeTheGeoOauthApplicationTrustedByDefault < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + execute(<<-SQL.squish) + UPDATE oauth_applications + SET confidential = true, trusted = true + WHERE id IN (SELECT oauth_application_id FROM geo_nodes); + SQL + end + + def down + # We won't be able to tell which trusted applications weren't + # confidential before the migration and setting all trusted + # applications are not confidential would introduce security + # issues. + end +end diff --git a/db/migrate/20210212163231_add_merge_when_pipeline_succeeds_to_notification_settings.rb b/db/migrate/20210212163231_add_merge_when_pipeline_succeeds_to_notification_settings.rb new file mode 100644 index 00000000000..08d0a99436e --- /dev/null +++ b/db/migrate/20210212163231_add_merge_when_pipeline_succeeds_to_notification_settings.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 AddMergeWhenPipelineSucceedsToNotificationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :notification_settings, :merge_when_pipeline_succeeds, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210214201118_add_delayed_project_removal_to_namespace_settings.rb b/db/migrate/20210214201118_add_delayed_project_removal_to_namespace_settings.rb new file mode 100644 index 00000000000..1c6e0b0c27c --- /dev/null +++ b/db/migrate/20210214201118_add_delayed_project_removal_to_namespace_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddDelayedProjectRemovalToNamespaceSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :namespace_settings, :delayed_project_removal, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20210214205155_add_index_to_namespaces_delayed_project_removal.rb b/db/migrate/20210214205155_add_index_to_namespaces_delayed_project_removal.rb new file mode 100644 index 00000000000..8d09a5c9269 --- /dev/null +++ b/db/migrate/20210214205155_add_index_to_namespaces_delayed_project_removal.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexToNamespacesDelayedProjectRemoval < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'tmp_idx_on_namespaces_delayed_project_removal' + + disable_ddl_transaction! + + def up + add_concurrent_index :namespaces, :id, name: INDEX_NAME, where: 'delayed_project_removal = TRUE' + end + + def down + remove_concurrent_index_by_name :namespaces, INDEX_NAME + end +end diff --git a/db/migrate/20210216122140_add_in_product_marketing_emails_enabled_setting.rb b/db/migrate/20210216122140_add_in_product_marketing_emails_enabled_setting.rb new file mode 100644 index 00000000000..5813b1b5f33 --- /dev/null +++ b/db/migrate/20210216122140_add_in_product_marketing_emails_enabled_setting.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddInProductMarketingEmailsEnabledSetting < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :in_product_marketing_emails_enabled, :boolean, null: false, default: true + end +end diff --git a/db/migrate/20210216193620_add_description_to_cluster_token.rb b/db/migrate/20210216193620_add_description_to_cluster_token.rb new file mode 100644 index 00000000000..67f7c6bd522 --- /dev/null +++ b/db/migrate/20210216193620_add_description_to_cluster_token.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddDescriptionToClusterToken < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless column_exists?(:cluster_agent_tokens, :description) + add_column :cluster_agent_tokens, :description, :text + end + + add_text_limit :cluster_agent_tokens, :description, 1024 + end + + def down + remove_column :cluster_agent_tokens, :description + end +end diff --git a/db/migrate/20210216223335_remove_index_on_issues_where_service_desk_reply_to_is_not_null.rb b/db/migrate/20210216223335_remove_index_on_issues_where_service_desk_reply_to_is_not_null.rb new file mode 100644 index 00000000000..5224b6f7031 --- /dev/null +++ b/db/migrate/20210216223335_remove_index_on_issues_where_service_desk_reply_to_is_not_null.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveIndexOnIssuesWhereServiceDeskReplyToIsNotNull < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_TABLE = :issues + INDEX_NAME = 'idx_on_issues_where_service_desk_reply_to_is_not_null' + + def up + Gitlab::BackgroundMigration.steal('PopulateIssueEmailParticipants') + remove_concurrent_index_by_name INDEX_TABLE, INDEX_NAME + end + + def down + add_concurrent_index(INDEX_TABLE, [:id], name: INDEX_NAME, where: 'service_desk_reply_to IS NOT NULL') + end +end diff --git a/db/migrate/20210217101901_create_epic_list_user_preferences.rb b/db/migrate/20210217101901_create_epic_list_user_preferences.rb new file mode 100644 index 00000000000..5aacea1938d --- /dev/null +++ b/db/migrate/20210217101901_create_epic_list_user_preferences.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CreateEpicListUserPreferences < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + create_table :boards_epic_list_user_preferences do |t| + t.bigint :user_id, null: false + t.bigint :epic_list_id, index: true, null: false + t.timestamps_with_timezone null: false + t.boolean :collapsed, null: false, default: false + end + + add_index :boards_epic_list_user_preferences, [:user_id, :epic_list_id], unique: true, name: 'index_epic_board_list_preferences_on_user_and_list' + end + + def down + drop_table :boards_epic_list_user_preferences + end +end diff --git a/db/migrate/20210218040814_add_environment_scope_to_group_variables.rb b/db/migrate/20210218040814_add_environment_scope_to_group_variables.rb new file mode 100644 index 00000000000..5cc41f570aa --- /dev/null +++ b/db/migrate/20210218040814_add_environment_scope_to_group_variables.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class AddEnvironmentScopeToGroupVariables < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + OLD_INDEX = 'index_ci_group_variables_on_group_id_and_key' + NEW_INDEX = 'index_ci_group_variables_on_group_id_and_key_and_environment' + + disable_ddl_transaction! + + def up + unless column_exists?(:ci_group_variables, :environment_scope) + # rubocop:disable Migration/AddLimitToTextColumns + # Added in 20210305013509_add_text_limit_to_group_ci_variables_environment_scope + add_column :ci_group_variables, :environment_scope, :text, null: false, default: '*' + # rubocop:enable Migration/AddLimitToTextColumns + end + + add_concurrent_index :ci_group_variables, [:group_id, :key, :environment_scope], unique: true, name: NEW_INDEX + remove_concurrent_index_by_name :ci_group_variables, OLD_INDEX + end + + def down + remove_duplicates! + + add_concurrent_index :ci_group_variables, [:group_id, :key], unique: true, name: OLD_INDEX + remove_concurrent_index_by_name :ci_group_variables, NEW_INDEX + + remove_column :ci_group_variables, :environment_scope + end + + private + + def remove_duplicates! + execute <<-SQL + DELETE FROM ci_group_variables + WHERE id NOT IN ( + SELECT MIN(id) + FROM ci_group_variables + GROUP BY group_id, key + ) + SQL + end +end diff --git a/db/migrate/20210218142626_change_finding_fingerprint_enum.rb b/db/migrate/20210218142626_change_finding_fingerprint_enum.rb new file mode 100644 index 00000000000..615509e0c04 --- /dev/null +++ b/db/migrate/20210218142626_change_finding_fingerprint_enum.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class ChangeFindingFingerprintEnum < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + change_column :vulnerability_finding_fingerprints, :algorithm_type, :integer, limit: 2 + end + + def down + change_column :vulnerability_finding_fingerprints, :algorithm_type, :integer + end +end diff --git a/db/migrate/20210218144056_add_sprints_start_date_not_null_check_constraint.rb b/db/migrate/20210218144056_add_sprints_start_date_not_null_check_constraint.rb new file mode 100644 index 00000000000..243080f49b2 --- /dev/null +++ b/db/migrate/20210218144056_add_sprints_start_date_not_null_check_constraint.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddSprintsStartDateNotNullCheckConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_not_null_constraint(:sprints, :start_date, validate: false) + end + + def down + remove_not_null_constraint(:sprints, :start_date) + end +end diff --git a/db/migrate/20210218144656_add_sprints_due_date_not_null_check_constraint.rb b/db/migrate/20210218144656_add_sprints_due_date_not_null_check_constraint.rb new file mode 100644 index 00000000000..9f3ed6fd13a --- /dev/null +++ b/db/migrate/20210218144656_add_sprints_due_date_not_null_check_constraint.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddSprintsDueDateNotNullCheckConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_not_null_constraint(:sprints, :due_date, validate: false) + end + + def down + remove_not_null_constraint(:sprints, :due_date) + end +end diff --git a/db/migrate/20210219100137_add_creator_foreign_key_to_custom_emoji.rb b/db/migrate/20210219100137_add_creator_foreign_key_to_custom_emoji.rb new file mode 100644 index 00000000000..a954ba5ba3b --- /dev/null +++ b/db/migrate/20210219100137_add_creator_foreign_key_to_custom_emoji.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddCreatorForeignKeyToCustomEmoji < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + FK_NAME = 'fk_custom_emoji_creator_id' + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :custom_emoji, :users, + on_delete: :cascade, + column: :creator_id, + name: FK_NAME + end + + def down + with_lock_retries do + remove_foreign_key :custom_emoji, name: FK_NAME + end + end +end diff --git a/db/migrate/20210219111040_add_epic_issue_composite_index.rb b/db/migrate/20210219111040_add_epic_issue_composite_index.rb new file mode 100644 index 00000000000..f1344baf0c7 --- /dev/null +++ b/db/migrate/20210219111040_add_epic_issue_composite_index.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddEpicIssueCompositeIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_epic_issues_on_epic_id_and_issue_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :epic_issues, [:epic_id, :issue_id], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :epic_issues, INDEX_NAME + end +end diff --git a/db/migrate/20210222030537_add_is_removed_to_oncall_participant.rb b/db/migrate/20210222030537_add_is_removed_to_oncall_participant.rb new file mode 100644 index 00000000000..83b81a067ab --- /dev/null +++ b/db/migrate/20210222030537_add_is_removed_to_oncall_participant.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIsRemovedToOncallParticipant < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :incident_management_oncall_participants, :is_removed, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :incident_management_oncall_participants, :is_removed + end + end +end diff --git a/db/migrate/20210222042745_add_is_removed_index_to_oncall_participant.rb b/db/migrate/20210222042745_add_is_removed_index_to_oncall_participant.rb new file mode 100644 index 00000000000..cfa9b1b89c9 --- /dev/null +++ b/db/migrate/20210222042745_add_is_removed_index_to_oncall_participant.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddIsRemovedIndexToOncallParticipant < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + EXISTING_INDEX_NAME = 'index_inc_mgmnt_oncall_participants_on_oncall_rotation_id' + NEW_INDEX_NAME = 'index_inc_mgmnt_oncall_pcpnt_on_oncall_rotation_id_is_removed' + + def up + add_concurrent_index :incident_management_oncall_participants, [:oncall_rotation_id, :is_removed], name: NEW_INDEX_NAME + remove_concurrent_index_by_name(:incident_management_oncall_participants, EXISTING_INDEX_NAME) + end + + def down + add_concurrent_index :incident_management_oncall_participants, :oncall_rotation_id, name: EXISTING_INDEX_NAME + remove_concurrent_index_by_name(:incident_management_oncall_participants, NEW_INDEX_NAME) + end +end diff --git a/db/migrate/20210222070356_add_storage_size_to_namespace_statistics.rb b/db/migrate/20210222070356_add_storage_size_to_namespace_statistics.rb new file mode 100644 index 00000000000..838c22382c6 --- /dev/null +++ b/db/migrate/20210222070356_add_storage_size_to_namespace_statistics.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddStorageSizeToNamespaceStatistics < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :namespace_statistics, :storage_size, :bigint, default: 0, null: false + end + end + + def down + with_lock_retries do + remove_column :namespace_statistics, :storage_size + end + end +end diff --git a/db/migrate/20210222070413_add_wiki_size_to_namespace_statistics.rb b/db/migrate/20210222070413_add_wiki_size_to_namespace_statistics.rb new file mode 100644 index 00000000000..9e6ced9fd64 --- /dev/null +++ b/db/migrate/20210222070413_add_wiki_size_to_namespace_statistics.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddWikiSizeToNamespaceStatistics < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :namespace_statistics, :wiki_size, :bigint, default: 0, null: false + end + end + + def down + with_lock_retries do + remove_column :namespace_statistics, :wiki_size + end + end +end diff --git a/db/migrate/20210222085529_add_epic_board_user_preference_user_fk.rb b/db/migrate/20210222085529_add_epic_board_user_preference_user_fk.rb new file mode 100644 index 00000000000..52de892a177 --- /dev/null +++ b/db/migrate/20210222085529_add_epic_board_user_preference_user_fk.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddEpicBoardUserPreferenceUserFk < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :boards_epic_list_user_preferences, :users, column: :user_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :boards_epic_list_user_preferences, :users + end + end +end diff --git a/db/migrate/20210222085551_add_epic_board_user_preference_epic_list_fk.rb b/db/migrate/20210222085551_add_epic_board_user_preference_epic_list_fk.rb new file mode 100644 index 00000000000..3f62036b899 --- /dev/null +++ b/db/migrate/20210222085551_add_epic_board_user_preference_epic_list_fk.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddEpicBoardUserPreferenceEpicListFk < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :boards_epic_list_user_preferences, :boards_epic_lists, column: :epic_list_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :boards_epic_list_user_preferences, :boards_epic_lists + end + end +end diff --git a/db/migrate/20210222105120_add_container_registry_access_level.rb b/db/migrate/20210222105120_add_container_registry_access_level.rb new file mode 100644 index 00000000000..2324866b0ef --- /dev/null +++ b/db/migrate/20210222105120_add_container_registry_access_level.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddContainerRegistryAccessLevel < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column( + :project_features, + :container_registry_access_level, + :integer, + default: 0, # ProjectFeature::DISABLED value + null: false + ) + end + end + + def down + with_lock_retries do + remove_column :project_features, :container_registry_access_level + end + end +end diff --git a/db/migrate/20210223053451_add_branch_name_to_dast_profile.rb b/db/migrate/20210223053451_add_branch_name_to_dast_profile.rb new file mode 100644 index 00000000000..311e809103f --- /dev/null +++ b/db/migrate/20210223053451_add_branch_name_to_dast_profile.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class AddBranchNameToDastProfile < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + add_column :dast_profiles, :branch_name, :text + end + + add_text_limit :dast_profiles, :branch_name, 255 + end + + def down + with_lock_retries do + remove_column :dast_profiles, :branch_name + end + end +end diff --git a/db/migrate/20210223132934_add_foreign_key_to_external_approval_rules.rb b/db/migrate/20210223132934_add_foreign_key_to_external_approval_rules.rb new file mode 100644 index 00000000000..b5f04672813 --- /dev/null +++ b/db/migrate/20210223132934_add_foreign_key_to_external_approval_rules.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddForeignKeyToExternalApprovalRules < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :external_approval_rules_protected_branches, :external_approval_rules, column: :external_approval_rule_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :external_approval_rules_protected_branches, column: :external_approval_rule_id + end + end +end diff --git a/db/migrate/20210223133116_add_foreign_key_to_external_approval_rules_protected_branches.rb b/db/migrate/20210223133116_add_foreign_key_to_external_approval_rules_protected_branches.rb new file mode 100644 index 00000000000..ad51f765d8a --- /dev/null +++ b/db/migrate/20210223133116_add_foreign_key_to_external_approval_rules_protected_branches.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddForeignKeyToExternalApprovalRulesProtectedBranches < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :external_approval_rules_protected_branches, :protected_branches, column: :protected_branch_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :external_approval_rules_protected_branches, column: :protected_branch_id + end + end +end diff --git a/db/migrate/20210224132547_add_null_constraint_to_terraform_state_name.rb b/db/migrate/20210224132547_add_null_constraint_to_terraform_state_name.rb new file mode 100644 index 00000000000..d9f23311cf5 --- /dev/null +++ b/db/migrate/20210224132547_add_null_constraint_to_terraform_state_name.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddNullConstraintToTerraformStateName < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + change_column_null :terraform_states, :name, false + end +end diff --git a/db/migrate/20210224133337_add_name_field_to_cluster_agent_token.rb b/db/migrate/20210224133337_add_name_field_to_cluster_agent_token.rb new file mode 100644 index 00000000000..2cec37f8477 --- /dev/null +++ b/db/migrate/20210224133337_add_name_field_to_cluster_agent_token.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AddNameFieldToClusterAgentToken < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in LimitClusterTokenSize + def change + add_column :cluster_agent_tokens, :name, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20210225090801_create_dora_daily_metrics.rb b/db/migrate/20210225090801_create_dora_daily_metrics.rb new file mode 100644 index 00000000000..65c1dbc23e4 --- /dev/null +++ b/db/migrate/20210225090801_create_dora_daily_metrics.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class CreateDoraDailyMetrics < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + create_table :dora_daily_metrics, if_not_exists: true do |t| + t.references :environment, null: false, foreign_key: { on_delete: :cascade }, index: false + t.date :date, null: false + t.integer :deployment_frequency + t.integer :lead_time_for_changes_in_seconds + + t.index [:environment_id, :date], unique: true + end + end + + add_check_constraint :dora_daily_metrics, "deployment_frequency >= 0", 'dora_daily_metrics_deployment_frequency_positive' + add_check_constraint :dora_daily_metrics, "lead_time_for_changes_in_seconds >= 0", 'dora_daily_metrics_lead_time_for_changes_in_seconds_positive' + end + + def down + with_lock_retries do + drop_table :dora_daily_metrics + end + end +end diff --git a/db/migrate/20210225135533_limit_cluster_token_size.rb b/db/migrate/20210225135533_limit_cluster_token_size.rb new file mode 100644 index 00000000000..6a1b6b7b4e8 --- /dev/null +++ b/db/migrate/20210225135533_limit_cluster_token_size.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class LimitClusterTokenSize < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :cluster_agent_tokens, :name, 255 + end + + def down + remove_text_limit :cluster_agent_tokens, :name + end +end diff --git a/db/migrate/20210225153522_add_allow_force_push_to_protected_branches.rb b/db/migrate/20210225153522_add_allow_force_push_to_protected_branches.rb new file mode 100644 index 00000000000..92a15cb45dd --- /dev/null +++ b/db/migrate/20210225153522_add_allow_force_push_to_protected_branches.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddAllowForcePushToProtectedBranches < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :protected_branches, :allow_force_push, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :protected_branches, :allow_force_push + end + end +end diff --git a/db/migrate/20210301150451_add_tier_to_environments.rb b/db/migrate/20210301150451_add_tier_to_environments.rb new file mode 100644 index 00000000000..28592dd2bf6 --- /dev/null +++ b/db/migrate/20210301150451_add_tier_to_environments.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddTierToEnvironments < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :environments, :tier, :smallint + end + end + + def down + with_lock_retries do + remove_column :environments, :tier + end + end +end diff --git a/db/migrate/20210301193412_add_optional_to_ci_build_needs.rb b/db/migrate/20210301193412_add_optional_to_ci_build_needs.rb new file mode 100644 index 00000000000..2c6e85f930d --- /dev/null +++ b/db/migrate/20210301193412_add_optional_to_ci_build_needs.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddOptionalToCiBuildNeeds < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :ci_build_needs, :optional, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :ci_build_needs, :optional + end + end +end diff --git a/db/migrate/20210301200601_rename_asset_proxy_allowlist_on_application_settings.rb b/db/migrate/20210301200601_rename_asset_proxy_allowlist_on_application_settings.rb index 8a9acd8b86e..8ac334fc6a4 100644 --- a/db/migrate/20210301200601_rename_asset_proxy_allowlist_on_application_settings.rb +++ b/db/migrate/20210301200601_rename_asset_proxy_allowlist_on_application_settings.rb @@ -8,6 +8,10 @@ class RenameAssetProxyAllowlistOnApplicationSettings < ActiveRecord::Migration[6 disable_ddl_transaction! def up + cleanup_concurrent_column_rename :application_settings, + :asset_proxy_whitelist, + :asset_proxy_allowlist + rename_column_concurrently :application_settings, :asset_proxy_allowlist, :asset_proxy_whitelist @@ -17,5 +21,9 @@ class RenameAssetProxyAllowlistOnApplicationSettings < ActiveRecord::Migration[6 undo_rename_column_concurrently :application_settings, :asset_proxy_allowlist, :asset_proxy_whitelist + + undo_cleanup_concurrent_column_rename :application_settings, + :asset_proxy_whitelist, + :asset_proxy_allowlist end end diff --git a/db/migrate/20210302103851_add_deployed_deployment_id_index_to_project_pages_metadata.rb b/db/migrate/20210302103851_add_deployed_deployment_id_index_to_project_pages_metadata.rb new file mode 100644 index 00000000000..e10e9a912cc --- /dev/null +++ b/db/migrate/20210302103851_add_deployed_deployment_id_index_to_project_pages_metadata.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDeployedDeploymentIdIndexToProjectPagesMetadata < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_on_pages_metadata_not_migrated' + + def up + add_concurrent_index :project_pages_metadata, :project_id, where: "deployed = TRUE AND pages_deployment_id is NULL", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :project_pages_metadata, INDEX_NAME + end +end diff --git a/db/migrate/20210302155904_remove_index_for_security_orchestration_policy.rb b/db/migrate/20210302155904_remove_index_for_security_orchestration_policy.rb new file mode 100644 index 00000000000..5d2594f2b9e --- /dev/null +++ b/db/migrate/20210302155904_remove_index_for_security_orchestration_policy.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveIndexForSecurityOrchestrationPolicy < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_sop_configs_on_security_policy_management_project_id' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name(:security_orchestration_policy_configurations, INDEX_NAME) + end + + def down + add_concurrent_index(:security_orchestration_policy_configurations, :security_policy_management_project_id, name: INDEX_NAME) + end +end diff --git a/db/migrate/20210302160544_add_index_to_security_orchestration_policy.rb b/db/migrate/20210302160544_add_index_to_security_orchestration_policy.rb new file mode 100644 index 00000000000..4750e2bdb79 --- /dev/null +++ b/db/migrate/20210302160544_add_index_to_security_orchestration_policy.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexToSecurityOrchestrationPolicy < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX = 'index_sop_configurations_project_id_policy_project_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_orchestration_policy_configurations, [:security_policy_management_project_id, :project_id], name: INDEX + end + + def down + remove_concurrent_index_by_name :security_orchestration_policy_configurations, INDEX + end +end diff --git a/db/migrate/20210302212623_rename_vuln_fingerprints_indexes.rb b/db/migrate/20210302212623_rename_vuln_fingerprints_indexes.rb new file mode 100644 index 00000000000..0f431fbeda5 --- /dev/null +++ b/db/migrate/20210302212623_rename_vuln_fingerprints_indexes.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class RenameVulnFingerprintsIndexes < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + FINGERPRINT_IDX = :idx_vuln_fingerprints_on_occurrences_id_and_fingerprint + FINGERPRINT_IDX_RENAMED = :idx_vuln_fingerprints_on_occurrences_id_and_fingerprint_sha256 + UNIQ_IDX = :idx_vuln_fingerprints_uniqueness + UNIQ_IDX_RENAMED = :idx_vuln_fingerprints_uniqueness_fingerprint_sha256 + + disable_ddl_transaction! + + def up + # These `unless` checks are necessary for re-running the migrations multiple times + unless index_exists_by_name?(:vulnerability_finding_fingerprints, FINGERPRINT_IDX_RENAMED) + rename_index :vulnerability_finding_fingerprints, FINGERPRINT_IDX, FINGERPRINT_IDX_RENAMED + end + + unless index_exists_by_name?(:vulnerability_finding_fingerprints, UNIQ_IDX_RENAMED) + rename_index :vulnerability_finding_fingerprints, UNIQ_IDX, UNIQ_IDX_RENAMED + end + end + + def down + unless index_exists_by_name?(:vulnerability_finding_fingerprints, FINGERPRINT_IDX) + rename_index :vulnerability_finding_fingerprints, FINGERPRINT_IDX_RENAMED, FINGERPRINT_IDX + end + + unless index_exists_by_name?(:vulnerability_finding_fingerprints, UNIQ_IDX) + rename_index :vulnerability_finding_fingerprints, UNIQ_IDX_RENAMED, UNIQ_IDX + end + end +end diff --git a/db/migrate/20210303053341_add_last_edited_at_and_last_edited_by_id_to_notes.rb b/db/migrate/20210303053341_add_last_edited_at_and_last_edited_by_id_to_notes.rb new file mode 100644 index 00000000000..b6f4da202fa --- /dev/null +++ b/db/migrate/20210303053341_add_last_edited_at_and_last_edited_by_id_to_notes.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddLastEditedAtAndLastEditedByIdToNotes < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :notes, :last_edited_at, :datetime_with_timezone + end + end + + def down + with_lock_retries do + remove_column :notes, :last_edited_at + end + end +end diff --git a/db/migrate/20210303091651_add_index_to_environments_tier.rb b/db/migrate/20210303091651_add_index_to_environments_tier.rb new file mode 100644 index 00000000000..0ec876945d9 --- /dev/null +++ b/db/migrate/20210303091651_add_index_to_environments_tier.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddIndexToEnvironmentsTier < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + INDEX_NAME = 'index_environments_on_project_id_and_tier' + + DOWNTIME = false + + def up + add_concurrent_index :environments, [:project_id, :tier], where: 'tier IS NOT NULL', name: INDEX_NAME + end + + def down + remove_concurrent_index :environments, :state, name: INDEX_NAME + end +end diff --git a/db/migrate/20210303165201_add_index_for_succeeded_deployments.rb b/db/migrate/20210303165201_add_index_for_succeeded_deployments.rb new file mode 100644 index 00000000000..1ae5b36d2f2 --- /dev/null +++ b/db/migrate/20210303165201_add_index_for_succeeded_deployments.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexForSucceededDeployments < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_deployments_on_environment_id_status_and_finished_at' + + disable_ddl_transaction! + + def up + add_concurrent_index(:deployments, %i[environment_id status finished_at], name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(:deployments, INDEX_NAME) + end +end diff --git a/db/migrate/20210303165301_add_not_null_constraint_to_cluster_token_name.rb b/db/migrate/20210303165301_add_not_null_constraint_to_cluster_token_name.rb new file mode 100644 index 00000000000..5fc8970b8f9 --- /dev/null +++ b/db/migrate/20210303165301_add_not_null_constraint_to_cluster_token_name.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddNotNullConstraintToClusterTokenName < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + # This will add the `NOT NULL` constraint WITHOUT validating it + add_not_null_constraint :cluster_agent_tokens, :name, validate: false + end + + def down + remove_not_null_constraint :cluster_agent_tokens, :name + end +end diff --git a/db/migrate/20210303193544_add_concurrent_fields_to_bulk_imports_trackers.rb b/db/migrate/20210303193544_add_concurrent_fields_to_bulk_imports_trackers.rb new file mode 100644 index 00000000000..a2d3d6daf09 --- /dev/null +++ b/db/migrate/20210303193544_add_concurrent_fields_to_bulk_imports_trackers.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddConcurrentFieldsToBulkImportsTrackers < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # rubocop:disable Rails/NotNullColumn + def up + add_column :bulk_import_trackers, :jid, :text + add_column :bulk_import_trackers, :stage, :smallint, default: 0, null: false + add_column :bulk_import_trackers, :status, :smallint, default: 0, null: false + end + # rubocop:enable Migration/AddLimitToTextColumns + # rubocop:enable Rails/NotNullColumn + + def down + remove_column :bulk_import_trackers, :jid, :text + remove_column :bulk_import_trackers, :stage, :smallint + remove_column :bulk_import_trackers, :status, :smallint + end +end diff --git a/db/migrate/20210303193605_add_text_limits_to_bulk_imports_trackers_jid_and_pipeline_name.rb b/db/migrate/20210303193605_add_text_limits_to_bulk_imports_trackers_jid_and_pipeline_name.rb new file mode 100644 index 00000000000..7686dd0343b --- /dev/null +++ b/db/migrate/20210303193605_add_text_limits_to_bulk_imports_trackers_jid_and_pipeline_name.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddTextLimitsToBulkImportsTrackersJidAndPipelineName < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :bulk_import_trackers, :jid, 255 + end + + def down + remove_text_limit :bulk_import_trackers, :jid + end +end diff --git a/db/migrate/20210305002016_update_terraform_states_locked_by_user_id_foreign_key.rb b/db/migrate/20210305002016_update_terraform_states_locked_by_user_id_foreign_key.rb new file mode 100644 index 00000000000..aa4a4e9c928 --- /dev/null +++ b/db/migrate/20210305002016_update_terraform_states_locked_by_user_id_foreign_key.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class UpdateTerraformStatesLockedByUserIdForeignKey < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + OLD_FOREIGN_KEY = 'fk_rails_558901b030' + NEW_FOREIGN_KEY = 'fk_558901b030' + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :terraform_states, :users, + column: :locked_by_user_id, on_delete: :nullify, name: NEW_FOREIGN_KEY + + with_lock_retries do + remove_foreign_key :terraform_states, :users, name: OLD_FOREIGN_KEY + end + end + + def down + add_concurrent_foreign_key :terraform_states, :users, + column: :locked_by_user_id, on_delete: nil, name: OLD_FOREIGN_KEY + + with_lock_retries do + remove_foreign_key :terraform_states, :users, name: NEW_FOREIGN_KEY + end + end +end diff --git a/db/migrate/20210305013509_add_text_limit_to_group_ci_variables_environment_scope.rb b/db/migrate/20210305013509_add_text_limit_to_group_ci_variables_environment_scope.rb new file mode 100644 index 00000000000..f5fa073b954 --- /dev/null +++ b/db/migrate/20210305013509_add_text_limit_to_group_ci_variables_environment_scope.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTextLimitToGroupCiVariablesEnvironmentScope < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :ci_group_variables, :environment_scope, 255 + end + + def down + remove_text_limit :ci_group_variables, :environment_scope + end +end diff --git a/db/migrate/20210305145622_add_terraform_module_max_file_size_to_plan_limits.rb b/db/migrate/20210305145622_add_terraform_module_max_file_size_to_plan_limits.rb new file mode 100644 index 00000000000..d2342a66549 --- /dev/null +++ b/db/migrate/20210305145622_add_terraform_module_max_file_size_to_plan_limits.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddTerraformModuleMaxFileSizeToPlanLimits < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :plan_limits, :terraform_module_max_file_size, :bigint, default: 1.gigabyte, null: false + end +end diff --git a/db/migrate/20210306121300_partition_web_hook_logs.rb b/db/migrate/20210306121300_partition_web_hook_logs.rb new file mode 100644 index 00000000000..ff35a19648e --- /dev/null +++ b/db/migrate/20210306121300_partition_web_hook_logs.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class PartitionWebHookLogs < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + include Gitlab::Database::PartitioningMigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + def up + partition_table_by_date :web_hook_logs, :created_at + end + + def down + drop_partitioned_table_for :web_hook_logs + end +end diff --git a/db/migrate/20210308125742_add_info_column_into_security_scans_table.rb b/db/migrate/20210308125742_add_info_column_into_security_scans_table.rb new file mode 100644 index 00000000000..d701fa98259 --- /dev/null +++ b/db/migrate/20210308125742_add_info_column_into_security_scans_table.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddInfoColumnIntoSecurityScansTable < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :security_scans, :info, :jsonb, null: false, default: {} + end +end diff --git a/db/migrate/20210308190413_change_batched_background_migrations_batch_class_name_default.rb b/db/migrate/20210308190413_change_batched_background_migrations_batch_class_name_default.rb new file mode 100644 index 00000000000..f841c1e9bd5 --- /dev/null +++ b/db/migrate/20210308190413_change_batched_background_migrations_batch_class_name_default.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class ChangeBatchedBackgroundMigrationsBatchClassNameDefault < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + change_column_default :batched_background_migrations, :batch_class_name, + from: 'Gitlab::Database::BackgroundMigration::PrimaryKeyBatchingStrategy', to: 'PrimaryKeyBatchingStrategy' + end +end diff --git a/db/migrate/20210309181019_add_last_used_at_to_cluster_agent_token.rb b/db/migrate/20210309181019_add_last_used_at_to_cluster_agent_token.rb new file mode 100644 index 00000000000..2a29ab374e5 --- /dev/null +++ b/db/migrate/20210309181019_add_last_used_at_to_cluster_agent_token.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddLastUsedAtToClusterAgentToken < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :cluster_agent_tokens, :last_used_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20210310000627_add_idx_vulnerability_occurrences_dedup.rb b/db/migrate/20210310000627_add_idx_vulnerability_occurrences_dedup.rb new file mode 100644 index 00000000000..5ffcc005225 --- /dev/null +++ b/db/migrate/20210310000627_add_idx_vulnerability_occurrences_dedup.rb @@ -0,0 +1,24 @@ +# 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 AddIdxVulnerabilityOccurrencesDedup < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + TABLE = :vulnerability_occurrences + INDEX_NAME = 'index_vulnerability_occurrences_deduplication' + COLUMNS = %i[project_id report_type project_fingerprint] + + disable_ddl_transaction! + + def up + add_concurrent_index TABLE, COLUMNS, name: INDEX_NAME + end + + def down + remove_concurrent_index TABLE, COLUMNS, name: INDEX_NAME + end +end diff --git a/db/migrate/20210310111009_add_settings_to_group_merge_request_approval_settings.rb b/db/migrate/20210310111009_add_settings_to_group_merge_request_approval_settings.rb new file mode 100644 index 00000000000..088f400efb9 --- /dev/null +++ b/db/migrate/20210310111009_add_settings_to_group_merge_request_approval_settings.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddSettingsToGroupMergeRequestApprovalSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + change_table(:group_merge_request_approval_settings, bulk: true) do |t| + t.column :allow_committer_approval, :boolean, null: false, default: false + t.column :allow_overrides_to_approver_list_per_merge_request, :boolean, null: false, default: false + t.column :retain_approvals_on_push, :boolean, null: false, default: false + t.column :require_password_to_approve, :boolean, null: false, default: false + end + end +end |