fix: entitlement_features.parent_feature_id nullOnDelete orphans child features #40

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

Problem

In Migrations/0001_01_01_000000_create_tenant_tables.php (line 141-142), the self-referential FK on entitlement_features.parent_feature_id uses nullOnDelete():

$table->foreignId('parent_feature_id')->nullable()
    ->constrained('entitlement_features')->nullOnDelete();

Impact

If a parent feature is deleted, all child features have their parent_feature_id silently set to NULL. This breaks:

  • Hierarchical feature pooling (the can() method in EntitlementService uses parent features for limit aggregation)
  • Any UI that displays feature hierarchies

Acceptance Criteria

  • Decide on intended behaviour: should child features be deleted with the parent, or reassigned?
  • Document the decision with a code comment
  • If children should cascade: change to cascadeOnDelete() and add test
  • If children should be preserved: add a test that verifies orphaned children are handled gracefully in EntitlementService

Discovered during automated scan (issue #3)

## Problem In `Migrations/0001_01_01_000000_create_tenant_tables.php` (line 141-142), the self-referential FK on `entitlement_features.parent_feature_id` uses `nullOnDelete()`: ```php $table->foreignId('parent_feature_id')->nullable() ->constrained('entitlement_features')->nullOnDelete(); ``` ## Impact If a parent feature is deleted, all child features have their `parent_feature_id` silently set to `NULL`. This breaks: - Hierarchical feature pooling (the `can()` method in EntitlementService uses parent features for limit aggregation) - Any UI that displays feature hierarchies ## Acceptance Criteria - Decide on intended behaviour: should child features be deleted with the parent, or reassigned? - Document the decision with a code comment - If children should cascade: change to `cascadeOnDelete()` and add test - If children should be preserved: add a test that verifies orphaned children are handled gracefully in EntitlementService _Discovered during automated scan (issue #3)_
Clotho added the
review
discovery
bug
labels 2026-02-20 16:44:01 +00:00
Clotho was assigned by Charon 2026-02-20 23:46:46 +00:00
Charon added the
agent-ready
label 2026-02-21 01:31:49 +00:00
Sign in to join this conversation.
No description provided.