diff options
Diffstat (limited to 'db/migrate')
59 files changed, 847 insertions, 0 deletions
diff --git a/db/migrate/20220824082427_remove_tmp_idx_vulnerability_occurrences_on_id_and_scanner_id.rb b/db/migrate/20220824082427_remove_tmp_idx_vulnerability_occurrences_on_id_and_scanner_id.rb new file mode 100644 index 00000000000..ebb90df569b --- /dev/null +++ b/db/migrate/20220824082427_remove_tmp_idx_vulnerability_occurrences_on_id_and_scanner_id.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveTmpIdxVulnerabilityOccurrencesOnIdAndScannerId < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'tmp_index_vulnerability_occurrences_on_id_and_scanner_id' + REPORT_TYPES = { cluster_image_scanning: 7, generic: 99 }.freeze + CLAUSE = "report_type IN (#{REPORT_TYPES.values.join(',')})" + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end + + def down + add_concurrent_index :vulnerability_occurrences, + [:id, :scanner_id], + where: CLAUSE, + name: INDEX_NAME + end +end diff --git a/db/migrate/20220908150054_add_runner_registration_enabled_to_namespace_settings.rb b/db/migrate/20220908150054_add_runner_registration_enabled_to_namespace_settings.rb new file mode 100644 index 00000000000..7721d0d592c --- /dev/null +++ b/db/migrate/20220908150054_add_runner_registration_enabled_to_namespace_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddRunnerRegistrationEnabledToNamespaceSettings < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :namespace_settings, :runner_registration_enabled, :boolean, default: true + end +end diff --git a/db/migrate/20221026095133_add_status_updated_at_to_container_repository.rb b/db/migrate/20221026095133_add_status_updated_at_to_container_repository.rb new file mode 100644 index 00000000000..caf838e8307 --- /dev/null +++ b/db/migrate/20221026095133_add_status_updated_at_to_container_repository.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddStatusUpdatedAtToContainerRepository < Gitlab::Database::Migration[2.0] + def change + add_column :container_repositories, :status_updated_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20221101174816_create_package_metadata.rb b/db/migrate/20221101174816_create_package_metadata.rb new file mode 100644 index 00000000000..f1456689641 --- /dev/null +++ b/db/migrate/20221101174816_create_package_metadata.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreatePackageMetadata < Gitlab::Database::Migration[2.0] + def change + create_table :pm_packages do |t| + t.integer :purl_type, null: false, limit: 2 + t.text :name, null: false, limit: 255 + t.index [:purl_type, :name], unique: true, name: 'i_pm_packages_purl_type_and_name' + end + end +end diff --git a/db/migrate/20221101194416_create_package_metadata_versions.rb b/db/migrate/20221101194416_create_package_metadata_versions.rb new file mode 100644 index 00000000000..19b86d86de1 --- /dev/null +++ b/db/migrate/20221101194416_create_package_metadata_versions.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreatePackageMetadataVersions < Gitlab::Database::Migration[2.0] + def change + create_table :pm_package_versions do |t| + t.references :pm_package, foreign_key: { to_table: :pm_packages, on_delete: :cascade } + t.text :version, null: false, limit: 255 + t.index [:pm_package_id, :version], unique: true, name: 'i_pm_package_versions_on_package_id_and_version' + end + end +end diff --git a/db/migrate/20221101195309_create_package_metadata_licenses.rb b/db/migrate/20221101195309_create_package_metadata_licenses.rb new file mode 100644 index 00000000000..1fbb0c147bd --- /dev/null +++ b/db/migrate/20221101195309_create_package_metadata_licenses.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class CreatePackageMetadataLicenses < Gitlab::Database::Migration[2.0] + def change + create_table :pm_licenses do |t| + t.text :spdx_identifier, null: false, limit: 50 + t.index [:spdx_identifier], unique: true, name: 'i_pm_licenses_on_spdx_identifier' + end + end +end diff --git a/db/migrate/20221101195543_create_package_metadata_package_version_licenses.rb b/db/migrate/20221101195543_create_package_metadata_package_version_licenses.rb new file mode 100644 index 00000000000..9007f869e1f --- /dev/null +++ b/db/migrate/20221101195543_create_package_metadata_package_version_licenses.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class CreatePackageMetadataPackageVersionLicenses < Gitlab::Database::Migration[2.0] + INDEX_NAME = 'i_pm_package_version_licenses_on_version_and_license_ids' + + def change + create_table :pm_package_version_licenses, primary_key: [:pm_package_version_id, :pm_license_id] do |t| + t.references :pm_package_version, foreign_key: { on_delete: :cascade }, null: false + t.references :pm_license, foreign_key: { on_delete: :cascade }, null: false + end + end +end diff --git a/db/migrate/20221102150737_index_environments_for_name_search_within_folder.rb b/db/migrate/20221102150737_index_environments_for_name_search_within_folder.rb new file mode 100644 index 00000000000..10fd8b33c45 --- /dev/null +++ b/db/migrate/20221102150737_index_environments_for_name_search_within_folder.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class IndexEnvironmentsForNameSearchWithinFolder < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_environments_for_name_search_within_folder' + + def up + add_concurrent_index :environments, + "project_id, lower(ltrim(name, environment_type || '/')) varchar_pattern_ops, state", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :environments, INDEX_NAME + end +end diff --git a/db/migrate/20221102195642_create_dependency_proxy_manifest_states.rb b/db/migrate/20221102195642_create_dependency_proxy_manifest_states.rb new file mode 100644 index 00000000000..e0da92c6c94 --- /dev/null +++ b/db/migrate/20221102195642_create_dependency_proxy_manifest_states.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class CreateDependencyProxyManifestStates < Gitlab::Database::Migration[2.0] + DEPENDENCY_PROXY_MANIFEST_INDEX_NAME = "index_manifest_states_on_dependency_proxy_manifest_id" + VERIFICATION_STATE_INDEX_NAME = "index_manifest_states_on_verification_state" + PENDING_VERIFICATION_INDEX_NAME = "index_manifest_states_pending_verification" + FAILED_VERIFICATION_INDEX_NAME = "index_manifest_states_failed_verification" + NEEDS_VERIFICATION_INDEX_NAME = "index_manifest_states_needs_verification" + + enable_lock_retries! + + def up + create_table :dependency_proxy_manifest_states, id: false do |t| + t.datetime_with_timezone :verification_started_at + t.datetime_with_timezone :verification_retry_at + t.datetime_with_timezone :verified_at + t.references :dependency_proxy_manifest, + primary_key: true, + index: { name: DEPENDENCY_PROXY_MANIFEST_INDEX_NAME }, + default: nil, + foreign_key: { on_delete: :cascade } + t.integer :verification_state, default: 0, limit: 2, null: false + t.integer :verification_retry_count, limit: 2, default: 0, null: false + t.binary :verification_checksum, using: 'verification_checksum::bytea' + t.text :verification_failure, limit: 255 + + t.index :verification_state, name: VERIFICATION_STATE_INDEX_NAME + t.index :verified_at, + where: "(verification_state = 0)", + order: { verified_at: 'ASC NULLS FIRST' }, + name: PENDING_VERIFICATION_INDEX_NAME + t.index :verification_retry_at, + where: "(verification_state = 3)", + order: { verification_retry_at: 'ASC NULLS FIRST' }, + name: FAILED_VERIFICATION_INDEX_NAME + t.index :verification_state, + where: "(verification_state = 0 OR verification_state = 3)", + name: NEEDS_VERIFICATION_INDEX_NAME + end + end + + def down + drop_table :dependency_proxy_manifest_states + end +end diff --git a/db/migrate/20221103205317_create_dast_pre_scan_verification.rb b/db/migrate/20221103205317_create_dast_pre_scan_verification.rb new file mode 100644 index 00000000000..85375be53b5 --- /dev/null +++ b/db/migrate/20221103205317_create_dast_pre_scan_verification.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CreateDastPreScanVerification < Gitlab::Database::Migration[2.0] + def up + create_table :dast_pre_scan_verifications do |t| + t.references :dast_profile, null: false, foreign_key: { on_delete: :cascade }, + index: { name: 'index_dast_pre_scan_verifications_on_dast_profile_id' } + + t.bigint :ci_pipeline_id, null: false + + t.timestamps_with_timezone + + t.integer :status, default: 0, limit: 2, null: false + + t.index :ci_pipeline_id, unique: true, name: :index_dast_pre_scan_verifications_on_ci_pipeline_id + end + end + + def down + drop_table :dast_pre_scan_verifications + end +end diff --git a/db/migrate/20221107013943_add_accepted_reviewers_to_merge_request_predictions.rb b/db/migrate/20221107013943_add_accepted_reviewers_to_merge_request_predictions.rb new file mode 100644 index 00000000000..9876ac3127a --- /dev/null +++ b/db/migrate/20221107013943_add_accepted_reviewers_to_merge_request_predictions.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddAcceptedReviewersToMergeRequestPredictions < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :merge_request_predictions, :accepted_reviewers, :jsonb, null: false, default: {} + end +end diff --git a/db/migrate/20221110080508_add_partition_id_to_ci_unit_test_failures.rb b/db/migrate/20221110080508_add_partition_id_to_ci_unit_test_failures.rb new file mode 100644 index 00000000000..2217048965c --- /dev/null +++ b/db/migrate/20221110080508_add_partition_id_to_ci_unit_test_failures.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiUnitTestFailures < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_unit_test_failures, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110080636_add_partition_id_to_ci_sources_pipelines.rb b/db/migrate/20221110080636_add_partition_id_to_ci_sources_pipelines.rb new file mode 100644 index 00000000000..a76955d8db1 --- /dev/null +++ b/db/migrate/20221110080636_add_partition_id_to_ci_sources_pipelines.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiSourcesPipelines < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_sources_pipelines, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110080748_add_partition_id_to_ci_build_pending_states.rb b/db/migrate/20221110080748_add_partition_id_to_ci_build_pending_states.rb new file mode 100644 index 00000000000..abf14f4ceca --- /dev/null +++ b/db/migrate/20221110080748_add_partition_id_to_ci_build_pending_states.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiBuildPendingStates < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_build_pending_states, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110080822_add_partition_id_to_ci_build_trace_chunks.rb b/db/migrate/20221110080822_add_partition_id_to_ci_build_trace_chunks.rb new file mode 100644 index 00000000000..27a9bbdb896 --- /dev/null +++ b/db/migrate/20221110080822_add_partition_id_to_ci_build_trace_chunks.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiBuildTraceChunks < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_build_trace_chunks, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110080913_add_partition_id_to_ci_build_report_results.rb b/db/migrate/20221110080913_add_partition_id_to_ci_build_report_results.rb new file mode 100644 index 00000000000..b915ac9f907 --- /dev/null +++ b/db/migrate/20221110080913_add_partition_id_to_ci_build_report_results.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiBuildReportResults < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_build_report_results, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110080956_add_partition_id_to_ci_build_needs.rb b/db/migrate/20221110080956_add_partition_id_to_ci_build_needs.rb new file mode 100644 index 00000000000..faa0309f2c1 --- /dev/null +++ b/db/migrate/20221110080956_add_partition_id_to_ci_build_needs.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiBuildNeeds < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_build_needs, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110081037_add_partition_id_to_ci_builds_runner_session.rb b/db/migrate/20221110081037_add_partition_id_to_ci_builds_runner_session.rb new file mode 100644 index 00000000000..e6f5d65c7b1 --- /dev/null +++ b/db/migrate/20221110081037_add_partition_id_to_ci_builds_runner_session.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiBuildsRunnerSession < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_builds_runner_session, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110081115_add_partition_id_to_ci_pending_builds.rb b/db/migrate/20221110081115_add_partition_id_to_ci_pending_builds.rb new file mode 100644 index 00000000000..24435fd7aa9 --- /dev/null +++ b/db/migrate/20221110081115_add_partition_id_to_ci_pending_builds.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiPendingBuilds < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_pending_builds, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110081207_add_partition_id_to_ci_build_trace_metadata.rb b/db/migrate/20221110081207_add_partition_id_to_ci_build_trace_metadata.rb new file mode 100644 index 00000000000..0c4baa2af1e --- /dev/null +++ b/db/migrate/20221110081207_add_partition_id_to_ci_build_trace_metadata.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiBuildTraceMetadata < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_build_trace_metadata, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110081348_add_partition_id_to_ci_running_builds.rb b/db/migrate/20221110081348_add_partition_id_to_ci_running_builds.rb new file mode 100644 index 00000000000..f4d61a93e3e --- /dev/null +++ b/db/migrate/20221110081348_add_partition_id_to_ci_running_builds.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiRunningBuilds < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_running_builds, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110081448_add_partition_id_to_ci_job_variables.rb b/db/migrate/20221110081448_add_partition_id_to_ci_job_variables.rb new file mode 100644 index 00000000000..0e0eadd8f72 --- /dev/null +++ b/db/migrate/20221110081448_add_partition_id_to_ci_job_variables.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiJobVariables < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_job_variables, :partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221110183103_add_dashboard_fields_to_namespace_details.rb b/db/migrate/20221110183103_add_dashboard_fields_to_namespace_details.rb new file mode 100644 index 00000000000..73e8ccbcb51 --- /dev/null +++ b/db/migrate/20221110183103_add_dashboard_fields_to_namespace_details.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddDashboardFieldsToNamespaceDetails < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :namespace_details, :dashboard_notification_at, :datetime_with_timezone + add_column :namespace_details, :dashboard_enforcement_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20221111123146_add_onboarding_in_progress_to_users.rb b/db/migrate/20221111123146_add_onboarding_in_progress_to_users.rb new file mode 100644 index 00000000000..665760347bf --- /dev/null +++ b/db/migrate/20221111123146_add_onboarding_in_progress_to_users.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddOnboardingInProgressToUsers < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + # rubocop:disable Migration/AddColumnsToWideTables + def up + add_column :users, :onboarding_in_progress, :boolean, default: false, null: false + end + + def down + remove_column :users, :onboarding_in_progress + end + # rubocop:enable Migration/AddColumnsToWideTables +end diff --git a/db/migrate/20221111123147_add_onboarding_step_url_to_user_details.rb b/db/migrate/20221111123147_add_onboarding_step_url_to_user_details.rb new file mode 100644 index 00000000000..7b6c035e05a --- /dev/null +++ b/db/migrate/20221111123147_add_onboarding_step_url_to_user_details.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddOnboardingStepUrlToUserDetails < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20221111123148_add_text_limit_to_onboarding_step_url.rb + def up + add_column :user_details, :onboarding_step_url, :text + end + + def down + remove_column :user_details, :onboarding_step_url + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20221111123148_add_text_limit_to_onboarding_step_url.rb b/db/migrate/20221111123148_add_text_limit_to_onboarding_step_url.rb new file mode 100644 index 00000000000..cfd9f004131 --- /dev/null +++ b/db/migrate/20221111123148_add_text_limit_to_onboarding_step_url.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToOnboardingStepUrl < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_text_limit :user_details, :onboarding_step_url, 2000 + end + + def down + remove_text_limit :user_details, :onboarding_step_url + end +end diff --git a/db/migrate/20221111135238_create_dependency_list_exports_table.rb b/db/migrate/20221111135238_create_dependency_list_exports_table.rb new file mode 100644 index 00000000000..d47bd93fff7 --- /dev/null +++ b/db/migrate/20221111135238_create_dependency_list_exports_table.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class CreateDependencyListExportsTable < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + create_table :dependency_list_exports do |t| + t.timestamps_with_timezone null: false + t.bigint :project_id, null: false + t.bigint :user_id + t.integer :file_store + t.integer :status, default: 0, null: false, limit: 2 + t.text :file, limit: 255 + + t.index :user_id + t.index :project_id + end + end + + def down + drop_table :dependency_list_exports + end +end diff --git a/db/migrate/20221111142921_add_hierarchy_restrictions.rb b/db/migrate/20221111142921_add_hierarchy_restrictions.rb new file mode 100644 index 00000000000..dd80de04969 --- /dev/null +++ b/db/migrate/20221111142921_add_hierarchy_restrictions.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddHierarchyRestrictions < Gitlab::Database::Migration[2.0] + UNIQUE_INDEX_NAME = 'index_work_item_hierarchy_restrictions_on_parent_and_child' + + def up + create_table :work_item_hierarchy_restrictions do |t| + t.references :parent_type, index: true, null: false, + foreign_key: { on_delete: :cascade, to_table: :work_item_types } + t.references :child_type, index: true, null: false, + foreign_key: { on_delete: :cascade, to_table: :work_item_types } + t.integer :maximum_depth, limit: 2 + + t.index [:parent_type_id, :child_type_id], unique: true, name: UNIQUE_INDEX_NAME + end + end + + def down + drop_table :work_item_hierarchy_restrictions + end +end diff --git a/db/migrate/20221114131943_add_short_title_to_appearances.rb b/db/migrate/20221114131943_add_short_title_to_appearances.rb new file mode 100644 index 00000000000..6bf5d32f441 --- /dev/null +++ b/db/migrate/20221114131943_add_short_title_to_appearances.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddShortTitleToAppearances < Gitlab::Database::Migration[2.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20221115085813_add_limit_to_appereances_short_title.rb + def change + add_column :appearances, :short_title, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20221114145103_add_last_seat_refresh_at_to_gitlab_subscriptions.rb b/db/migrate/20221114145103_add_last_seat_refresh_at_to_gitlab_subscriptions.rb new file mode 100644 index 00000000000..77d6bb42f02 --- /dev/null +++ b/db/migrate/20221114145103_add_last_seat_refresh_at_to_gitlab_subscriptions.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddLastSeatRefreshAtToGitlabSubscriptions < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + TABLE_NAME = 'gitlab_subscriptions' + COLUMN_NAME = 'last_seat_refresh_at' + + def up + add_column(TABLE_NAME, COLUMN_NAME, :datetime_with_timezone) + end + + def down + remove_column(TABLE_NAME, COLUMN_NAME) + end +end diff --git a/db/migrate/20221114212908_add_debug_trace_to_ci_builds_metadata.rb b/db/migrate/20221114212908_add_debug_trace_to_ci_builds_metadata.rb new file mode 100644 index 00000000000..aee479dfcee --- /dev/null +++ b/db/migrate/20221114212908_add_debug_trace_to_ci_builds_metadata.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddDebugTraceToCiBuildsMetadata < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :p_ci_builds_metadata, :debug_trace_enabled, :boolean, null: false, default: false + end +end diff --git a/db/migrate/20221115085813_add_limit_to_appereances_short_title.rb b/db/migrate/20221115085813_add_limit_to_appereances_short_title.rb new file mode 100644 index 00000000000..d75895216f7 --- /dev/null +++ b/db/migrate/20221115085813_add_limit_to_appereances_short_title.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddLimitToAppereancesShortTitle < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_text_limit :appearances, :short_title, 255 + end + + def down + remove_text_limit :appearances, :short_title + end +end diff --git a/db/migrate/20221116100056_add_foreign_key_to_dependency_list_exports.rb b/db/migrate/20221116100056_add_foreign_key_to_dependency_list_exports.rb new file mode 100644 index 00000000000..1c7df66bd04 --- /dev/null +++ b/db/migrate/20221116100056_add_foreign_key_to_dependency_list_exports.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class AddForeignKeyToDependencyListExports < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key( + :dependency_list_exports, + :users, + column: :user_id, + on_delete: :nullify) + add_concurrent_foreign_key( + :dependency_list_exports, + :projects, + column: :project_id, + on_delete: :cascade) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :dependency_list_exports, column: :user_id + end + with_lock_retries do + remove_foreign_key_if_exists :dependency_list_exports, column: :project_id + end + end +end diff --git a/db/migrate/20221116113323_add_index_on_team_id_and_chat_id.rb b/db/migrate/20221116113323_add_index_on_team_id_and_chat_id.rb new file mode 100644 index 00000000000..7a7bcf48d80 --- /dev/null +++ b/db/migrate/20221116113323_add_index_on_team_id_and_chat_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexOnTeamIdAndChatId < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_chat_names_on_team_id_and_chat_id' + + def up + add_concurrent_index(:chat_names, [:team_id, :chat_id], name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name :chat_names, INDEX_NAME + end +end diff --git a/db/migrate/20221116124821_add_enterprise_boolean_to_bulk_imports.rb b/db/migrate/20221116124821_add_enterprise_boolean_to_bulk_imports.rb new file mode 100644 index 00000000000..69cc39b72f6 --- /dev/null +++ b/db/migrate/20221116124821_add_enterprise_boolean_to_bulk_imports.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddEnterpriseBooleanToBulkImports < Gitlab::Database::Migration[2.0] + def change + add_column :bulk_imports, :source_enterprise, :boolean, default: true, null: false + end +end diff --git a/db/migrate/20221116160204_create_ml_experiment_metadata_and_ml_candidate_metadata.rb b/db/migrate/20221116160204_create_ml_experiment_metadata_and_ml_candidate_metadata.rb new file mode 100644 index 00000000000..288d1e4be98 --- /dev/null +++ b/db/migrate/20221116160204_create_ml_experiment_metadata_and_ml_candidate_metadata.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CreateMlExperimentMetadataAndMlCandidateMetadata < Gitlab::Database::Migration[2.0] + def change + create_table :ml_experiment_metadata do |t| + t.timestamps_with_timezone null: false + t.references :experiment, + foreign_key: { to_table: :ml_experiments, on_delete: :cascade }, + index: false, + null: false + t.text :name, limit: 255, null: false + t.text :value, limit: 5000, null: false + + t.index [:experiment_id, :name], unique: true + end + + create_table :ml_candidate_metadata do |t| + t.timestamps_with_timezone null: false + t.references :candidate, + foreign_key: { to_table: :ml_candidates, on_delete: :cascade }, + index: false, + null: false + t.text :name, limit: 255, null: false, index: true + t.text :value, limit: 5000, null: false + + t.index [:candidate_id, :name], unique: true + end + end +end diff --git a/db/migrate/20221116161126_add_auth_signing_type_to_keys.rb b/db/migrate/20221116161126_add_auth_signing_type_to_keys.rb new file mode 100644 index 00000000000..795074fa0ca --- /dev/null +++ b/db/migrate/20221116161126_add_auth_signing_type_to_keys.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddAuthSigningTypeToKeys < Gitlab::Database::Migration[2.0] + def change + add_column :keys, :usage_type, :integer, limit: 2, null: false, default: 0 + end +end diff --git a/db/migrate/20221121091238_add_work_item_progress.rb b/db/migrate/20221121091238_add_work_item_progress.rb new file mode 100644 index 00000000000..0e306bf7332 --- /dev/null +++ b/db/migrate/20221121091238_add_work_item_progress.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddWorkItemProgress < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + create_table :work_item_progresses, id: false do |t| + t.timestamps_with_timezone null: false + t.references :issue, primary_key: true, index: false, default: nil, + foreign_key: { on_delete: :cascade, to_table: :issues } + t.integer :progress, default: 0, limit: 2, null: false + end + end + + def down + drop_table :work_item_progresses + end +end diff --git a/db/migrate/20221121100431_add_partition_id_to_ci_resources.rb b/db/migrate/20221121100431_add_partition_id_to_ci_resources.rb new file mode 100644 index 00000000000..5b783057b3a --- /dev/null +++ b/db/migrate/20221121100431_add_partition_id_to_ci_resources.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddPartitionIdToCiResources < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column(:ci_resources, :partition_id, :bigint, default: 100, null: false) + end +end diff --git a/db/migrate/20221122141046_add_allow_pipeline_trigger_approve_deployment_to_project_settings.rb b/db/migrate/20221122141046_add_allow_pipeline_trigger_approve_deployment_to_project_settings.rb new file mode 100644 index 00000000000..b9397d80211 --- /dev/null +++ b/db/migrate/20221122141046_add_allow_pipeline_trigger_approve_deployment_to_project_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddAllowPipelineTriggerApproveDeploymentToProjectSettings < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def change + add_column :project_settings, :allow_pipeline_trigger_approve_deployment, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20221122225925_set_email_confirmation_setting_before_removing_send_user_confirmation_email_column.rb b/db/migrate/20221122225925_set_email_confirmation_setting_before_removing_send_user_confirmation_email_column.rb new file mode 100644 index 00000000000..f92704ac212 --- /dev/null +++ b/db/migrate/20221122225925_set_email_confirmation_setting_before_removing_send_user_confirmation_email_column.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class SetEmailConfirmationSettingBeforeRemovingSendUserConfirmationEmailColumn < Gitlab::Database::Migration[2.0] + restrict_gitlab_migration gitlab_schema: :gitlab_main + + class ApplicationSetting < MigrationRecord + self.table_name = 'application_settings' + end + + def up + return unless ApplicationSetting.exists? + return unless ApplicationSetting.last.send_user_confirmation_email + + ApplicationSetting.last.update(email_confirmation_setting: 2) + end + + def down + return unless ApplicationSetting.exists? + + ApplicationSetting.last.update(email_confirmation_setting: 0) + end +end diff --git a/db/migrate/20221124113925_add_pipeline_hierarchy_size_to_plan_limits.rb b/db/migrate/20221124113925_add_pipeline_hierarchy_size_to_plan_limits.rb new file mode 100644 index 00000000000..f96097febe5 --- /dev/null +++ b/db/migrate/20221124113925_add_pipeline_hierarchy_size_to_plan_limits.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPipelineHierarchySizeToPlanLimits < Gitlab::Database::Migration[2.1] + def change + add_column(:plan_limits, :pipeline_hierarchy_size, :integer, default: 1000, null: false) + end +end diff --git a/db/migrate/20221128123514_add_source_partition_id_to_ci_sources_pipeline.rb b/db/migrate/20221128123514_add_source_partition_id_to_ci_sources_pipeline.rb new file mode 100644 index 00000000000..a98cdbf88de --- /dev/null +++ b/db/migrate/20221128123514_add_source_partition_id_to_ci_sources_pipeline.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddSourcePartitionIdToCiSourcesPipeline < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :ci_sources_pipelines, :source_partition_id, :bigint, default: 100, null: false + end +end diff --git a/db/migrate/20221129192619_increase_self_hosted_attachment_size_limit.rb b/db/migrate/20221129192619_increase_self_hosted_attachment_size_limit.rb new file mode 100644 index 00000000000..ec938afc7ba --- /dev/null +++ b/db/migrate/20221129192619_increase_self_hosted_attachment_size_limit.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class IncreaseSelfHostedAttachmentSizeLimit < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def up + change_column_default :application_settings, :max_attachment_size, from: 10, to: 100 + end + + def down + change_column_default :application_settings, :max_attachment_size, from: 100, to: 10 + end +end diff --git a/db/migrate/20221130170433_create_dast_pre_scan_verification_step.rb b/db/migrate/20221130170433_create_dast_pre_scan_verification_step.rb new file mode 100644 index 00000000000..f0b88ab1c4d --- /dev/null +++ b/db/migrate/20221130170433_create_dast_pre_scan_verification_step.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateDastPreScanVerificationStep < Gitlab::Database::Migration[2.1] + def up + create_table :dast_pre_scan_verification_steps do |t| + t.references :dast_pre_scan_verification, + null: false, foreign_key: { on_delete: :cascade }, + index: { name: 'i_dast_pre_scan_verification_steps_on_pre_scan_verification_id' } + t.timestamps_with_timezone + t.text :name, limit: 255 + t.text :verification_errors, array: true, default: [], null: false + end + end + + def down + drop_table :dast_pre_scan_verification_steps + end +end diff --git a/db/migrate/20221130182056_add_plan_limits_max_size_to_requirements_v2_artifact.rb b/db/migrate/20221130182056_add_plan_limits_max_size_to_requirements_v2_artifact.rb new file mode 100644 index 00000000000..48d53d69898 --- /dev/null +++ b/db/migrate/20221130182056_add_plan_limits_max_size_to_requirements_v2_artifact.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPlanLimitsMaxSizeToRequirementsV2Artifact < Gitlab::Database::Migration[2.0] + def change + add_column :plan_limits, :ci_max_artifact_size_requirements_v2, :integer, null: false, default: 0 + end +end diff --git a/db/migrate/20221202144210_create_achievements.rb b/db/migrate/20221202144210_create_achievements.rb new file mode 100644 index 00000000000..30b2fd528ee --- /dev/null +++ b/db/migrate/20221202144210_create_achievements.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CreateAchievements < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def up + create_table :achievements do |t| + t.references :namespace, + null: false, + index: false, + foreign_key: { on_delete: :cascade } + t.timestamps_with_timezone null: false + t.text :name, null: false, limit: 255 + t.text :avatar, limit: 255 + t.text :description, limit: 1024 + t.boolean :revokeable, default: false, null: false + t.index 'namespace_id, LOWER(name)', unique: true + end + end + + def down + drop_table :achievements + end +end diff --git a/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb b/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb new file mode 100644 index 00000000000..81a636739b4 --- /dev/null +++ b/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +class RemoveIndexICiJobTokenProjectScopeLinksOnSourceAndTargetProject < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + TABLE_NAME = 'ci_job_token_project_scope_links' + OLD_INDEX_NAME = 'i_ci_job_token_project_scope_links_on_source_and_target_project' + NEW_INDEX_NAME = 'ci_job_token_scope_links_source_and_target_project_direction' + NEW_INDEX_COL = %w[source_project_id target_project_id direction] + + def up + add_concurrent_index( + TABLE_NAME, + NEW_INDEX_COL, + name: NEW_INDEX_NAME, + unique: true + ) + remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME) + end + + def down + # noop: as we can have duplicate records once the unique index is removed + end +end diff --git a/db/migrate/20221205061134_add_disable_pats_to_application_settings.rb b/db/migrate/20221205061134_add_disable_pats_to_application_settings.rb new file mode 100644 index 00000000000..0f2438f3e78 --- /dev/null +++ b/db/migrate/20221205061134_add_disable_pats_to_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDisablePatsToApplicationSettings < Gitlab::Database::Migration[2.0] + def change + add_column(:application_settings, :disable_personal_access_tokens, :boolean, default: false, null: false) + end +end diff --git a/db/migrate/20221206163420_add_use_new_navigation_to_user_preferences.rb b/db/migrate/20221206163420_add_use_new_navigation_to_user_preferences.rb new file mode 100644 index 00000000000..72531e8c067 --- /dev/null +++ b/db/migrate/20221206163420_add_use_new_navigation_to_user_preferences.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddUseNewNavigationToUserPreferences < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def change + add_column :user_preferences, :use_new_navigation, :boolean, default: nil, null: true + end +end diff --git a/db/migrate/20221206211814_add_authorized_scopes_to_slack_integration.rb b/db/migrate/20221206211814_add_authorized_scopes_to_slack_integration.rb new file mode 100644 index 00000000000..40abf087dfe --- /dev/null +++ b/db/migrate/20221206211814_add_authorized_scopes_to_slack_integration.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class AddAuthorizedScopesToSlackIntegration < Gitlab::Database::Migration[2.1] + def up + create_table :slack_api_scopes do |t| + t.text :name, null: false, limit: 100 + + t.index :name, name: 'index_slack_api_scopes_on_name', unique: true + end + + create_table :slack_integrations_scopes do |t| + references :slack_api_scope, + null: false, + index: false, # See composite index + foreign_key: { + to_table: :slack_api_scopes, + on_delete: :cascade + } + + references :slack_integration, + null: false, + index: false, # see composite index + foreign_key: { + to_table: :slack_integrations, + on_delete: :cascade + } + + t.index [:slack_integration_id, :slack_api_scope_id], + unique: true, + name: 'index_slack_api_scopes_on_name_and_integration' + end + end + + def down + drop_table :slack_integrations_scopes, if_exists: true + drop_table :slack_api_scopes, if_exists: true + end +end diff --git a/db/migrate/20221206222032_add_read_code_to_member_roles.rb b/db/migrate/20221206222032_add_read_code_to_member_roles.rb new file mode 100644 index 00000000000..dc62672ccd0 --- /dev/null +++ b/db/migrate/20221206222032_add_read_code_to_member_roles.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddReadCodeToMemberRoles < Gitlab::Database::Migration[2.1] + def change + add_column :member_roles, :read_code, :boolean, default: false + end +end diff --git a/db/migrate/20221206235208_add_max_terraform_state_size_bytes_to_application_settings.rb b/db/migrate/20221206235208_add_max_terraform_state_size_bytes_to_application_settings.rb new file mode 100644 index 00000000000..28bfce8ac0b --- /dev/null +++ b/db/migrate/20221206235208_add_max_terraform_state_size_bytes_to_application_settings.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddMaxTerraformStateSizeBytesToApplicationSettings < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + CONSTRAINT_NAME = "app_settings_max_terraform_state_size_bytes_check" + + def up + add_column( + :application_settings, + :max_terraform_state_size_bytes, + :integer, + null: false, + default: 0, + if_not_exists: true + ) + + add_check_constraint :application_settings, "max_terraform_state_size_bytes >= 0", CONSTRAINT_NAME + end + + def down + remove_column :application_settings, :max_terraform_state_size_bytes, if_exists: true + end +end diff --git a/db/migrate/20221207140259_add_bulk_import_enabled_to_application_settings.rb b/db/migrate/20221207140259_add_bulk_import_enabled_to_application_settings.rb new file mode 100644 index 00000000000..c6702559da1 --- /dev/null +++ b/db/migrate/20221207140259_add_bulk_import_enabled_to_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddBulkImportEnabledToApplicationSettings < Gitlab::Database::Migration[2.1] + def change + add_column :application_settings, :bulk_import_enabled, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20221207220120_create_dast_scanner_profiles_runner_tags.rb b/db/migrate/20221207220120_create_dast_scanner_profiles_runner_tags.rb new file mode 100644 index 00000000000..f07cebb6b2c --- /dev/null +++ b/db/migrate/20221207220120_create_dast_scanner_profiles_runner_tags.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateDastScannerProfilesRunnerTags < Gitlab::Database::Migration[2.1] + def up + create_table :dast_scanner_profiles_tags do |t| + t.references :dast_scanner_profile, null: false, foreign_key: { on_delete: :cascade }, + index: { name: 'i_dast_scanner_profiles_tags_on_scanner_profiles_id' } + + t.bigint :tag_id, null: false + + t.index :tag_id, name: :index_dast_scanner_profiles_tags_on_tag_id + end + end + + def down + drop_table :dast_scanner_profiles_tags + end +end diff --git a/db/migrate/20221208122921_remove_constraints_from_ci_resources_for_partition_id.rb b/db/migrate/20221208122921_remove_constraints_from_ci_resources_for_partition_id.rb new file mode 100644 index 00000000000..ffdd744b05c --- /dev/null +++ b/db/migrate/20221208122921_remove_constraints_from_ci_resources_for_partition_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class RemoveConstraintsFromCiResourcesForPartitionId < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def up + change_column_null :ci_resources, :partition_id, true + end + + def down + # no-op + # Adding back the not null constraint requires a long exclusive lock. + # Also depending on when it gets called, it might not even be possible to + # execute because the application could have inserted null values. + end +end diff --git a/db/migrate/20221209110934_update_import_sources_on_application_settings.rb b/db/migrate/20221209110934_update_import_sources_on_application_settings.rb new file mode 100644 index 00000000000..59955d30544 --- /dev/null +++ b/db/migrate/20221209110934_update_import_sources_on_application_settings.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class UpdateImportSourcesOnApplicationSettings < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + class ApplicationSetting < MigrationRecord + end + + def up + return if import_sources.empty? + + new_sources = import_sources - ['google_code'] + ApplicationSetting.update_all(import_sources: new_sources.to_yaml) + end + + def down + ## a reversion is not needed as google_code is no longer a supported import source + # and attempting to save it as one will result in a ActiveRecord error. + end + + def import_sources + ## the last ApplicationSetting record is used to determine application settings + import_sources = ApplicationSetting.last&.import_sources + import_sources.nil? ? [] : YAML.safe_load(import_sources) + end +end diff --git a/db/migrate/20221209110935_fix_update_import_sources_on_application_settings.rb b/db/migrate/20221209110935_fix_update_import_sources_on_application_settings.rb new file mode 100644 index 00000000000..d3123113e82 --- /dev/null +++ b/db/migrate/20221209110935_fix_update_import_sources_on_application_settings.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# This fixes 20221209110934_update_import_sources_on_application_settings.rb, which +# previously serialized a YAML column into a string. +class FixUpdateImportSourcesOnApplicationSettings < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + class ApplicationSetting < MigrationRecord + end + + def up + sources = ApplicationSetting.last&.import_sources + + return unless sources.is_a?(String) + return if sources.start_with?('---') + + sources = YAML.safe_load(sources) + + ApplicationSetting.update_all(import_sources: sources.to_yaml) + end + + def down; end +end diff --git a/db/migrate/20221213184314_change_enabled_default_in_dependency_proxy_group_settings.rb b/db/migrate/20221213184314_change_enabled_default_in_dependency_proxy_group_settings.rb new file mode 100644 index 00000000000..6cddcb80949 --- /dev/null +++ b/db/migrate/20221213184314_change_enabled_default_in_dependency_proxy_group_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ChangeEnabledDefaultInDependencyProxyGroupSettings < Gitlab::Database::Migration[2.0] + def change + change_column_default :dependency_proxy_group_settings, :enabled, from: false, to: true + end +end |