Skip to content

Prepare projects and namespaces loose foreign keys

Furkan Ayhan requested to merge track-deletions-in-namespaces-and-projects into master

ROLLBACK steps

There is a small chance that the introduced DB triggers will cause performance degradation (slower deletion speed). If this becomes a big problem (incident), then we can mitigate it by dropping the triggers. Dropping the triggers is safe.

SET lock_timeout='3s';  -- attempt short lock waits

-- During busy hours, we might need to retry these statements a few times until they succeed:
DROP TRIGGER projects_loose_fk_trigger ON projects;
DROP TRIGGER namespaces_loose_fk_trigger ON namespaces;

What does this MR do and why?

This MR adds post-migrations for tracking deletions of namespaces and projects tables. They will be used for syncing those tables to their ci-mirrors.

This MR did not include specs and foreign key definitions because those ci-mirror tables are not available yet. (will be added in: !75621 (merged))

DB

UP

== 20211130201100 TrackDeletionsInNamespaces: migrating =======================
-- execute("CREATE TRIGGER namespaces_loose_fk_trigger\nAFTER DELETE ON namespaces REFERENCING OLD TABLE AS old_table\nFOR EACH STATEMENT\nEXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();\n")
   -> 0.0023s
== 20211130201100 TrackDeletionsInNamespaces: migrated (0.0023s) ==============

== 20211130201101 TrackDeletionsInProjects: migrating =========================
-- execute("CREATE TRIGGER projects_loose_fk_trigger\nAFTER DELETE ON projects REFERENCING OLD TABLE AS old_table\nFOR EACH STATEMENT\nEXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();\n")
   -> 0.0014s
== 20211130201101 TrackDeletionsInProjects: migrated (0.0014s) ================

DOWN

== 20211130201101 TrackDeletionsInProjects: reverting =========================
-- execute("DROP TRIGGER IF EXISTS projects_loose_fk_trigger ON projects")
   -> 0.0011s
== 20211130201101 TrackDeletionsInProjects: reverted (0.0012s) ================

== 20211130201100 TrackDeletionsInNamespaces: reverting =======================
-- execute("DROP TRIGGER IF EXISTS namespaces_loose_fk_trigger ON namespaces")
   -> 0.0011s
== 20211130201100 TrackDeletionsInNamespaces: reverted (0.0011s) ==============

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 Adam Hegyi

Merge request reports

Loading