From 8b05b8a76dd5b951d9559a161a85bd7c0c381cbe Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Mar 2026 13:11:29 +0000 Subject: [PATCH] fix: cascade delete namespaces when workspace is removed Change namespaces.workspace_id FK from nullOnDelete to cascadeOnDelete so that namespaces are properly cleaned up when their parent workspace is deleted, instead of being orphaned with a null workspace_id. Fixes #10 Co-Authored-By: Claude Opus 4.6 (1M context) --- ..._delete_namespaces_on_workspace_delete.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php diff --git a/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php b/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php new file mode 100644 index 0000000..bb5f6a5 --- /dev/null +++ b/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php @@ -0,0 +1,40 @@ +dropForeign(['workspace_id']); + + $table->foreign('workspace_id') + ->references('id') + ->on('workspaces') + ->cascadeOnDelete(); + }); + } + + public function down(): void + { + Schema::table('namespaces', function (Blueprint $table) { + $table->dropForeign(['workspace_id']); + + $table->foreign('workspace_id') + ->references('id') + ->on('workspaces') + ->nullOnDelete(); + }); + } +};