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) <noreply@anthropic.com>
This commit is contained in:
Claude 2026-03-24 13:11:29 +00:00
parent c51e4310b1
commit 8b05b8a76d
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Change namespaces.workspace_id FK from nullOnDelete to cascadeOnDelete.
*
* Fixes #10 — namespaces were orphaned with null workspace_id when
* the parent workspace was deleted.
*/
public function up(): void
{
Schema::table('namespaces', function (Blueprint $table) {
$table->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();
});
}
};