Skip to content

Drop sequences that should no longer exist in database

What does this MR do and why?

Normally a sequence should be dropped when its associated table is dropped. However, due to a bug in GitLab's sequences_owned_by implementation (fixed via !160528 (merged)), sequences may have erroneously been assigned to columns in the ci_builds or p_ci_builds tables. As a result, if the sequences were assigned to those CI tables, they may not have been dropped when their assocated tables were dropped.

This commit adds a migration to remove possible orphaned sequences to ensure they don't cause problems in the future, as they did with #474293 (closed).

Relates to #474293 (closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Run bin/rails db:migrate
main: == [advisory_lock_connection] object_id: 656420, pg_backend_pid: 22427
main: == 20240724181016 DropOrphanedSequences: migrating ============================
main: -- execute("DROP SEQUENCE IF EXISTS ci_editor_ai_conversation_messages_id_seq")
main:    -> 0.0010s
main: -- execute("DROP SEQUENCE IF EXISTS ci_partitions_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS dast_scanner_profiles_tags_id_seq")
main:    -> 0.0007s
main: -- execute("DROP SEQUENCE IF EXISTS external_approval_rules_protected_branches_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS geo_hashed_storage_attachments_events_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS geo_hashed_storage_migrated_events_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS geo_repositories_changed_events_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS geo_repository_created_events_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS geo_repository_deleted_events_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS geo_repository_renamed_events_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS geo_repository_updated_events_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS geo_reset_checksum_events_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS in_product_marketing_emails_id_seq")
main:    -> 0.0006s
main: -- execute("DROP SEQUENCE IF EXISTS member_tasks_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS merge_request_diff_llm_summaries_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS product_analytics_events_experimental_id_seq")
main:    -> 0.0005s
main: -- execute("DROP SEQUENCE IF EXISTS project_repository_states_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS sbom_vulnerable_component_versions_id_seq")
main:    -> 0.0004s
main: -- execute("DROP SEQUENCE IF EXISTS schema_inconsistencies_id_seq")
main:    -> 0.0009s
main: -- execute("DROP SEQUENCE IF EXISTS u2f_registrations_id_seq")
main:    -> 0.0006s
main: -- execute("DROP SEQUENCE IF EXISTS vulnerability_advisories_id_seq")
main:    -> 0.0010s
main: -- execute("DROP SEQUENCE IF EXISTS zoekt_indexed_namespaces_id_seq")
main:    -> 0.0005s
main: == 20240724181016 DropOrphanedSequences: migrated (0.0165s) ===================

main: == [advisory_lock_connection] object_id: 656420, pg_backend_pid: 22427
ci: == [advisory_lock_connection] object_id: 656500, pg_backend_pid: 22497
ci: == 20240724181016 DropOrphanedSequences: migrating ============================
ci: -- execute("DROP SEQUENCE IF EXISTS ci_editor_ai_conversation_messages_id_seq")
ci:    -> 0.0013s
ci: -- execute("DROP SEQUENCE IF EXISTS ci_partitions_id_seq")
ci:    -> 0.0008s
ci: -- execute("DROP SEQUENCE IF EXISTS dast_scanner_profiles_tags_id_seq")
ci:    -> 0.0006s
ci: -- execute("DROP SEQUENCE IF EXISTS external_approval_rules_protected_branches_id_seq")
ci:    -> 0.0006s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_hashed_storage_attachments_events_id_seq")
ci:    -> 0.0086s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_hashed_storage_migrated_events_id_seq")
ci:    -> 0.0005s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_repositories_changed_events_id_seq")
ci:    -> 0.0004s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_repository_created_events_id_seq")
ci:    -> 0.0006s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_repository_deleted_events_id_seq")
ci:    -> 0.0005s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_repository_renamed_events_id_seq")
ci:    -> 0.0010s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_repository_updated_events_id_seq")
ci:    -> 0.0010s
ci: -- execute("DROP SEQUENCE IF EXISTS geo_reset_checksum_events_id_seq")
ci:    -> 0.0004s
ci: -- execute("DROP SEQUENCE IF EXISTS in_product_marketing_emails_id_seq")
ci:    -> 0.0004s
ci: -- execute("DROP SEQUENCE IF EXISTS member_tasks_id_seq")
ci:    -> 0.0006s
ci: -- execute("DROP SEQUENCE IF EXISTS merge_request_diff_llm_summaries_id_seq")
ci:    -> 0.0005s
ci: -- execute("DROP SEQUENCE IF EXISTS product_analytics_events_experimental_id_seq")
ci:    -> 0.0007s
ci: -- execute("DROP SEQUENCE IF EXISTS project_repository_states_id_seq")
ci:    -> 0.0009s
ci: -- execute("DROP SEQUENCE IF EXISTS sbom_vulnerable_component_versions_id_seq")
ci:    -> 0.0006s
ci: -- execute("DROP SEQUENCE IF EXISTS schema_inconsistencies_id_seq")
ci:    -> 0.0005s
ci: -- execute("DROP SEQUENCE IF EXISTS u2f_registrations_id_seq")
ci:    -> 0.0004s
ci: -- execute("DROP SEQUENCE IF EXISTS vulnerability_advisories_id_seq")
ci:    -> 0.0004s
ci: -- execute("DROP SEQUENCE IF EXISTS zoekt_indexed_namespaces_id_seq")
ci:    -> 0.0003s
ci: == 20240724181016 DropOrphanedSequences: migrated (0.0456s) ===================
Edited by Stan Hu

Merge request reports

Loading