feat: add database migration tooling - #151
Open
Keengfk wants to merge 1 commit into
Open
Conversation
- Add Prisma 5.22.0 (prisma + @prisma/client) as dependencies - Add prisma/schema.prisma with Intent, Solver, Token models and IntentState / SupportedChain enums; all fields indexed appropriately - Add initial migration SQL (prisma/migrations/20240101000000_init/) - Add PrismaService (extends PrismaClient, NestJS lifecycle hooks) and global PrismaModule; wire into AppModule - Add DATABASE_URL to Joi validation schema, AppConfig, and .env.example - Add npm scripts: db:generate, db:migrate, db:migrate:prod, db:studio, db:validate - Update Dockerfile: build stage runs prisma generate; runtime CMD runs prisma migrate deploy before starting the server - Update CI: add postgres:16-alpine service container and migration steps (db:validate, db:generate, db:migrate:prod) before build/test - Add PrismaService unit test (src/prisma/prisma.service.spec.ts) - Mock PrismaService in e2e test helper so suites stay DB-free Closes stellar-vortex-protocol#37
|
@Keengfk 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.
Summary
Sets up Prisma as the schema migration layer for vortex-backend, addressing the
requirement from #36 to version schema changes rather than applying them ad
hoc. The service still uses in-memory stores for all feature data — this PR
lays the foundation so the on-chain writes roadmap item can swap them out for
real DB-backed services without a separate tooling setup step.
───────────────────────────────────────────────────────────────────────────────
Changes
Schema & migrations
and SupportedChain enums, JSONB columns for nested token objects, and indexes
on all commonly-filtered fields (user, state, solver, chain, symbol)
into version control so every developer and CI run starts from the same
baseline
NestJS integration
onModuleInit, disconnects on onModuleDestroy
any feature module can inject PrismaService without re-importing
Configuration
boots without a live DB in unit tests), AppConfig interface, and .env.example
npm scripts
┌────────┬──────────────┐
│ Script │ What it does │
├─────────────────────┼─────────────────────────────────────────────┤
│ npm run db:generate │ Regenerate Prisma client after schema edits │
├─────────────────────────┼─────────────────────────────────────────────┤
│ npm run db:migrate │ Create a new migration (dev) │
├─────────────────────────┼─────────────────────────────────────────────┤
│ npm run db:migrate:prod │ Apply pending migrations (production / CI) │
├─────────────────────────┼─────────────────────────────────────────────┤
│ npm run db:studio │ Open Prisma Studio │
├─────────────────────────┼─────────────────────────────────────────────┤
│ npm run db:validate │ Validate schema without a DB connection │
└─────────────────────────┴─────────────────────────────────────────────┘
Docker
applied automatically on every container start, making it impossible to forget
the step
CI
lint/typecheck/build/test, catching broken migration SQL before merge
───────────────────────────────────────────────────────────────────────────────
Testing
$connect/$disconnect, lifecycle hooks, model accessor shape)
mock so e2e suites remain self-contained (no live database required to run npm
run test:e2e)
npm run lint ✓ 0 errors
npm run typecheck ✓ 0 errors
npm run build ✓ clean
npm test ✓ 22 tests, 4 suites
npm run test:e2e ✓ 23 tests, 5 suites
prisma validate ✓ schema valid
closes #57