Skip to content

Cleanup orphaned routes

Alexandru Croitor requested to merge cleanup-orphaned-routes into master

What does this MR do and why?

After backfilling namespace_id on routes table it is quite easy to detect orphaned routes, which was much harder with the polymorphic source_id, source_type association.

This migration would cleanup orphaned routes and check one more time any routes records that may be missing a namespace_id.

After this migration we should have no routes records with namespace_id = NULL and should be able to add a NOT NULL constraint on routes#namespace_id column as well as a ON DELETE CASCADE FK instead of a ON DELETE SET NULL re #347400 (closed)

re #352371 (closed)

Database migration

UP

~/work/projects/gitlab/gdk-ee/gitlab(origin->cleanup-orphaned-routes)$ rake db:migrate VERSION=20220524080944
WARNING: This version of GitLab depends on gitlab-shell 14.7.1, but you're running 14.5.0. Please update gitlab-shell.
main: == 20220524080944 CleanupOrphanedRoutes: migrating ============================
main: -- transaction_open?()
main:    -> 0.0000s
main: == 20220524080944 CleanupOrphanedRoutes: migrated (0.2329s) ===================

ci: == 20220524080944 CleanupOrphanedRoutes: migrating ============================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared].
ci: == 20220524080944 CleanupOrphanedRoutes: migrated (0.0001s) ===================

DOWN

~/work/projects/gitlab/gdk-ee/gitlab(origin->cleanup-orphaned-routes)$ rake db:migrate:down:main VERSION=20220524080944
WARNING: This version of GitLab depends on gitlab-shell 14.7.1, but you're running 14.5.0. Please update gitlab-shell.
main: == 20220524080944 CleanupOrphanedRoutes: reverting ============================
main: == 20220524080944 CleanupOrphanedRoutes: reverted (0.0217s) ===================

Query plans

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alexandru Croitor

Merge request reports