From a7b3560714b4d9cc4ab32dffcd1f74a284b93580 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 18 Feb 2022 09:45:46 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-8-stable-ee --- ...316171009_create_packages_helm_file_metadata.rb | 8 ++- ...354_create_clusters_integration_elasticstack.rb | 8 ++- ...10628154900_create_detached_partitions_table.rb | 8 ++- ...20140841_create_postgres_async_indexes_table.rb | 8 ++- db/migrate/20210729081351_create_topics.rb | 8 ++- ..._unique_index_to_vulnerability_finding_links.rb | 12 ++-- .../20211119111006_create_job_artifact_states.rb | 32 +++++++++ .../20211122103051_add_line_code_to_draft_notes.rb | 10 +++ ...hed_background_migration_job_transition_logs.rb | 38 +++++++++++ ...4095704_add_draft_notes_line_code_text_limit.rb | 13 ++++ ...rification_token_to_external_ae_destinations.rb | 13 ++++ ...insert_or_update_vulnerability_reads_trigger.rb | 58 ++++++++++++++++ ...12043_add_update_vulnerability_reads_trigger.rb | 40 +++++++++++ ..._update_vulnerability_reads_location_trigger.rb | 41 +++++++++++ ...dd_has_issues_on_vulnerability_reads_trigger.rb | 79 ++++++++++++++++++++++ ...111154950_add_token_expires_at_to_ci_runners.rb | 7 ++ ...951_add_index_to_ci_runners_token_expires_at.rb | 15 ++++ ...1_add_text_limit_to_exad_verification_tokens.rb | 13 ++++ ...15633_add_url_text_to_issuable_metric_images.rb | 10 +++ ...add_url_text_limit_to_issuable_metric_images.rb | 13 ++++ ...3_add_unique_index_to_aed_verification_token.rb | 15 ++++ ...ependency_proxy_size_to_namespace_statistics.rb | 7 ++ ...xy_size_to_namespace_root_storage_statistics.rb | 7 ++ ...ulnerability_occurrences_deduplication_index.rb | 20 ++++++ ...9220620_add_scan_method_to_dast_site_profile.rb | 11 +++ ..._create_alert_management_alert_metric_images.rb | 18 +++++ ...er_project_index_to_runner_id_and_project_id.rb | 19 ++++++ ...tempts_to_loose_foreign_keys_deleted_records.rb | 13 ++++ ...122228_add_topics_non_private_projects_count.rb | 11 +++ ..._add_topics_non_private_projects_count_index.rb | 15 ++++ ...dex_on_project_id_and_id_for_vulnerabilities.rb | 15 ++++ ..._sk_key_restrictions_to_application_settings.rb | 10 +++ ...and_import_done_at_to_container_repositories.rb | 14 ++++ ...evel_to_merge_requests_compliance_violations.rb | 7 ++ ...ow_diff_preview_in_email_to_project_settings.rb | 9 +++ ...0_remove_index_for_vulnerability_occurrences.rb | 17 +++++ ...nd_migration_state_to_container_repositories.rb | 16 +++++ ..._migration_indexes_to_container_repositories.rb | 21 ++++++ ...220203123333_add_batched_migration_max_batch.rb | 7 ++ ...source_license_available_to_project_settings.rb | 9 +++ ...n_greatest_done_at_to_container_repositories.rb | 17 +++++ ...users_get_by_id_limit_to_application_setting.rb | 15 ++++ ...not_valid_foreign_key_to_ci_builds_runner_id.rb | 15 ++++ ...ate_default_scan_method_of_dast_site_profile.rb | 24 +++++++ ...rations_trigger_type_new_on_insert_null_safe.rb | 36 ++++++++++ 45 files changed, 789 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20211119111006_create_job_artifact_states.rb create mode 100644 db/migrate/20211122103051_add_line_code_to_draft_notes.rb create mode 100644 db/migrate/20211123135255_create_batched_background_migration_job_transition_logs.rb create mode 100644 db/migrate/20211124095704_add_draft_notes_line_code_text_limit.rb create mode 100644 db/migrate/20220105082217_add_verification_token_to_external_ae_destinations.rb create mode 100644 db/migrate/20220106111958_add_insert_or_update_vulnerability_reads_trigger.rb create mode 100644 db/migrate/20220106112043_add_update_vulnerability_reads_trigger.rb create mode 100644 db/migrate/20220106112085_add_update_vulnerability_reads_location_trigger.rb create mode 100644 db/migrate/20220106163326_add_has_issues_on_vulnerability_reads_trigger.rb create mode 100644 db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb create mode 100644 db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb create mode 100644 db/migrate/20220117082611_add_text_limit_to_exad_verification_tokens.rb create mode 100644 db/migrate/20220118015633_add_url_text_to_issuable_metric_images.rb create mode 100644 db/migrate/20220118020026_add_url_text_limit_to_issuable_metric_images.rb create mode 100644 db/migrate/20220119094023_add_unique_index_to_aed_verification_token.rb create mode 100644 db/migrate/20220119141407_add_dependency_proxy_size_to_namespace_statistics.rb create mode 100644 db/migrate/20220119144253_add_dependency_proxy_size_to_namespace_root_storage_statistics.rb create mode 100644 db/migrate/20220119170426_remove_temporary_vulnerability_occurrences_deduplication_index.rb create mode 100644 db/migrate/20220119220620_add_scan_method_to_dast_site_profile.rb create mode 100644 db/migrate/20220120033115_create_alert_management_alert_metric_images.rb create mode 100644 db/migrate/20220120085655_add_ci_runner_project_index_to_runner_id_and_project_id.rb create mode 100644 db/migrate/20220125084127_add_cleanup_attempts_to_loose_foreign_keys_deleted_records.rb create mode 100644 db/migrate/20220125122228_add_topics_non_private_projects_count.rb create mode 100644 db/migrate/20220125122725_add_topics_non_private_projects_count_index.rb create mode 100644 db/migrate/20220125230538_add_compound_index_on_project_id_and_id_for_vulnerabilities.rb create mode 100644 db/migrate/20220128093756_add_ecdsa_sk_and_ed25519_sk_key_restrictions_to_application_settings.rb create mode 100644 db/migrate/20220128194722_add_index_on_migration_state_and_import_done_at_to_container_repositories.rb create mode 100644 db/migrate/20220131135725_add_severity_level_to_merge_requests_compliance_violations.rb create mode 100644 db/migrate/20220131192643_add_show_diff_preview_in_email_to_project_settings.rb create mode 100644 db/migrate/20220201205300_remove_index_for_vulnerability_occurrences.rb create mode 100644 db/migrate/20220202034409_add_tmp_index_on_id_and_migration_state_to_container_repositories.rb create mode 100644 db/migrate/20220202115350_add_migration_indexes_to_container_repositories.rb create mode 100644 db/migrate/20220203123333_add_batched_migration_max_batch.rb create mode 100644 db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb create mode 100644 db/migrate/20220204154220_add_index_on_greatest_done_at_to_container_repositories.rb create mode 100644 db/migrate/20220207083129_add_users_get_by_id_limit_to_application_setting.rb create mode 100644 db/migrate/20220208170445_add_not_valid_foreign_key_to_ci_builds_runner_id.rb create mode 100644 db/migrate/20220208171826_update_default_scan_method_of_dast_site_profile.rb create mode 100644 db/migrate/20220211214605_update_integrations_trigger_type_new_on_insert_null_safe.rb (limited to 'db/migrate') diff --git a/db/migrate/20210316171009_create_packages_helm_file_metadata.rb b/db/migrate/20210316171009_create_packages_helm_file_metadata.rb index f5a9c5f1146..47a9b808e63 100644 --- a/db/migrate/20210316171009_create_packages_helm_file_metadata.rb +++ b/db/migrate/20210316171009_create_packages_helm_file_metadata.rb @@ -5,7 +5,7 @@ class CreatePackagesHelmFileMetadata < ActiveRecord::Migration[6.0] DOWNTIME = false - def change + def up create_table_with_constraints :packages_helm_file_metadata, id: false do |t| t.timestamps_with_timezone t.references :package_file, primary_key: true, index: false, default: nil, null: false, foreign_key: { to_table: :packages_package_files, on_delete: :cascade }, type: :bigint @@ -17,4 +17,10 @@ class CreatePackagesHelmFileMetadata < ActiveRecord::Migration[6.0] t.index :channel end end + + def down + with_lock_retries do + drop_table :packages_helm_file_metadata + end + end end diff --git a/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb b/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb index 5868325e701..79680821060 100644 --- a/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb +++ b/db/migrate/20210504153354_create_clusters_integration_elasticstack.rb @@ -3,7 +3,7 @@ class CreateClustersIntegrationElasticstack < ActiveRecord::Migration[6.0] include Gitlab::Database::MigrationHelpers - def change + def up create_table_with_constraints :clusters_integration_elasticstack, id: false do |t| t.timestamps_with_timezone null: false t.references :cluster, primary_key: true, default: nil, index: false, foreign_key: { on_delete: :cascade } @@ -12,4 +12,10 @@ class CreateClustersIntegrationElasticstack < ActiveRecord::Migration[6.0] t.text_limit :chart_version, 10 end end + + def down + with_lock_retries do + drop_table :clusters_integration_elasticstack + end + end end diff --git a/db/migrate/20210628154900_create_detached_partitions_table.rb b/db/migrate/20210628154900_create_detached_partitions_table.rb index 05290f4dfb9..cf31d71835a 100644 --- a/db/migrate/20210628154900_create_detached_partitions_table.rb +++ b/db/migrate/20210628154900_create_detached_partitions_table.rb @@ -3,7 +3,7 @@ class CreateDetachedPartitionsTable < ActiveRecord::Migration[6.1] include Gitlab::Database::MigrationHelpers - def change + def up create_table_with_constraints :detached_partitions do |t| t.timestamps_with_timezone null: false t.datetime_with_timezone :drop_after, null: false @@ -14,4 +14,10 @@ class CreateDetachedPartitionsTable < ActiveRecord::Migration[6.1] t.text_limit :table_name, 63 end end + + def down + with_lock_retries do + drop_table :detached_partitions + end + end end diff --git a/db/migrate/20210720140841_create_postgres_async_indexes_table.rb b/db/migrate/20210720140841_create_postgres_async_indexes_table.rb index 707367e5f6c..99025149840 100644 --- a/db/migrate/20210720140841_create_postgres_async_indexes_table.rb +++ b/db/migrate/20210720140841_create_postgres_async_indexes_table.rb @@ -3,7 +3,7 @@ class CreatePostgresAsyncIndexesTable < ActiveRecord::Migration[6.1] include Gitlab::Database::MigrationHelpers - def change + def up create_table_with_constraints :postgres_async_indexes do |t| t.timestamps_with_timezone null: false @@ -18,4 +18,10 @@ class CreatePostgresAsyncIndexesTable < ActiveRecord::Migration[6.1] t.index :name, unique: true end end + + def down + with_lock_retries do + drop_table :postgres_async_indexes + end + end end diff --git a/db/migrate/20210729081351_create_topics.rb b/db/migrate/20210729081351_create_topics.rb index c6fdc6bb98a..13ed2dc7ccc 100644 --- a/db/migrate/20210729081351_create_topics.rb +++ b/db/migrate/20210729081351_create_topics.rb @@ -3,7 +3,7 @@ class CreateTopics < ActiveRecord::Migration[6.1] include Gitlab::Database::MigrationHelpers - def change + def up create_table_with_constraints :topics do |t| t.text :name, null: false t.text_limit :name, 255 @@ -13,4 +13,10 @@ class CreateTopics < ActiveRecord::Migration[6.1] t.timestamps_with_timezone end end + + def down + with_lock_retries do + drop_table :topics + end + end end diff --git a/db/migrate/20210811193033_add_unique_index_to_vulnerability_finding_links.rb b/db/migrate/20210811193033_add_unique_index_to_vulnerability_finding_links.rb index 1bcee89ae57..cf51bca630a 100644 --- a/db/migrate/20210811193033_add_unique_index_to_vulnerability_finding_links.rb +++ b/db/migrate/20210811193033_add_unique_index_to_vulnerability_finding_links.rb @@ -1,18 +1,14 @@ # frozen_string_literal: true class AddUniqueIndexToVulnerabilityFindingLinks < Gitlab::Database::Migration[1.0] - disable_ddl_transaction! - - NAME_URL_INDEX_NAME = 'finding_link_name_url_idx' - URL_INDEX_NAME = 'finding_link_url_idx' + # This migration has been moved to db/post_migrate/20220201193033_add_unique_index_to_vulnerability_finding_links_with_truncate.rb + # Previously, this was causing an bug where there was a conflict between the table cleanup and the index creation. def up - add_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :name, :url], unique: true, name: NAME_URL_INDEX_NAME - add_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :url], unique: true, where: 'name is null', name: URL_INDEX_NAME + # no op end def down - remove_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :name, :url], name: NAME_URL_INDEX_NAME - remove_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :url], name: URL_INDEX_NAME + # no op end end diff --git a/db/migrate/20211119111006_create_job_artifact_states.rb b/db/migrate/20211119111006_create_job_artifact_states.rb new file mode 100644 index 00000000000..44dffed58ee --- /dev/null +++ b/db/migrate/20211119111006_create_job_artifact_states.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class CreateJobArtifactStates < Gitlab::Database::Migration[1.0] + VERIFICATION_STATE_INDEX_NAME = "index_job_artifact_states_on_verification_state" + PENDING_VERIFICATION_INDEX_NAME = "index_job_artifact_states_pending_verification" + FAILED_VERIFICATION_INDEX_NAME = "index_job_artifact_states_failed_verification" + NEEDS_VERIFICATION_INDEX_NAME = "index_job_artifact_states_needs_verification" + + enable_lock_retries! + + def up + create_table :ci_job_artifact_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 :job_artifact, primary_key: true, null: false, foreign_key: { on_delete: :cascade, to_table: :ci_job_artifacts } + t.integer :verification_state, default: 0, limit: 2, null: false + t.integer :verification_retry_count, limit: 2 + 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 :ci_job_artifact_states + end +end diff --git a/db/migrate/20211122103051_add_line_code_to_draft_notes.rb b/db/migrate/20211122103051_add_line_code_to_draft_notes.rb new file mode 100644 index 00000000000..c78b75f3a33 --- /dev/null +++ b/db/migrate/20211122103051_add_line_code_to_draft_notes.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddLineCodeToDraftNotes < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in db/migrate/20211124095704_add_draft_notes_line_code_text_limit.rb + def change + add_column :draft_notes, :line_code, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20211123135255_create_batched_background_migration_job_transition_logs.rb b/db/migrate/20211123135255_create_batched_background_migration_job_transition_logs.rb new file mode 100644 index 00000000000..280626c5d3b --- /dev/null +++ b/db/migrate/20211123135255_create_batched_background_migration_job_transition_logs.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class CreateBatchedBackgroundMigrationJobTransitionLogs < Gitlab::Database::Migration[1.0] + include Gitlab::Database::PartitioningMigrationHelpers + + def up + execute(<<~SQL) + CREATE TABLE batched_background_migration_job_transition_logs ( + id bigserial NOT NULL, + batched_background_migration_job_id bigint NOT NULL, + created_at timestamp with time zone NOT NULL, + updated_at timestamp with time zone NOT NULL, + previous_status smallint NOT NULL, + next_status smallint NOT NULL, + exception_class text, + exception_message text, + CONSTRAINT check_50e580811a CHECK ((char_length(exception_message) <= 1000)), + CONSTRAINT check_76e202c37a CHECK ((char_length(exception_class) <= 100)), + PRIMARY KEY (id, created_at) + ) PARTITION BY RANGE (created_at); + + CREATE INDEX i_batched_background_migration_job_transition_logs_on_job_id + ON batched_background_migration_job_transition_logs USING btree (batched_background_migration_job_id); + + ALTER TABLE batched_background_migration_job_transition_logs ADD CONSTRAINT fk_rails_b7523a175b + FOREIGN KEY (batched_background_migration_job_id) REFERENCES batched_background_migration_jobs(id) ON DELETE CASCADE; + SQL + + min_date = Date.today + max_date = Date.today + 6.months + + create_daterange_partitions('batched_background_migration_job_transition_logs', 'created_at', min_date, max_date) + end + + def down + drop_table :batched_background_migration_job_transition_logs + end +end diff --git a/db/migrate/20211124095704_add_draft_notes_line_code_text_limit.rb b/db/migrate/20211124095704_add_draft_notes_line_code_text_limit.rb new file mode 100644 index 00000000000..b3567d6b873 --- /dev/null +++ b/db/migrate/20211124095704_add_draft_notes_line_code_text_limit.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddDraftNotesLineCodeTextLimit < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :draft_notes, :line_code, 255 + end + + def down + remove_text_limit :draft_notes, :line_code + end +end diff --git a/db/migrate/20220105082217_add_verification_token_to_external_ae_destinations.rb b/db/migrate/20220105082217_add_verification_token_to_external_ae_destinations.rb new file mode 100644 index 00000000000..046a628b8ae --- /dev/null +++ b/db/migrate/20220105082217_add_verification_token_to_external_ae_destinations.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddVerificationTokenToExternalAeDestinations < Gitlab::Database::Migration[1.0] + def up + # rubocop:disable Migration/AddLimitToTextColumns + add_column :audit_events_external_audit_event_destinations, :verification_token, :text + # rubocop:enable Migration/AddLimitToTextColumns + end + + def down + remove_column :audit_events_external_audit_event_destinations, :verification_token + end +end diff --git a/db/migrate/20220106111958_add_insert_or_update_vulnerability_reads_trigger.rb b/db/migrate/20220106111958_add_insert_or_update_vulnerability_reads_trigger.rb new file mode 100644 index 00000000000..0049f4e00a2 --- /dev/null +++ b/db/migrate/20220106111958_add_insert_or_update_vulnerability_reads_trigger.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +class AddInsertOrUpdateVulnerabilityReadsTrigger < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + FUNCTION_NAME = 'insert_or_update_vulnerability_reads' + TRIGGER_NAME = 'trigger_insert_or_update_vulnerability_reads_from_occurrences' + + def up + execute(<<~SQL) + CREATE OR REPLACE FUNCTION #{FUNCTION_NAME}() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ + DECLARE + severity smallint; + state smallint; + report_type smallint; + resolved_on_default_branch boolean; + BEGIN + IF (NEW.vulnerability_id IS NULL AND (TG_OP = 'INSERT' OR TG_OP = 'UPDATE')) THEN + RETURN NULL; + END IF; + + IF (TG_OP = 'UPDATE' AND OLD.vulnerability_id IS NOT NULL AND NEW.vulnerability_id IS NOT NULL) THEN + RETURN NULL; + END IF; + + SELECT + vulnerabilities.severity, vulnerabilities.state, vulnerabilities.report_type, vulnerabilities.resolved_on_default_branch + INTO + severity, state, report_type, resolved_on_default_branch + FROM + vulnerabilities + WHERE + vulnerabilities.id = NEW.vulnerability_id; + + INSERT INTO vulnerability_reads (vulnerability_id, project_id, scanner_id, report_type, severity, state, resolved_on_default_branch, uuid, location_image, cluster_agent_id) + VALUES (NEW.vulnerability_id, NEW.project_id, NEW.scanner_id, report_type, severity, state, resolved_on_default_branch, NEW.uuid::uuid, NEW.location->>'image', NEW.location->'kubernetes_resource'->>'agent_id') + ON CONFLICT(vulnerability_id) DO NOTHING; + RETURN NULL; + END + $$; + SQL + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_NAME} + AFTER INSERT OR UPDATE ON vulnerability_occurrences + FOR EACH ROW + EXECUTE PROCEDURE #{FUNCTION_NAME}(); + SQL + end + + def down + drop_trigger(:vulnerability_occurrences, TRIGGER_NAME) + drop_function(FUNCTION_NAME) + end +end diff --git a/db/migrate/20220106112043_add_update_vulnerability_reads_trigger.rb b/db/migrate/20220106112043_add_update_vulnerability_reads_trigger.rb new file mode 100644 index 00000000000..940ec638924 --- /dev/null +++ b/db/migrate/20220106112043_add_update_vulnerability_reads_trigger.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class AddUpdateVulnerabilityReadsTrigger < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + TRIGGER_NAME = 'trigger_update_vulnerability_reads_on_vulnerability_update' + FUNCTION_NAME = 'update_vulnerability_reads_from_vulnerability' + + def up + create_trigger_function(FUNCTION_NAME, replace: true) do + <<~SQL + UPDATE + vulnerability_reads + SET + severity = NEW.severity, + state = NEW.state, + resolved_on_default_branch = NEW.resolved_on_default_branch + WHERE vulnerability_id = NEW.id; + RETURN NULL; + SQL + end + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_NAME} + AFTER UPDATE ON vulnerabilities + FOR EACH ROW + WHEN ( + OLD.severity IS DISTINCT FROM NEW.severity OR + OLD.state IS DISTINCT FROM NEW.state OR + OLD.resolved_on_default_branch IS DISTINCT FROM NEW.resolved_on_default_branch + ) + EXECUTE PROCEDURE #{FUNCTION_NAME}(); + SQL + end + + def down + drop_trigger(:vulnerabilities, TRIGGER_NAME) + drop_function(FUNCTION_NAME) + end +end diff --git a/db/migrate/20220106112085_add_update_vulnerability_reads_location_trigger.rb b/db/migrate/20220106112085_add_update_vulnerability_reads_location_trigger.rb new file mode 100644 index 00000000000..a863fe8b7b8 --- /dev/null +++ b/db/migrate/20220106112085_add_update_vulnerability_reads_location_trigger.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class AddUpdateVulnerabilityReadsLocationTrigger < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + TRIGGER_NAME = 'trigger_update_location_on_vulnerability_occurrences_update' + FUNCTION_NAME = 'update_location_from_vulnerability_occurrences' + + def up + create_trigger_function(FUNCTION_NAME, replace: true) do + <<~SQL + UPDATE + vulnerability_reads + SET + location_image = NEW.location->>'image', + cluster_agent_id = NEW.location->'kubernetes_resource'->>'agent_id' + WHERE + vulnerability_id = NEW.vulnerability_id; + RETURN NULL; + SQL + end + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_NAME} + AFTER UPDATE ON vulnerability_occurrences + FOR EACH ROW + WHEN ( + NEW.report_type IN (2, 7) AND ( + OLD.location->>'image' IS DISTINCT FROM NEW.location->>'image' OR + OLD.location->'kubernetes_resource'->>'agent_id' IS DISTINCT FROM NEW.location->'kubernetes_resource'->>'agent_id' + ) + ) + EXECUTE PROCEDURE #{FUNCTION_NAME}(); + SQL + end + + def down + drop_trigger(:vulnerability_occurrences, TRIGGER_NAME) + drop_function(FUNCTION_NAME) + end +end diff --git a/db/migrate/20220106163326_add_has_issues_on_vulnerability_reads_trigger.rb b/db/migrate/20220106163326_add_has_issues_on_vulnerability_reads_trigger.rb new file mode 100644 index 00000000000..b3023a1f915 --- /dev/null +++ b/db/migrate/20220106163326_add_has_issues_on_vulnerability_reads_trigger.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +class AddHasIssuesOnVulnerabilityReadsTrigger < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + TRIGGER_ON_INSERT = 'trigger_update_has_issues_on_vulnerability_issue_links_update' + INSERT_FUNCTION_NAME = 'set_has_issues_on_vulnerability_reads' + + TRIGGER_ON_DELETE = 'trigger_update_has_issues_on_vulnerability_issue_links_delete' + DELETE_FUNCTION_NAME = 'unset_has_issues_on_vulnerability_reads' + + def up + create_trigger_function(INSERT_FUNCTION_NAME, replace: true) do + <<~SQL + UPDATE + vulnerability_reads + SET + has_issues = true + WHERE + vulnerability_id = NEW.vulnerability_id AND has_issues IS FALSE; + RETURN NULL; + SQL + end + + execute(<<~SQL) + CREATE OR REPLACE FUNCTION #{DELETE_FUNCTION_NAME}() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ + DECLARE + has_issue_links integer; + BEGIN + PERFORM 1 + FROM + vulnerability_reads + WHERE + vulnerability_id = OLD.vulnerability_id + FOR UPDATE; + + SELECT 1 INTO has_issue_links FROM vulnerability_issue_links WHERE vulnerability_id = OLD.vulnerability_id LIMIT 1; + + IF (has_issue_links = 1) THEN + RETURN NULL; + END IF; + + UPDATE + vulnerability_reads + SET + has_issues = false + WHERE + vulnerability_id = OLD.vulnerability_id; + + RETURN NULL; + END + $$; + SQL + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_ON_INSERT} + AFTER INSERT ON vulnerability_issue_links + FOR EACH ROW + EXECUTE FUNCTION #{INSERT_FUNCTION_NAME}(); + SQL + + execute(<<~SQL) + CREATE TRIGGER #{TRIGGER_ON_DELETE} + AFTER DELETE ON vulnerability_issue_links + FOR EACH ROW + EXECUTE FUNCTION #{DELETE_FUNCTION_NAME}(); + SQL + end + + def down + drop_trigger(:vulnerability_issue_links, TRIGGER_ON_INSERT) + drop_function(INSERT_FUNCTION_NAME) + drop_trigger(:vulnerability_issue_links, TRIGGER_ON_DELETE) + drop_function(DELETE_FUNCTION_NAME) + end +end diff --git a/db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb b/db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb new file mode 100644 index 00000000000..b4d7c63d24b --- /dev/null +++ b/db/migrate/20220111154950_add_token_expires_at_to_ci_runners.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTokenExpiresAtToCiRunners < Gitlab::Database::Migration[1.0] + def change + add_column :ci_runners, :token_expires_at, :datetime_with_timezone + end +end diff --git a/db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb b/db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb new file mode 100644 index 00000000000..53623198f51 --- /dev/null +++ b/db/migrate/20220111154951_add_index_to_ci_runners_token_expires_at.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddIndexToCiRunnersTokenExpiresAt < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_index :ci_runners, [:token_expires_at, :id], order: { token_expires_at: :asc, id: :desc }, name: 'index_ci_runners_on_token_expires_at_and_id_desc' + add_concurrent_index :ci_runners, [:token_expires_at, :id], order: { token_expires_at: :desc, id: :desc }, name: 'index_ci_runners_on_token_expires_at_desc_and_id_desc' + end + + def down + remove_concurrent_index_by_name :ci_runners, 'index_ci_runners_on_token_expires_at_desc_and_id_desc' + remove_concurrent_index_by_name :ci_runners, 'index_ci_runners_on_token_expires_at_and_id_desc' + end +end diff --git a/db/migrate/20220117082611_add_text_limit_to_exad_verification_tokens.rb b/db/migrate/20220117082611_add_text_limit_to_exad_verification_tokens.rb new file mode 100644 index 00000000000..9978e87a1e3 --- /dev/null +++ b/db/migrate/20220117082611_add_text_limit_to_exad_verification_tokens.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToExadVerificationTokens < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :audit_events_external_audit_event_destinations, :verification_token, 24 + end + + def down + remove_text_limit :audit_events_external_audit_event_destinations, :verification_token + end +end diff --git a/db/migrate/20220118015633_add_url_text_to_issuable_metric_images.rb b/db/migrate/20220118015633_add_url_text_to_issuable_metric_images.rb new file mode 100644 index 00000000000..55d820c1256 --- /dev/null +++ b/db/migrate/20220118015633_add_url_text_to_issuable_metric_images.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddUrlTextToIssuableMetricImages < Gitlab::Database::Migration[1.0] + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20220118020026_add_url_text_limit_to_issuable_metric_images + def change + add_column :issuable_metric_images, :url_text, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20220118020026_add_url_text_limit_to_issuable_metric_images.rb b/db/migrate/20220118020026_add_url_text_limit_to_issuable_metric_images.rb new file mode 100644 index 00000000000..2f0f27681cd --- /dev/null +++ b/db/migrate/20220118020026_add_url_text_limit_to_issuable_metric_images.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddUrlTextLimitToIssuableMetricImages < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_text_limit :issuable_metric_images, :url_text, 128 + end + + def down + remove_text_limit :issuable_metric_images, :url_text + end +end diff --git a/db/migrate/20220119094023_add_unique_index_to_aed_verification_token.rb b/db/migrate/20220119094023_add_unique_index_to_aed_verification_token.rb new file mode 100644 index 00000000000..bd40fe2203e --- /dev/null +++ b/db/migrate/20220119094023_add_unique_index_to_aed_verification_token.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUniqueIndexToAedVerificationToken < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + INDEX_NAME = 'index_audit_events_external_audit_on_verification_token' + + def up + add_concurrent_index :audit_events_external_audit_event_destinations, :verification_token, unique: true, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :audit_events_external_audit_event_destinations, INDEX_NAME + end +end diff --git a/db/migrate/20220119141407_add_dependency_proxy_size_to_namespace_statistics.rb b/db/migrate/20220119141407_add_dependency_proxy_size_to_namespace_statistics.rb new file mode 100644 index 00000000000..d8107ad8e21 --- /dev/null +++ b/db/migrate/20220119141407_add_dependency_proxy_size_to_namespace_statistics.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDependencyProxySizeToNamespaceStatistics < Gitlab::Database::Migration[1.0] + def change + add_column :namespace_statistics, :dependency_proxy_size, :bigint, default: 0, null: false + end +end diff --git a/db/migrate/20220119144253_add_dependency_proxy_size_to_namespace_root_storage_statistics.rb b/db/migrate/20220119144253_add_dependency_proxy_size_to_namespace_root_storage_statistics.rb new file mode 100644 index 00000000000..8218f869ce6 --- /dev/null +++ b/db/migrate/20220119144253_add_dependency_proxy_size_to_namespace_root_storage_statistics.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddDependencyProxySizeToNamespaceRootStorageStatistics < Gitlab::Database::Migration[1.0] + def change + add_column :namespace_root_storage_statistics, :dependency_proxy_size, :bigint, default: 0, null: false + end +end diff --git a/db/migrate/20220119170426_remove_temporary_vulnerability_occurrences_deduplication_index.rb b/db/migrate/20220119170426_remove_temporary_vulnerability_occurrences_deduplication_index.rb new file mode 100644 index 00000000000..26859beb671 --- /dev/null +++ b/db/migrate/20220119170426_remove_temporary_vulnerability_occurrences_deduplication_index.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveTemporaryVulnerabilityOccurrencesDeduplicationIndex < Gitlab::Database::Migration[1.0] + MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid' + INDEX_NAME = 'tmp_idx_deduplicate_vulnerability_occurrences' + + disable_ddl_transaction! + + def up + finalize_background_migration(MIGRATION) + + remove_concurrent_index_by_name(:vulnerability_occurrences, INDEX_NAME) + end + + def down + add_concurrent_index :vulnerability_occurrences, + %i[project_id report_type location_fingerprint primary_identifier_id id], + name: INDEX_NAME + end +end diff --git a/db/migrate/20220119220620_add_scan_method_to_dast_site_profile.rb b/db/migrate/20220119220620_add_scan_method_to_dast_site_profile.rb new file mode 100644 index 00000000000..f7b7580d673 --- /dev/null +++ b/db/migrate/20220119220620_add_scan_method_to_dast_site_profile.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddScanMethodToDastSiteProfile < Gitlab::Database::Migration[1.0] + def up + add_column :dast_site_profiles, :scan_method, :integer, limit: 2, default: 0, null: false + end + + def down + remove_column :dast_site_profiles, :scan_method + end +end diff --git a/db/migrate/20220120033115_create_alert_management_alert_metric_images.rb b/db/migrate/20220120033115_create_alert_management_alert_metric_images.rb new file mode 100644 index 00000000000..e98392190f4 --- /dev/null +++ b/db/migrate/20220120033115_create_alert_management_alert_metric_images.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateAlertManagementAlertMetricImages < Gitlab::Database::Migration[1.0] + def up + create_table :alert_management_alert_metric_images do |t| + t.references :alert, null: false, index: true, foreign_key: { to_table: :alert_management_alerts, on_delete: :cascade } + t.timestamps_with_timezone + t.integer :file_store, limit: 2 + t.text :file, limit: 255, null: false + t.text :url, limit: 255 + t.text :url_text, limit: 128 + end + end + + def down + drop_table :alert_management_alert_metric_images, if_exists: true + end +end diff --git a/db/migrate/20220120085655_add_ci_runner_project_index_to_runner_id_and_project_id.rb b/db/migrate/20220120085655_add_ci_runner_project_index_to_runner_id_and_project_id.rb new file mode 100644 index 00000000000..bcf32d2abd0 --- /dev/null +++ b/db/migrate/20220120085655_add_ci_runner_project_index_to_runner_id_and_project_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddCiRunnerProjectIndexToRunnerIdAndProjectId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + OLD_INDEX_NAME = 'index_ci_runner_projects_on_runner_id' + NEW_INDEX_NAME = 'index_ci_runner_projects_on_runner_id_and_project_id' + TABLE_NAME = :ci_runner_projects + + def up + add_concurrent_index(TABLE_NAME, [:runner_id, :project_id], name: NEW_INDEX_NAME) + remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME) + end + + def down + add_concurrent_index(TABLE_NAME, :runner_id, name: OLD_INDEX_NAME) + remove_concurrent_index_by_name(TABLE_NAME, NEW_INDEX_NAME) + end +end diff --git a/db/migrate/20220125084127_add_cleanup_attempts_to_loose_foreign_keys_deleted_records.rb b/db/migrate/20220125084127_add_cleanup_attempts_to_loose_foreign_keys_deleted_records.rb new file mode 100644 index 00000000000..e0c80ad79e5 --- /dev/null +++ b/db/migrate/20220125084127_add_cleanup_attempts_to_loose_foreign_keys_deleted_records.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddCleanupAttemptsToLooseForeignKeysDeletedRecords < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + add_column :loose_foreign_keys_deleted_records, :cleanup_attempts, :smallint, default: 0 + end + + def down + remove_column :loose_foreign_keys_deleted_records, :cleanup_attempts + end +end diff --git a/db/migrate/20220125122228_add_topics_non_private_projects_count.rb b/db/migrate/20220125122228_add_topics_non_private_projects_count.rb new file mode 100644 index 00000000000..8c7b750d5ff --- /dev/null +++ b/db/migrate/20220125122228_add_topics_non_private_projects_count.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddTopicsNonPrivateProjectsCount < Gitlab::Database::Migration[1.0] + def up + add_column :topics, :non_private_projects_count, :bigint, null: false, default: 0 + end + + def down + remove_column :topics, :non_private_projects_count + end +end diff --git a/db/migrate/20220125122725_add_topics_non_private_projects_count_index.rb b/db/migrate/20220125122725_add_topics_non_private_projects_count_index.rb new file mode 100644 index 00000000000..46b4d298a2e --- /dev/null +++ b/db/migrate/20220125122725_add_topics_non_private_projects_count_index.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddTopicsNonPrivateProjectsCountIndex < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_topics_non_private_projects_count' + + disable_ddl_transaction! + + def up + add_concurrent_index :topics, [:non_private_projects_count, :id], order: { non_private_projects_count: :desc }, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :topics, INDEX_NAME + end +end diff --git a/db/migrate/20220125230538_add_compound_index_on_project_id_and_id_for_vulnerabilities.rb b/db/migrate/20220125230538_add_compound_index_on_project_id_and_id_for_vulnerabilities.rb new file mode 100644 index 00000000000..c745fa51328 --- /dev/null +++ b/db/migrate/20220125230538_add_compound_index_on_project_id_and_id_for_vulnerabilities.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddCompoundIndexOnProjectIdAndIdForVulnerabilities < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_vulnerabilities_on_project_id_and_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerabilities, [:project_id, :id], name: INDEX_NAME + end + + def down + remove_concurrent_index :vulnerabilities, [:project_id, :id], name: INDEX_NAME + end +end diff --git a/db/migrate/20220128093756_add_ecdsa_sk_and_ed25519_sk_key_restrictions_to_application_settings.rb b/db/migrate/20220128093756_add_ecdsa_sk_and_ed25519_sk_key_restrictions_to_application_settings.rb new file mode 100644 index 00000000000..1acd9599da4 --- /dev/null +++ b/db/migrate/20220128093756_add_ecdsa_sk_and_ed25519_sk_key_restrictions_to_application_settings.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddEcdsaSkAndEd25519SkKeyRestrictionsToApplicationSettings < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + add_column :application_settings, :ecdsa_sk_key_restriction, :integer, default: 0, null: false + add_column :application_settings, :ed25519_sk_key_restriction, :integer, default: 0, null: false + end +end diff --git a/db/migrate/20220128194722_add_index_on_migration_state_and_import_done_at_to_container_repositories.rb b/db/migrate/20220128194722_add_index_on_migration_state_and_import_done_at_to_container_repositories.rb new file mode 100644 index 00000000000..6c9fb20bbbd --- /dev/null +++ b/db/migrate/20220128194722_add_index_on_migration_state_and_import_done_at_to_container_repositories.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddIndexOnMigrationStateAndImportDoneAtToContainerRepositories < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_container_repositories_on_migration_state_import_done_at' + disable_ddl_transaction! + + def up + add_concurrent_index :container_repositories, [:migration_state, :migration_import_done_at], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :container_repositories, INDEX_NAME + end +end diff --git a/db/migrate/20220131135725_add_severity_level_to_merge_requests_compliance_violations.rb b/db/migrate/20220131135725_add_severity_level_to_merge_requests_compliance_violations.rb new file mode 100644 index 00000000000..50aa0121055 --- /dev/null +++ b/db/migrate/20220131135725_add_severity_level_to_merge_requests_compliance_violations.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddSeverityLevelToMergeRequestsComplianceViolations < Gitlab::Database::Migration[1.0] + def change + add_column :merge_requests_compliance_violations, :severity_level, :integer, limit: 2, null: false, default: 0 + end +end diff --git a/db/migrate/20220131192643_add_show_diff_preview_in_email_to_project_settings.rb b/db/migrate/20220131192643_add_show_diff_preview_in_email_to_project_settings.rb new file mode 100644 index 00000000000..1811bf04ee4 --- /dev/null +++ b/db/migrate/20220131192643_add_show_diff_preview_in_email_to_project_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddShowDiffPreviewInEmailToProjectSettings < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + add_column :project_settings, :show_diff_preview_in_email, :boolean, default: true, null: false + end +end diff --git a/db/migrate/20220201205300_remove_index_for_vulnerability_occurrences.rb b/db/migrate/20220201205300_remove_index_for_vulnerability_occurrences.rb new file mode 100644 index 00000000000..89591d14aae --- /dev/null +++ b/db/migrate/20220201205300_remove_index_for_vulnerability_occurrences.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveIndexForVulnerabilityOccurrences < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_vulnerability_occurrences_on_unique_keys' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end + + def down + # no-op + + # The index is UNIQUE so we cannot add it back again + end +end diff --git a/db/migrate/20220202034409_add_tmp_index_on_id_and_migration_state_to_container_repositories.rb b/db/migrate/20220202034409_add_tmp_index_on_id_and_migration_state_to_container_repositories.rb new file mode 100644 index 00000000000..b999c871a3e --- /dev/null +++ b/db/migrate/20220202034409_add_tmp_index_on_id_and_migration_state_to_container_repositories.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddTmpIndexOnIdAndMigrationStateToContainerRepositories < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'tmp_index_container_repositories_on_id_migration_state' + + disable_ddl_transaction! + + # Temporary index to be removed https://gitlab.com/gitlab-org/gitlab/-/issues/351783 + def up + add_concurrent_index :container_repositories, [:id, :migration_state], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :container_repositories, INDEX_NAME + end +end diff --git a/db/migrate/20220202115350_add_migration_indexes_to_container_repositories.rb b/db/migrate/20220202115350_add_migration_indexes_to_container_repositories.rb new file mode 100644 index 00000000000..673d066e3c0 --- /dev/null +++ b/db/migrate/20220202115350_add_migration_indexes_to_container_repositories.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddMigrationIndexesToContainerRepositories < Gitlab::Database::Migration[1.0] + PRE_IMPORTING_INDEX = 'idx_container_repos_on_pre_import_started_at_when_pre_importing' + PRE_IMPORT_DONE_INDEX = 'idx_container_repos_on_pre_import_done_at_when_pre_import_done' + IMPORTING_INDEX = 'idx_container_repos_on_import_started_at_when_importing' + + disable_ddl_transaction! + + def up + add_concurrent_index :container_repositories, :migration_pre_import_started_at, name: PRE_IMPORTING_INDEX, where: "migration_state = 'pre_importing'" + add_concurrent_index :container_repositories, :migration_pre_import_done_at, name: PRE_IMPORT_DONE_INDEX, where: "migration_state = 'pre_import_done'" + add_concurrent_index :container_repositories, :migration_import_started_at, name: IMPORTING_INDEX, where: "migration_state = 'importing'" + end + + def down + remove_concurrent_index_by_name :container_repositories, IMPORTING_INDEX + remove_concurrent_index_by_name :container_repositories, PRE_IMPORT_DONE_INDEX + remove_concurrent_index_by_name :container_repositories, PRE_IMPORTING_INDEX + end +end diff --git a/db/migrate/20220203123333_add_batched_migration_max_batch.rb b/db/migrate/20220203123333_add_batched_migration_max_batch.rb new file mode 100644 index 00000000000..d16c6dd4110 --- /dev/null +++ b/db/migrate/20220203123333_add_batched_migration_max_batch.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddBatchedMigrationMaxBatch < Gitlab::Database::Migration[1.0] + def change + add_column :batched_background_migrations, :max_batch_size, :integer + end +end diff --git a/db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb b/db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb new file mode 100644 index 00000000000..47f92fae496 --- /dev/null +++ b/db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddLegacyOpenSourceLicenseAvailableToProjectSettings < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + add_column :project_settings, :legacy_open_source_license_available, :boolean, default: true, null: false + end +end diff --git a/db/migrate/20220204154220_add_index_on_greatest_done_at_to_container_repositories.rb b/db/migrate/20220204154220_add_index_on_greatest_done_at_to_container_repositories.rb new file mode 100644 index 00000000000..455a8478cc4 --- /dev/null +++ b/db/migrate/20220204154220_add_index_on_greatest_done_at_to_container_repositories.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexOnGreatestDoneAtToContainerRepositories < Gitlab::Database::Migration[1.0] + INDEX_NAME = 'index_container_repositories_on_greatest_done_at' + disable_ddl_transaction! + + def up + add_concurrent_index :container_repositories, + 'GREATEST(migration_pre_import_done_at, migration_import_done_at, migration_aborted_at)', + where: "migration_state IN ('import_done', 'pre_import_done', 'import_aborted')", + name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :container_repositories, INDEX_NAME + end +end diff --git a/db/migrate/20220207083129_add_users_get_by_id_limit_to_application_setting.rb b/db/migrate/20220207083129_add_users_get_by_id_limit_to_application_setting.rb new file mode 100644 index 00000000000..cdf2aced213 --- /dev/null +++ b/db/migrate/20220207083129_add_users_get_by_id_limit_to_application_setting.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddUsersGetByIdLimitToApplicationSetting < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def up + add_column :application_settings, :users_get_by_id_limit, :integer, null: false, default: 300 + add_column :application_settings, :users_get_by_id_limit_allowlist, :text, array: true, limit: 255, null: false, default: [] + end + + def down + remove_column :application_settings, :users_get_by_id_limit + remove_column :application_settings, :users_get_by_id_limit_allowlist + end +end diff --git a/db/migrate/20220208170445_add_not_valid_foreign_key_to_ci_builds_runner_id.rb b/db/migrate/20220208170445_add_not_valid_foreign_key_to_ci_builds_runner_id.rb new file mode 100644 index 00000000000..9b2ba17e068 --- /dev/null +++ b/db/migrate/20220208170445_add_not_valid_foreign_key_to_ci_builds_runner_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddNotValidForeignKeyToCiBuildsRunnerId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :ci_builds, :ci_runners, column: :runner_id, on_delete: :nullify, validate: false + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :ci_builds, column: :runner_id + end + end +end diff --git a/db/migrate/20220208171826_update_default_scan_method_of_dast_site_profile.rb b/db/migrate/20220208171826_update_default_scan_method_of_dast_site_profile.rb new file mode 100644 index 00000000000..b01dbe642e2 --- /dev/null +++ b/db/migrate/20220208171826_update_default_scan_method_of_dast_site_profile.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class UpdateDefaultScanMethodOfDastSiteProfile < Gitlab::Database::Migration[1.0] + BATCH_SIZE = 500 + + disable_ddl_transaction! + + def up + each_batch_range('dast_site_profiles', scope: ->(table) { table.where(target_type: 1) }, of: BATCH_SIZE) do |min, max| + execute <<~SQL + UPDATE dast_site_profiles + SET scan_method = 1 + WHERE id BETWEEN #{min} AND #{max} + SQL + end + end + + def down + # noop + end +end diff --git a/db/migrate/20220211214605_update_integrations_trigger_type_new_on_insert_null_safe.rb b/db/migrate/20220211214605_update_integrations_trigger_type_new_on_insert_null_safe.rb new file mode 100644 index 00000000000..7a60ea48f40 --- /dev/null +++ b/db/migrate/20220211214605_update_integrations_trigger_type_new_on_insert_null_safe.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class UpdateIntegrationsTriggerTypeNewOnInsertNullSafe < Gitlab::Database::Migration[1.0] + include Gitlab::Database::SchemaHelpers + + FUNCTION_NAME = 'integrations_set_type_new' + + def up + # Update `type_new` dynamically based on `type`, if `type_new` is null + # and `type` dynamically based on `type_new`, if `type` is null. + # + # The old class names are in the format `AbcService`, and the new ones `Integrations::Abc`. + create_trigger_function(FUNCTION_NAME, replace: true) do + <<~SQL.squish + UPDATE integrations + SET type_new = COALESCE(NEW.type_new, regexp_replace(NEW.type, '\\A(.+)Service\\Z', 'Integrations::\\1')) + , type = COALESCE(NEW.type, regexp_replace(NEW.type_new, '\\AIntegrations::(.+)\\Z', '\\1Service')) + WHERE integrations.id = NEW.id; + RETURN NULL; + SQL + end + end + + def down + # Update `type_new` dynamically based on `type`. + # + # The old class names are in the format `AbcService`, and the new ones `Integrations::Abc`. + create_trigger_function(FUNCTION_NAME, replace: true) do + <<~SQL + UPDATE integrations SET type_new = regexp_replace(NEW.type, '\\A(.+)Service\\Z', 'Integrations::\\1') + WHERE integrations.id = NEW.id; + RETURN NULL; + SQL + end + end +end -- cgit v1.2.1