chores: updated - #528
Open
KodeSage wants to merge 1 commit into
Open
Conversation
|
@KodeSage 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! 🚀 |
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.
Description
Locks in the schema-level guarantees of the
device_prekeystable (signed + one-time prekeys in one table, discriminated bykey_type) with regression coverage.The table itself already landed with the unified prekey work:
apps/backend/src/db/schema.tsdefines every column, index, and constraint the issue calls for, andapps/backend/drizzle/0000_stale_mandarin.sqlmigrates it. Verified against the issue's acceptance criteria:iduuid PK,keyIdinteger,publicKeytext,signaturenullable,consumedboolean defaultfalse,createdAtkeyTypepgEnum (signed/one_time)prekey_typeenumdeviceIduuid FK, cascade deletedevice_prekeys_device_id_devices_id_fk(deviceId, keyType, keyId)device_prekeys_device_type_keyid_idx(deviceId)WHEREkey_type='one_time' AND consumed=falsedevice_prekeys_one_time_available_idxdevice_prekeys_signed_device_idxWHEREkey_type='signed'device_prekeys_signed_requires_signatureconsumed=trueatomicallySELECT … FOR UPDATE SKIP LOCKEDinside a transaction,routes/users.tsThe gap this PR closes: nothing pinned those invariants. Every one of them lives in DDL rather than route code, so an edit to
schema.tscould silently drop the check constraint or a partial index and no test would fail.Changes:
devicePrekeys.schema.test.ts— 15 tests asserting the table shape and invariants against the live Drizzle definition viagetTableConfig. Partial-index and check-constraint predicates are serialized throughPgDialectand compared as SQL text, so weakening a predicate fails the build. A final block scans the generated migration DDL, which catches the case where a constraint exists in TypeScript but was never generated into a migration and so never reaches Postgres.users.bundle.test.ts— it previously only asserted that some update ran, which would still pass if the row lock orSKIP LOCKEDwere removed. It now asserts the transaction,for('update', { skipLocked: true }), andset({ consumed: true })specifically, pinning both the atomicity and the flip-don't-delete behaviour that keeps bundle-fetch history auditable.Note on the FK target: the issue specifies
deviceId → user_devices.id. It points atdevices.idinstead, which is correct rather than a deviation —user_deviceswas merged intodevices, now the single canonical device registry thatmessages.senderDeviceId,messageEnvelopes.recipientDeviceId, andpushSubscriptions.deviceIdall reference. Left as is.Type of change
Issue numbers
Fixes #154
Testing
schema.tsfailed exactly the three relevant tests (allows exactly one signed prekey per device,allows many one-time prekeys per device,requires a signature on signed prekey rows), confirming the assertions are not vacuous.schema.tswas then restored and is unmodified in this PR.tsc --noEmitreports 9 errors, all pre-existing onmain(inroomManager,uploads,stellarListener) and none in the files touched here.Checklist