alembic: add ON DELETE CASCADE to organization child FKs (#96) #108
No reviewers
Labels
No labels
agentic-osint
audit
blocked:commit-ready-failed
blocked:gate-fetch
blocked:gate-fetch
blocked:gate-lint
blocked:gate-plan
blocked:gate-research
blocked:needs-decision
blocked:needs-human
blocked:no-changes
blocked:preflight
blocked:verify-failed
bug
chore
deferred
enhancement
feature-request
in-progress
lint-baseline
lint-cleanup
needs-decompose
needs-triage
performance
quickfix
security/medium
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/osint-hub!108
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/96-ondelete-cascade-migration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #96.
Commit
d0723c9set ondelete="CASCADE" in the SQLModel metadata for the org_id FKs of OrganizationEmail / OrganizationPhone / OrganizationDomain (app/models.py), but no alembic migration was generated. Existing databases keep the original NO ACTION FKs, so deleting an organization raises a FK violation on child rows. This PR adds migration b53942abd63a, which drops the three<table>_org_id_fkeyconstraints and recreates them with ON DELETE CASCADE (downgrade restores NO ACTION).app/models.py is untouched; the diff contains exactly one new file: backend/alembic/versions/b53942abd63a_ondelete_cascade_org_children.py.
Verification on throwaway Postgres 16 (alembic upgrade head / downgrade -1 / re-upgrade head all exit 0; alembic check reports no pending ops). psql \d:
Foreign-key constraints:
"organization_email_org_id_fkey" FOREIGN KEY (org_id) REFERENCES organization(id) ON DELETE CASCADE
Foreign-key constraints:
"organization_phone_org_id_fkey" FOREIGN KEY (org_id) REFERENCES organization(id) ON DELETE CASCADE
Foreign-key constraints:
"organization_domain_org_id_fkey" FOREIGN KEY (org_id) REFERENCES organization(id) ON DELETE CASCADE
Cascade drill: DELETE org with 1 email/1 phone/1 domain child -> all counts 0,0,0, no FK violation. Full log: verify-b53942abd63a.log (attachment on kanban task t_a5378f87).
CI status note: run 5938 (this PR) failed, but the failure is a pre-existing baseline, not this change.
bd0fb0f(run 5900, push) already failed at 121s. Same short-failure signature before this PR touched anything.ruff check app/ --config ../pyproject.tomlreports 118 errors, all underapp/(pre-existing lint debt on main). CI's backend-lint job gates on exactly that command. None of the errors involve patterns this migration could influence; and CI lint scope isapp/only — it never checksbackend/alembic/versions/.ruff checkon b53942abd63a_ondelete_cascade_org_children.py exits 0).The "checks pass" gate cannot go green without fixing the 118 baseline ruff errors on main, which is outside this PR's scope (this PR deliberately adds only the migration file). Recommend separate tracking for the baseline lint debt if CI green is required before merge.
Closing as superseded: the canonical fix for #96 has landed on
mainvia watcher recovery commit8a891e7(migrationb2c3d4e5f6a8_add_ondelete_cascade_org_child_fks.py, 173 lines). That migration mirrors the provenf101c4scd0a1_add_ondelete_cascade_case_membership_fkpattern from #101 with an_fk_has_cascadeguard for safe re-run / fresh-schema no-op. PR #103 and PR #108 are now both superseded.Thanks for the earlier migration drafts — the discussion on idempotency and the data-preservation pattern informed the landed version.
Pull request closed