fix: add FK constraint on usage_alert_history.feature_code #56

Open
Charon wants to merge 3 commits from feat/constrain-feature-code-fk into dev
Member

Summary

  • Adds foreign key constraints from usage_alert_history.feature_code, entitlement_boosts.feature_code, and entitlement_usage_records.feature_code to entitlement_features.code
  • Uses cascadeOnUpdate so feature code renames propagate automatically
  • Uses restrictOnDelete to prevent deleting features that have associated records

Fixes #12

Test plan

  • Run php artisan migrate on a fresh database — migration should apply cleanly
  • Run php artisan migrate:rollback — FK constraints should be dropped
  • Verify inserting a usage_alert_history row with an invalid feature_code is rejected
  • Verify deleting an entitlement_feature with existing usage records is rejected
## Summary - Adds foreign key constraints from `usage_alert_history.feature_code`, `entitlement_boosts.feature_code`, and `entitlement_usage_records.feature_code` to `entitlement_features.code` - Uses `cascadeOnUpdate` so feature code renames propagate automatically - Uses `restrictOnDelete` to prevent deleting features that have associated records Fixes #12 ## Test plan - [ ] Run `php artisan migrate` on a fresh database — migration should apply cleanly - [ ] Run `php artisan migrate:rollback` — FK constraints should be dropped - [ ] Verify inserting a usage_alert_history row with an invalid feature_code is rejected - [ ] Verify deleting an entitlement_feature with existing usage records is rejected
Charon added 3 commits 2026-03-24 13:11:48 +00:00
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>
Add foreign key constraints from usage_alert_history.feature_code,
entitlement_boosts.feature_code, and entitlement_usage_records.feature_code
to entitlement_features.code to prevent orphaned records.

Uses cascadeOnUpdate (code renames propagate) and restrictOnDelete
(cannot delete a feature that has usage/alert/boost records).

Fixes #12

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The self-referential FK on entitlement_features.parent_feature_id used
nullOnDelete(), which orphaned child features when a parent was deleted.
Children that belong to a pool have no meaning without their parent, so
cascade deletion is the correct behaviour.

Adds a migration that drops and re-creates the FK with cascadeOnDelete().

Fixes #40

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/constrain-feature-code-fk:feat/constrain-feature-code-fk
git checkout feat/constrain-feature-code-fk

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feat/constrain-feature-code-fk
git checkout feat/constrain-feature-code-fk
git rebase dev
git checkout dev
git merge --ff-only feat/constrain-feature-code-fk
git checkout feat/constrain-feature-code-fk
git rebase dev
git checkout dev
git merge --no-ff feat/constrain-feature-code-fk
git checkout dev
git merge --squash feat/constrain-feature-code-fk
git checkout dev
git merge --ff-only feat/constrain-feature-code-fk
git checkout dev
git merge feat/constrain-feature-code-fk
git push origin dev
Sign in to join this conversation.
No description provided.