fix: namespaces.workspace_id should cascade on workspace delete #10

Open
opened 2026-02-20 16:35:49 +00:00 by Clotho · 0 comments
Member

Problem

In Migrations/0001_01_01_000000_create_tenant_tables.php (line 115-116), the namespaces.workspace_id foreign key uses nullOnDelete() instead of cascadeOnDelete():

$table->foreignId('workspace_id')->nullable()
    ->constrained()->nullOnDelete(); // Should this cascade?

Impact

When a workspace is deleted, all its namespaces lose their workspace context (become workspace_id = null). This means:

  • Namespace entitlement billing aggregation is silently lost
  • The namespace remains in the database in an orphaned state
  • Usage records tied to those namespaces are no longer associated with any workspace

Questions to Resolve

  • Intentional? Was nullOnDelete chosen to preserve namespaces after workspace deletion?
  • If namespaces should survive workspace deletion, document this as an explicit design choice
  • If namespaces should be deleted with the workspace, change to cascadeOnDelete()

Acceptance Criteria

  • Document the intended behaviour clearly in a code comment
  • If cascade is correct: create migration to update the constraint
  • Add test for workspace deletion to verify namespace handling

Discovered during automated scan (issue #3)

## Problem In `Migrations/0001_01_01_000000_create_tenant_tables.php` (line 115-116), the `namespaces.workspace_id` foreign key uses `nullOnDelete()` instead of `cascadeOnDelete()`: ```php $table->foreignId('workspace_id')->nullable() ->constrained()->nullOnDelete(); // Should this cascade? ``` ## Impact When a workspace is deleted, all its namespaces lose their workspace context (become `workspace_id = null`). This means: - Namespace entitlement billing aggregation is silently lost - The namespace remains in the database in an orphaned state - Usage records tied to those namespaces are no longer associated with any workspace ## Questions to Resolve - **Intentional?** Was `nullOnDelete` chosen to preserve namespaces after workspace deletion? - If namespaces should survive workspace deletion, document this as an explicit design choice - If namespaces should be deleted with the workspace, change to `cascadeOnDelete()` ## Acceptance Criteria - Document the intended behaviour clearly in a code comment - If cascade is correct: create migration to update the constraint - Add test for workspace deletion to verify namespace handling _Discovered during automated scan (issue #3)_
Clotho added the
review
discovery
bug
labels 2026-02-20 16:35:49 +00:00
Clotho was assigned by Charon 2026-02-21 00:01:45 +00:00
Charon added the
agent-ready
label 2026-02-21 01:32:00 +00:00
Sign in to join this conversation.
No description provided.