Skip to content

fix(db): declare on-delete behaviour for group relations - #394

Open
gtrefe wants to merge 2 commits into
Rotula-Labs:mainfrom
gtrefe:fix/issue-248-fix-db-declare-the-on-delete-behaviour-for-the
Open

gtrefe wants to merge 2 commits into
Rotula-Labs:mainfrom
gtrefe:fix/issue-248-fix-db-declare-the-on-delete-behaviour-for-the

Conversation

@gtrefe

@gtrefe gtrefe commented Oct 17, 2026

Copy link
Copy Markdown

Overview

This PR declares an explicit onDelete behaviour for every relation hanging off SavingsGroup in prisma/schema.prisma, instead of relying on Prisma's implicit Restrict default. Operational rows (memberships, payouts) are cascaded with the group; append-only audit records (PayoutOrderLog, MemberExitLog) are preserved by making their group reference nullable with SetNull. A migration applies the new foreign-key actions, and the group deletion path plus its tests are updated to match.

Related Issue

Changes

🗄️ Schema — explicit delete policies

  • [MODIFY] prisma/schema.prisma
    • GroupMember.group and Payout.group → onDelete: Cascade (operational rows have no meaning without the group).
    • PayoutOrderLog.group and MemberExitLog.group → group reference made optional with onDelete: SetNull (append-only audit records survive the group they describe).
    • Each relation now carries a short comment documenting the chosen policy.

🧩 Service — deletion path

  • [MODIFY] src/services/group.service.ts
    • Group deletion no longer trips a foreign-key violation for groups that have members, payouts or exit logs; the cascade/nullify behaviour is now relied on deliberately rather than accidentally.

🧪 Tests

  • [MODIFY] src/__tests__/group.service.test.ts
    • Covers the intended behaviour per relation: memberships and payouts are removed with the group, while payout order logs and member exit logs remain and have their group reference nulled.

🚚 Migration

  • [ADD] prisma/migrations/20260901000000_add_group_relation_on_delete/migration.sql
    • Drops and recreates the affected foreign keys with the new ON DELETE CASCADE / ON DELETE SET NULL actions, and makes the audit-log group columns nullable.

Verification Results

npm test
✅ group.service tests pass (cascade + audit-retention cases)
Acceptance Criteria Status
Each group relation states its delete behaviour explicitly ✅ onDelete declared on GroupMember, Payout, PayoutOrderLog, MemberExitLog
Audit records survive the deletion of the group they reference ✅ PayoutOrderLog / MemberExitLog use nullable group ref + SetNull
A test covers the intended behaviour for each relation ✅ Added to src/__tests__/group.service.test.ts
npm test passes locally ✅ Passing

Closes #248

Toyosi5566 and others added 2 commits October 16, 2026 15:32
.env is read by dotenv.config() at boot and holds ENCRYPTION_KEY, JWT_SECRET,
SEP10_SERVER_SECRET, HMAC_KEY and DEPLOYER_SECRET_KEY. None of the .env
variants were ignored, so a contributor's real credentials file could be
staged by a routine `git add .` with nothing to warn anyone. Ignore the
.env variants and keep the committed example file trackable.

No .env file is tracked at HEAD and no .env object appears anywhere in the
repository history, so this is preventive rather than a remediation.
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@gtrefe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Abdul-dev-creator
Abdul-dev-creator force-pushed the main branch 2 times, most recently from af3277b to a2a4455 Compare October 18, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(db): declare the on-delete behaviour for the group relations

2 participants