feat: add scheduled membership state reconciliation (#53)#67
Open
Anichris-koded wants to merge 4 commits into
Open
feat: add scheduled membership state reconciliation (#53)#67Anichris-koded wants to merge 4 commits into
Anichris-koded wants to merge 4 commits into
Conversation
) - Add reconciliationWorker with runReconciliation() and startReconciliationWorker() - Query targets state IN [active,suspended] AND expiresAt < now; updates to expired - Emit MEMBERSHIP_UPDATED audit event per changed row with before/after state - Wire worker into startup/shutdown in index.ts - Add RECONCILIATION_INTERVAL_MS config (default 5 min) + .env.example entry - Add @@index([state, expiresAt]) on Membership for efficient reconciliation queries - Add getNormalizedMembershipState() to memberService for read-time expiry checks - Update jest.config.js roots to include src/ so worker tests are discovered - Fix schema: add Badge<->Member back-relation and remove duplicate comment - 10 tests covering all acceptance criteria
- 20260615_init: create all base tables (was missing, causing CI migrate deploy to fail) - 20260618_membership_reconciliation_index: CREATE INDEX for Membership(state, expiresAt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #53
Summary
Implements scheduled membership state reconciliation as described in issue #53.
Changes
New files
apps/access-api/src/workers/reconciliationWorker.ts—runReconciliation()scans memberships wherestate IN (active, suspended) AND expiresAt < now, updates each toexpired, and emits aMEMBERSHIP_UPDATEDaudit event per row.startReconciliationWorker(intervalMs)wraps it in a configurablesetIntervaland returns a stop function.Modified files
apps/access-api/src/services/memberService.ts— addedgetNormalizedMembershipState()helper; applied across all four public methods so read-time expiry is the first line of defence (not the reconciliation worker)apps/access-api/prisma/schema.prisma— added@@index([state, expiresAt])onMembershipfor efficient reconciliation queries; fixed pre-existingBadge→Membermissing back-relation; removed duplicate commentapps/access-api/src/config.ts— addedRECONCILIATION_INTERVAL_MS(default 300 000 ms)apps/access-api/src/index.ts— starts worker after app boot, stops it on SIGTERM/SIGINTapps/access-api/jest.config.js— addedsrcto roots sosrc/workers/tests are discovered.env.example— documentedRECONCILIATION_INTERVAL_MSTests
10 unit tests in
src/workers/reconciliationWorker.test.tscovering all acceptance criteria:Notes
getNormalizedMembershipState()remains the authoritative check for access decisions.