Commit 4fa40777 authored by dfrazao-gitlab's avatar dfrazao-gitlab

Remove old migrations

- Remove Gitlab v13 regular and post migrations
- Rename schema version of init migration

Changelog: performance

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/331248
parent b4c272ca
......@@ -346,7 +346,7 @@ rspec fast_spec_helper minimal:
db:rollback:
extends: .db-job-base
script:
- scripts/db_tasks db:migrate VERSION=20181228175414
- scripts/db_tasks db:migrate VERSION=20210301200959
- scripts/db_tasks db:migrate SKIP_SCHEMA_VERSION_CHECK=true
db:rollback decomposed:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
# frozen_string_literal: true
class AddBloatEstimateToReindexAction < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :postgres_reindex_actions, :bloat_estimate_bytes_start, :bigint
end
end
# frozen_string_literal: true
class ChangeMrAllowMaintainerToPushDefault < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
change_column_default :merge_requests, :allow_maintainer_to_push, from: nil, to: true
end
end
def down
with_lock_retries do
change_column_default :merge_requests, :allow_maintainer_to_push, from: true, to: nil
end
end
end
# frozen_string_literal: true
class AddHasExternalWikiTrigger < ActiveRecord::Migration[6.0]
include Gitlab::Database::SchemaHelpers
DOWNTIME = false
FUNCTION_NAME = 'set_has_external_wiki'
TRIGGER_ON_INSERT_NAME = 'trigger_has_external_wiki_on_insert'
TRIGGER_ON_UPDATE_NAME = 'trigger_has_external_wiki_on_update'
TRIGGER_ON_DELETE_NAME = 'trigger_has_external_wiki_on_delete'
def up
create_trigger_function(FUNCTION_NAME, replace: true) do
<<~SQL
UPDATE projects SET has_external_wiki = COALESCE(NEW.active, FALSE)
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.active = TRUE AND NEW.type = 'ExternalWikiService' 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.type = 'ExternalWikiService' 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.type = 'ExternalWikiService' 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
# frozen_string_literal: true
class AddExpirationPolicyCompletedAtToContainerRepositories < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
add_column(:container_repositories, :expiration_policy_completed_at, :datetime_with_timezone)
end
def down
remove_column(:container_repositories, :expiration_policy_completed_at)
end
end
# frozen_string_literal: true
class AddContainerRegistryCleanupTagsServiceMaxListSizeToApplicationSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column(:application_settings, :container_registry_cleanup_tags_service_max_list_size, :integer, default: 200, null: false)
end
end
# frozen_string_literal: true
class AddAppSettingsContainerRegCleanupTagsServiceMaxListSizeConstraint < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'app_settings_container_reg_cleanup_tags_max_list_size_positive'
disable_ddl_transaction!
def up
add_check_constraint :application_settings, 'container_registry_cleanup_tags_service_max_list_size >= 0', CONSTRAINT_NAME
end
def down
remove_check_constraint :application_settings, CONSTRAINT_NAME
end
end
# frozen_string_literal: true
class AddCustomMappingColumnsToHttpIntegrations < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :alert_management_http_integrations, :payload_example, :jsonb, null: false, default: {}
add_column :alert_management_http_integrations, :payload_attribute_mapping, :jsonb, null: false, default: {}
end
end
# frozen_string_literal: true
class AddEpicBoardList < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
unless table_exists?(:boards_epic_lists)
with_lock_retries do
create_table :boards_epic_lists do |t|
t.timestamps_with_timezone
t.references :epic_board, index: true, foreign_key: { to_table: :boards_epic_boards, on_delete: :cascade }, null: false
t.references :label, index: true, foreign_key: { on_delete: :cascade }
t.integer :position
t.integer :list_type, default: 1, limit: 2, null: false
t.index [:epic_board_id, :label_id], unique: true, where: 'list_type = 1', name: 'index_boards_epic_lists_on_epic_board_id_and_label_id'
end
end
end
add_check_constraint :boards_epic_lists, '(list_type <> 1) OR ("position" IS NOT NULL AND "position" >= 0)', 'boards_epic_lists_position_constraint'
end
def down
with_lock_retries do
drop_table :boards_epic_lists
end
end
end
# frozen_string_literal: true
class DeleteMockDeploymentServiceRecords < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
if Rails.env.development?
execute("DELETE FROM services WHERE type = 'MockDeploymentService'")
end
end
def down
# no-op
end
end
# frozen_string_literal: true
class ChangeUniqueIndexOnSecurityFindings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
OLD_INDEX_NAME = 'index_security_findings_on_uuid'
NEW_INDEX_NAME = 'index_security_findings_on_uuid_and_scan_id'
disable_ddl_transaction!
class SecurityFinding < ActiveRecord::Base
include EachBatch
self.table_name = 'security_findings'
end
def up
add_concurrent_index :security_findings, [:uuid, :scan_id], unique: true, name: NEW_INDEX_NAME
remove_concurrent_index_by_name :security_findings, OLD_INDEX_NAME
end
def down
# It is very unlikely that we rollback this migration but just in case if we have to,
# we have to clear the table because there can be multiple records with the same UUID
# which would break the creation of unique index on the `uuid` column.
# We choose clearing the table because just removing the duplicated records would
# cause data inconsistencies.
SecurityFinding.each_batch(of: 10000) { |relation| relation.delete_all }
add_concurrent_index :security_findings, :uuid, unique: true, name: OLD_INDEX_NAME
remove_concurrent_index_by_name :security_findings, NEW_INDEX_NAME
end
end
# frozen_string_literal: true
class CreateNamespacePackageSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
with_lock_retries do
create_table :namespace_package_settings, if_not_exists: true, id: false do |t|
t.references :namespace, primary_key: true, index: false, default: nil, foreign_key: { to_table: :namespaces, on_delete: :cascade }, type: :bigint
t.boolean :maven_duplicates_allowed, null: false, default: true
t.text :maven_duplicate_exception_regex, null: false, default: ''
end
end
add_text_limit :namespace_package_settings, :maven_duplicate_exception_regex, 255
end
def down
drop_table :namespace_package_settings
end
end
# frozen_string_literal: true
class AddSquashCommitShaIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = "index_merge_requests_on_target_project_id_and_squash_commit_sha"
disable_ddl_transaction!
def up
add_concurrent_index :merge_requests,
[:target_project_id, :squash_commit_sha],
name: INDEX_NAME
end
def down
remove_concurrent_index :merge_requests,
[:target_project_id, :squash_commit_sha],
name: INDEX_NAME
end
end
# frozen_string_literal: true
class AddDevopsAdoptionSnapshotRangeEnd < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :analytics_devops_adoption_snapshots, :end_time, :datetime_with_timezone
end
end
# frozen_string_literal: true
class AddGroupMergeRequestApprovalSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
create_table :group_merge_request_approval_settings, id: false do |t|
t.timestamps_with_timezone null: false
t.references :group, references: :namespaces, primary_key: true, default: nil, index: false,
foreign_key: { to_table: :namespaces, on_delete: :cascade }
t.boolean :allow_author_approval, null: false, default: false
end
end
end
def down
with_lock_retries do
drop_table :group_merge_request_approval_settings
end
end
end
# frozen_string_literal: true
class ChangePagesDeploymentSizeToBigint < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
change_column_type_concurrently :pages_deployments, :size, :bigint
end
def down
undo_change_column_type_concurrently :pages_deployments, :size
end
end
# frozen_string_literal: true
class CreateElasticReindexingSubtasks < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
class ReindexingTask < ActiveRecord::Base
self.table_name = 'elastic_reindexing_tasks'
end
class ReindexingSubtask < ActiveRecord::Base
self.table_name = 'elastic_reindexing_subtasks'
end
def up
unless table_exists?(:elastic_reindexing_subtasks)
create_table :elastic_reindexing_subtasks do |t|
t.references :elastic_reindexing_task, foreign_key: { on_delete: :cascade }, null: false
t.text :alias_name, null: false
t.text :index_name_from, null: false
t.text :index_name_to, null: false
t.text :elastic_task, null: false
t.integer :documents_count_target
t.integer :documents_count
t.timestamps_with_timezone null: false
end
end
add_text_limit :elastic_reindexing_subtasks, :index_name_from, 255
add_text_limit :elastic_reindexing_subtasks, :index_name_to, 255
add_text_limit :elastic_reindexing_subtasks, :elastic_task, 255
add_text_limit :elastic_reindexing_subtasks, :alias_name, 255
ReindexingTask.find_each do |task|
next if task.index_name_from.blank? || task.index_name_to.blank? || task.elastic_task.blank?
next if ReindexingSubtask.where(elastic_reindexing_task_id: task.id).exists?
ReindexingSubtask.create(
elastic_reindexing_task_id: task.id,
documents_count_target: task.documents_count_target,
documents_count: task.documents_count,
alias_name: 'gitlab-production',
index_name_from: task.index_name_from,
index_name_to: task.index_name_to,
elastic_task: task.elastic_task
)
end
end
def down
drop_table :elastic_reindexing_subtasks
end
end
# frozen_string_literal: true
class CreateAdminNotes < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
create_table_with_constraints :namespace_admin_notes do |t|
t.timestamps_with_timezone
t.references :namespace, null: false, foreign_key: { on_delete: :cascade }
t.text :note
t.text_limit :note, 1000
end
end
def down
drop_table :namespace_admin_notes
end
end
# frozen_string_literal: true
class AddDevopsSnapshotIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX_NAME = 'index_on_snapshots_segment_id_end_time'
def up
add_concurrent_index :analytics_devops_adoption_snapshots, [:segment_id, :end_time], name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :analytics_devops_adoption_snapshots, INDEX_NAME
end
end
# frozen_string_literal: true
class ChangeClustersHelmMajorVersionDefaultTo3 < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
change_column_default(:clusters, :helm_major_version, from: 2, to: 3)
end
end
# frozen_string_literal: true
class AddServiceDeskReplyToIsNotNullIndexOnIssues < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
# no-op, the migration's version number was lowered to be executed earlier than db/post_migrate/20201128210234_schedule_populate_issue_email_participants.rb
#
# The new migration is located here: db/migrate/20201128210000_add_service_desk_reply_to_is_not_null_index_on_issues_fix.rb
end
end
# frozen_string_literal: true
class UpdateTrustedAppsToConfidential < 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
add_concurrent_index :oauth_applications, :id, where: 'trusted = true', name: INDEX_NAME
execute('UPDATE oauth_applications SET confidential = true WHERE trusted = true')
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
remove_concurrent_index_by_name :oauth_applications, INDEX_NAME
end
end
# frozen_string_literal: true
class AddRestrictUserDefinedVariablesToProjectSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_column :project_ci_cd_settings, :restrict_user_defined_variables, :boolean, default: false, null: false
end
end
def down
with_lock_retries do
remove_column :project_ci_cd_settings, :restrict_user_defined_variables
end
end
end
# frozen_string_literal: true
class MigrateCoverageReportWorker < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
sidekiq_queue_migrate 'ci_pipelines_create_artifact', to: 'ci_pipeline_artifacts_coverage_report' # rubocop:disable Migration/SidekiqQueueMigrate
end
def down
sidekiq_queue_migrate 'ci_pipeline_artifacts_coverage_report', to: 'ci_pipelines_create_artifact' # rubocop:disable Migration/SidekiqQueueMigrate
end
end
# 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
# 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
# frozen_string_literal: true
class AddDismissalReasonIntoVulnerabilityFeedbackTable < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
add_column :vulnerability_feedback, :dismissal_reason, :smallint
end
def down
remove_column :vulnerability_feedback, :dismissal_reason
end
end
# frozen_string_literal: true
class AddInvisibleCaptchaEnabledToSettings < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :application_settings, :invisible_captcha_enabled, :boolean, null: false, default: false
end
end
# frozen_string_literal: true
class AddRateLimitingResponseTextToApplicationSettings < ActiveRecord::Migration[6.0]
DOWNTIME = false
# rubocop:disable Migration/AddLimitToTextColumns
# limit is added in 20210101110640_set_limit_for_rate_limiting_response_text
def change
add_column :application_settings, :rate_limiting_response_text, :text
end
# rubocop:enable Migration/AddLimitToTextColumns
end
# frozen_string_literal: true
class CreateOnboardingProgress < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
create_table :onboarding_progresses do |t|
t.references :namespace, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
t.timestamps_with_timezone null: false
t.datetime_with_timezone :git_pull_at
t.datetime_with_timezone :git_write_at
t.datetime_with_timezone :merge_request_created_at
t.datetime_with_timezone :pipeline_created_at
t.datetime_with_timezone :user_added_at
t.datetime_with_timezone :trial_started_at
t.datetime_with_timezone :subscription_created_at
t.datetime_with_timezone :required_mr_approvals_enabled_at
t.datetime_with_timezone :code_owners_enabled_at
t.datetime_with_timezone :scoped_label_created_at
t.datetime_with_timezone :security_scan_enabled_at
t.datetime_with_timezone :issue_auto_closed_at
t.datetime_with_timezone :repository_imported_at
t.datetime_with_timezone :repository_mirrored_at
end
end
end
def down
with_lock_retries do
drop_table :onboarding_progresses
end
end
end
# frozen_string_literal: true
class SetLimitForRateLimitingResponseText < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_text_limit :application_settings, :rate_limiting_response_text, 255
end
def down
remove_text_limit :application_settings, :rate_limiting_response_text
end
end
# frozen_string_literal: true
class DropTemporaryIndexOnCiBuilds < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX = 'tmp_build_stage_position_index'
def up
remove_concurrent_index_by_name :ci_builds, INDEX
end
def down
add_concurrent_index :ci_builds, [:stage_id, :stage_idx], where: 'stage_idx IS NOT NULL', name: INDEX
end
end
# frozen_string_literal: true
class AddEpicBoardPositionIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_boards_epic_board_positions_on_scoped_relative_position'
disable_ddl_transaction!
def up
add_concurrent_index :boards_epic_board_positions, [:epic_board_id, :epic_id, :relative_position], name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :boards_epic_board_positions, INDEX_NAME
end
end
# 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
# 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
# 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
# frozen_string_literal: true
class AddUniqueIndexForGolangPackages < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_packages_on_project_id_name_version_unique_when_golang'
PACKAGE_TYPE_GOLANG = 8
disable_ddl_transaction!
def up
add_concurrent_index :packages_packages, [:project_id, :name, :version], unique: true, where: "package_type = #{PACKAGE_TYPE_GOLANG}", name: INDEX_NAME
end
def down
remove_concurrent_index_by_name(:packages_packages, INDEX_NAME)
end
end
# frozen_string_literal: true
class DropTmpIndexOnEmails < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
EMAIL_INDEX_NAME = 'tmp_index_for_email_unconfirmation_migration'
disable_ddl_transaction!
def up
Gitlab::BackgroundMigration.steal('WrongfullyConfirmedEmailUnconfirmer')
remove_concurrent_index_by_name(:emails, EMAIL_INDEX_NAME)
end
def down
add_concurrent_index(:emails, :id, where: 'confirmed_at IS NOT NULL', name: EMAIL_INDEX_NAME)
end
end
# 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
# 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
# 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
# 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
# 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
# frozen_string_literal: true
class UpdateMaxImportSizeDefault < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
change_column_default(:application_settings, :max_import_size, from: 50, to: 0)
end
end
# 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
# 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
# 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
# frozen_string_literal: true
class DropTmpIndexOnEmailsAgain < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
EMAIL_INDEX_NAME = 'tmp_index_for_email_unconfirmation_migration'
disable_ddl_transaction!
def up
remove_concurrent_index_by_name(:emails, EMAIL_INDEX_NAME)
end
def down
add_concurrent_index(:emails, :id, where: 'confirmed_at IS NOT NULL', name: EMAIL_INDEX_NAME)
end
end
# 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
# 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
# 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
# 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
# frozen_string_literal: true
class RemoveGroupIdTitleIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX_NAME = 'index_labels_on_group_id_and_title_with_null_project_id'
LABELS_TABLE = :labels
def up
remove_concurrent_index_by_name LABELS_TABLE, INDEX_NAME
end
def down
add_concurrent_index LABELS_TABLE, [:group_id, :title], where: 'project_id IS NULL', name: INDEX_NAME
end
end
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment