7.27 Prisma Migration & Database Sync#330
Merged
Om7035 merged 43 commits intoQuoteVote:mainfrom Apr 23, 2026
Merged
Conversation
… and corresponding unit tests.
Add shared test helpers (_helpers.ts) for Mongoose schema validation testing and update jest.config.ts modulePathIgnorePatterns for proper test isolation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add comprehensive schema tests covering required fields, default values, enum validation, and field types for the core domain models. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover vote type enum validation, soft-delete defaults, required fields, and VoteLog token/description constraints. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover message text requirement, soft-delete defaults, readBy/deliveredTo subdocs, room messageType enum, and isDirect defaults. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nce, Typing Cover emoji requirement, roster status enum (pending/accepted/declined/blocked), presence status enum, and typing TTL expiry behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ontent, Creator, Domain Cover activity event type enum, collection name requirement, content title requirement, creator fields, and domain key requirement. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…, UserInvite, UserReport, UserReputation, Group Cover notification type enum, report reason/status/severity enums, invite expiry, reputation score defaults, and group privacy enum. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover SolidConnection CRUD operations and schema validation including webId/issuer requirements, tokens object, and connection status. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove unnecessary mock function declarations to align with the standardized Mongoose mock pattern used across all model tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…d relations in social
…vity, and VoteLog
Add createdAt timestamp, simplify Quote relation from dual (quoter/quoted) to single userId to match current Mongoose model. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Quote: replace quoter/quoted with single userId to match Mongoose - Post, Comment, Vote: add createdAt timestamps for Mongoose parity - Reaction: add createdAt/updatedAt and compound userId+messageId index Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- PostMessage: add createdAt, compound index on messageRoomId+created - MessageRoom: add createdAt for Mongoose timestamps parity Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…yping - Presence: add createdAt/updatedAt, lastHeartbeat index, defaults - Typing: add createdAt/updatedAt, expiresAt field, isTyping default true Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add integration test suite covering 13 model types with 28 tests: - User, Post, Comment, Quote, Vote CRUD and relations - MessageRoom, PostMessage, Reaction relations - Presence, Roster, Typing with unique constraint checks - UserReport bidirectional relations - Deep nested traversal (user -> posts -> comments/votes/quotes) - Deep messaging traversal (room -> messages -> reactions) - Activity model relations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…cation and data validation
The Message model was renamed from PostMessage in 7.26, but the hardcoded model list in the health-check script still referenced the old name. Update it so the output matches the actual generated Prisma Client. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Prisma's MongoDB connector uses transactions internally for create/update/delete operations, which requires MongoDB to run as a replica set. A standalone mongod fails with a cryptic P2031 error mid-run. This preflight script probes the database with a tiny user.create/delete round trip and either exits 0 (replica set detected) or exits 1 with a boxed, actionable hint covering Docker, local mongod, and Atlas fixes — so integration tests never surface raw P2031 from the middle of a suite. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…st:prisma - Rename misleading prisma:studio (which actually ran db push) to prisma:push - Add real prisma:studio for the GUI - Add prisma:sync (push + generate) as a one-shot convenience - Add prisma:parity wired to scripts/prisma-mongoose-parity.ts - Gate pnpm test:prisma behind scripts/check-replica-set.ts so the suite fails fast with a readable message instead of mid-suite P2031 if the local MongoDB is not running as a replica set Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…aversal Replaces the previous 4-model smoke test with a full CRUD + relationship exercise across every Prisma model: User, Group, Post, Comment, Quote, Vote, VoteLog, Reaction, Message, DirectMessage, MessageRoom, Notification, Activity, Roster, Presence, Typing, UserInvite, UserReport, BotReport, UserReputation, Domain, Creator, Content, Collection (24 total). Includes 2-level deep traversal (user → posts → comments/votes/quotes; room → messages → reactions; user → activities/notifications/collections) and a 24-model COUNT smoke test to verify every delegate is callable. LIFO cleanup wrapped in try/finally so partial failures don't leave orphan test data. Replica-set errors are detected and produce the same friendly hint as the preflight script. All delegate maps are fully typed — no `any`, no eslint-disable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… check Because Mongoose (primary ORM) and Prisma (migration target) read/write the same MongoDB collections, the risk is silent drift between @Map() directives and Mongoose field names. This CLI script detects drift at runtime. For each critical model (User, Post, MessageRoom), runs two bidirectional round-trips: - Mongoose -> Prisma: create via Mongoose, read via Prisma, assert mapped fields (admin/isAdmin, _followingId/followingIds, _followersId/followerIds, _wallet/wallet, enable_voting/enableVoting, users/userIds) surface correctly - Prisma -> Mongoose: create via Prisma, read raw via Mongoose, assert the MongoDB document uses the expected legacy field names Also adds a functional parity check comparing the same logical query shape via Mongoose's populate() against Prisma's include() — asserts post title, populated author id, author username, and countDocuments match prisma.count. LIFO cleanup wrapped in finally; replica-set errors produce the friendly preflight hint. Fully typed — no `any`, no eslint-disable. Exits 0 on full alignment, 1 with a diff report on any mismatch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rsal Expands the Prisma integration suite so every model is tested: New suites: VoteLog, DirectMessage, Notification, UserInvite, BotReport, UserReputation, Domain, Creator, Content, Collection — each with CRUD plus relation reads and, where the schema has one, a unique-constraint assertion (BotReport reporterId+userId, UserReputation userId). New 3-level deep traversal tests: - user -> posts -> comments -> commenter (back to User) - user -> rooms -> messages -> reactions -> reactor New smoke test: count() on every one of the 24 models in a single Promise.all, asserting the entire delegate surface is callable. Added a beforeAll replica-set probe that throws a readable error instead of letting Prisma's cryptic P2031 leak out of the suite when MongoDB is not running as a replica set. Expanded the typed deleteFns map to cover all newly tested models for LIFO cleanup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…uirement Ticket 7.27 asks to run `prisma migrate dev --name init`, but that command is SQL-only and hard-errors on MongoDB. The correct workflow is db push. This doc captures: - Why migrate dev does not work for MongoDB - The db push / db generate / db sync workflow - The @Map()-based bridging between Mongoose and Prisma field names - A backfill script pattern (placed under scripts/migrations/) for any future field renames or required-field additions - How pnpm prisma:parity verifies Mongoose <-> Prisma alignment (both field-mapping and functional populate-vs-include parity) - A table of integrity check commands (validate / health / test / test:prisma / parity) and what each covers - The MongoDB replica-set requirement (Prisma uses transactions for write operations) with three ways to satisfy it: Docker one-liner, local mongod config, MongoDB Atlas - When to re-run prisma:sync Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@shubham-01-star is attempting to deploy a commit to the Louis Girifalco's projects Team on Vercel. A member of the Team first needs to authorize it. |
Om7035
approved these changes
Apr 23, 2026
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.
Summary
db push(Prisma'smigrate devis SQL-only and does not support MongoDB)populate()vsinclude()check)Acceptance Criteria
prisma migrate dev --name initcompletesmigrate devis SQL-only and errors out on MongoDB. Correct equivalentpnpm prisma:pushis wired. Seedocs/prisma-migration-strategy.md.pnpm prisma:testcovers all 24 Prisma modelspnpm prisma:parityverifies both field mappings and functional query parityWhat changed
New files
docs/prisma-migration-strategy.md— whymigrate devdoesn't work for MongoDB, thedb pushworkflow, backfill patterns, replica-set requirements, and when to re-syncquotevote-backend/scripts/check-replica-set.ts— preflight guard; detects non-replica-set MongoDB and fails fast with an actionable hint instead of cryptic P2031quotevote-backend/scripts/prisma-mongoose-parity.ts— bidirectional round-trips + functionalpopulate()vsinclude()comparisonModified
quotevote-backend/package.json—prisma:studio(previously randb push) →prisma:push; added realprisma:studio,prisma:sync,prisma:parity;test:prismanow gated by the replica-set preflightquotevote-backend/scripts/prisma-crud-test.ts— rewritten from 4-model smoke test to full 24-model CRUD + deep traversalquotevote-backend/__tests__/integration/prisma-dependent-models.test.ts— added 10 missing model suites (VoteLog, DirectMessage, Notification, UserInvite, BotReport, UserReputation, Domain, Creator, Content, Collection), 3-level deep traversal, 24-model delegate smoke test, and abeforeAllreplica-set guardquotevote-backend/scripts/prisma-health-check.ts— fix stalePostMessagereference (renamed toMessagein 7.26)24 models covered
User, Group, Post, Comment, Quote, Vote, VoteLog, Reaction, Message, DirectMessage, MessageRoom, Notification, Activity, Roster, Presence, Typing, UserInvite, UserReport, BotReport, UserReputation, Domain, Creator, Content, Collection
Deep traversal coverage
Type safety
anyacross all new/modified fileseslint-disablecommentsPrismaDelegate,PrismaModelKey,MongooseModel,MongooseModelKey)Test plan
CI-safe (no live DB required)
pnpm exec prisma validate— schemas validpnpm type-check— cleanpnpm lint— cleanpnpm build— cleanpnpm test— 700/700 passingLive-DB (requires MongoDB replica set)
pnpm prisma:push— apply schema to local/staging MongoDBpnpm prisma:health— confirms connectivity + 24-model countpnpm prisma:test— full CRUD + traversal across all 24 modelspnpm test:prisma— Jest integration suite (preflight-guarded)pnpm prisma:parity— Mongoose ↔ Prisma alignment, field mappings, functional populate-vs-include parityIf the reviewer's MongoDB is not already a replica set, any of the DB-dependent commands will print an actionable hint with Docker / local mongod / Atlas fixes. See
docs/prisma-migration-strategy.md.