Repository navigation
[M2.2b1] Make command and audit persistence atomic - #41
Merged
Merged
Conversation
This was referenced Nov 4, 2026
samuelmbabhazi
force-pushed
the
feat/m2.2b1-transactional-audit
branch
from
November 5, 2026 12:10
f467fd5 to
b791e52
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
## Task M2.2b2, part of #21. Depends on #41; base `feat/m2.2b1-transactional-audit`. ## What changed and why Add PostgreSQL users, browser sessions and single-use identity credentials. `citext` enforces case-insensitive email uniqueness; foreign keys bind credentials to their user. Database constraints prevent unknown account states/purposes, active unverified accounts, negative security versions, plaintext-shaped credential hashes and lifetimes beyond the specification. Indexes support credential lookup, revocation and expiry cleanup. No account endpoint is exposed yet. The next PR adds repositories and command behavior on this schema. ## Validation - Eleven integration tests pass against PostgreSQL 17, including five identity schema tests. - Identity tests independently cover duplicate emails, invalid account transitions, invalid token hashes/purposes/lifetimes, competing token consumers over separate connections, persistence after reconnect, session lifetime limits and credential cascades. - Migration application is repeated to verify the test migration runner remains idempotent. - Prisma client regenerated; workspace lint and type checks pass. ## Security considerations Only token hashes are stored. Session and identity credentials carry the user's security version so later commands can invalidate stale credentials on password or privilege changes. Runtime database mutations arrive in the following PR and will use the transaction/audit mechanism from #41. The migration adds tables without altering existing fleet or audit records. ## Checklist - [x] M2.2b2 acceptance met and checked in PLAN; M2.2 remains open - [x] Lint, types and integration tests pass - [x] Invalid-input and concurrency cases covered on real PostgreSQL - [x] No new shell invocation or plaintext credential persistence - [x] No runtime command introduced; audit will be enforced by command handlers - [x] Data model follows SPEC 4 and identity limits from SPEC 8.1
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
## Task M2.2b3, part of #21. Base: `feat/m2.2b2-identity-schema`; follows the identity schema PR. ## What changed and why Add the identity storage port, redacting domain records and Prisma adapter. Per-user row locks serialize sensitive mutations. Password changes increment the security version and revoke sessions and reset credentials; single-use token claims use conditional updates. Session activity advances monotonically across overlapping requests and cannot revive expired, revoked, disabled-owner or stale-version sessions. Commands can share the transaction/audit boundary from #41. Driver errors from command transactions are replaced with an opaque availability error to keep bound data out of HTTP logs. A reusable integration fixture owns its PostgreSQL container, temporary KEK, Nest application and cleanup. ## Validation - Workspace lint, type checks and TypeScript tests pass. - Seventeen PostgreSQL integration tests pass, including six repository tests covering concurrent mutations, consumed-token rollback with audit rollback, duplicate signup transactions, expired/future-created credentials, monotonic activity and security-version invalidation. - Existing schema, fleet and audit integration suites pass unchanged. ## Security considerations No HTTP endpoint is exposed yet. Application handlers must perform mutations and publish their events inside `transaction` or `withUserLock`; this PR supplies and tests that boundary. Password hashes returned by repositories are wrapped in `Secret`. Session activity is authentication telemetry, not a separate domain command. No new shell invocation or dynamic SQL identifier is introduced. ## Checklist - [x] M2.2b persistence acceptance met and checked; M2.2 account flows remain open - [x] Lint, types and tests pass - [x] Real PostgreSQL concurrency and failure cases covered - [x] No new secret exposure path - [x] Transaction and audit rollback verified - [x] Threat model updated
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.
Task
M2.2b1, part of #21. Depends on #40; base
feat/m2.2a-identity-primitives.What changed and why
Add a request-local Prisma unit of work and make the audit repository participate in the current command transaction. Identity commands can now roll back their state change when audit persistence fails. Nested commands share their caller's transaction; concurrent requests remain isolated. Existing repositories retain their behavior until they explicitly adopt this unit of work.
Validation
Security considerations
No endpoint, role, credential or external delivery is added. Transaction callbacks must await their work and allow failures to propagate; password hashing and external I/O remain outside transactions. The synchronous audit subscriber is the only current event consumer; future external consumers must use an outbox rather than emit side effects inside a database transaction.
Checklist