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:
parent
c51e4310b1
commit
8b05b8a76d
1 changed files with 40 additions and 0 deletions
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue