From b6fb0d4adcf074f513b8f9d07f0718673f6a6a19 Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Tue, 30 Nov 2021 23:23:31 +0300 Subject: [PATCH] Prepare projects and namespaces loose foreign keys This commit adds post-migrations for tracking deletions of namespaces and projects tables. This commit did not include specs and foreign key definitions because those tables are not available yet. Changelog: other --- ...0211130201100_track_deletions_in_namespaces.rb | 15 +++++++++++++++ .../20211130201101_track_deletions_in_projects.rb | 15 +++++++++++++++ db/schema_migrations/20211130201100 | 1 + db/schema_migrations/20211130201101 | 1 + db/structure.sql | 4 ++++ 5 files changed, 36 insertions(+) create mode 100644 db/post_migrate/20211130201100_track_deletions_in_namespaces.rb create mode 100644 db/post_migrate/20211130201101_track_deletions_in_projects.rb create mode 100644 db/schema_migrations/20211130201100 create mode 100644 db/schema_migrations/20211130201101 diff --git a/db/post_migrate/20211130201100_track_deletions_in_namespaces.rb b/db/post_migrate/20211130201100_track_deletions_in_namespaces.rb new file mode 100644 index 00000000000000..e688e0b467df2c --- /dev/null +++ b/db/post_migrate/20211130201100_track_deletions_in_namespaces.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackDeletionsInNamespaces < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:namespaces) + end + + def down + untrack_record_deletions(:namespaces) + end +end diff --git a/db/post_migrate/20211130201101_track_deletions_in_projects.rb b/db/post_migrate/20211130201101_track_deletions_in_projects.rb new file mode 100644 index 00000000000000..dfe7ab4c037f06 --- /dev/null +++ b/db/post_migrate/20211130201101_track_deletions_in_projects.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class TrackDeletionsInProjects < Gitlab::Database::Migration[1.0] + include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers + + enable_lock_retries! + + def up + track_record_deletions(:projects) + end + + def down + untrack_record_deletions(:projects) + end +end diff --git a/db/schema_migrations/20211130201100 b/db/schema_migrations/20211130201100 new file mode 100644 index 00000000000000..80c2d68671b1ef --- /dev/null +++ b/db/schema_migrations/20211130201100 @@ -0,0 +1 @@ +cc0146769929c9fbb0b7b6788826d2e188c8664a14e1015563ba4f9e65397c4e \ No newline at end of file diff --git a/db/schema_migrations/20211130201101 b/db/schema_migrations/20211130201101 new file mode 100644 index 00000000000000..ef1178c10c5d37 --- /dev/null +++ b/db/schema_migrations/20211130201101 @@ -0,0 +1 @@ +b0215ac45031593ca98de4f8858d21f1c29af03742a422bffd83598e39a6871c \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index b8c75e33e7b098..a932ea30de515c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -28729,6 +28729,10 @@ CREATE TRIGGER ci_pipelines_loose_fk_trigger AFTER DELETE ON ci_pipelines REFERE CREATE TRIGGER ci_runners_loose_fk_trigger AFTER DELETE ON ci_runners REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records(); +CREATE TRIGGER namespaces_loose_fk_trigger AFTER DELETE ON namespaces REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records(); + +CREATE TRIGGER projects_loose_fk_trigger AFTER DELETE ON projects REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records(); + CREATE TRIGGER trigger_delete_project_namespace_on_project_delete AFTER DELETE ON projects FOR EACH ROW WHEN ((old.project_namespace_id IS NOT NULL)) EXECUTE FUNCTION delete_associated_project_namespace(); CREATE TRIGGER trigger_has_external_issue_tracker_on_delete AFTER DELETE ON integrations FOR EACH ROW WHEN ((((old.category)::text = 'issue_tracker'::text) AND (old.active = true) AND (old.project_id IS NOT NULL))) EXECUTE FUNCTION set_has_external_issue_tracker(); -- GitLab