feat(server): migrate database layer from SQLite to PostgreSQL - #193
Merged
Dannyswiss1 merged 3 commits intoAug 29, 2026
Merged
Conversation
The master merge left the branch half-converted: the DB module still referenced the libSQL adapter, the second Campaign migration was SQLite `PRAGMA`/RedefineTables syntax, the e2e suite booted against SQLite files, and CI had no database service. Lint was the first step to fail, hiding the rest. - database.module: use the pg driver adapter (import was already pg-only) - migrations: make `add_campaign_returnable` a plain Postgres ALTER TABLE and fold the non-null `refundable` default into the init migration - env.validation.spec: supply a DATABASE_URL so the CORS cases test CORS, and cover the new required-postgres-URL rule - e2e: drop the per-file SQLite scaffolding; run migrations once via a jest globalSetup, share one Postgres schema, reset tables per spec, and run serially (--runInBand) - server.yml: add a postgres:16 service + migration step; point DATABASE_URL at it - lint: wrap an over-length line flagged by prettier - package-lock: drop the now-unused @libsql/* / adapter-libsql entries Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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 PostgreSQL as the persistent store for indexed blockchain data in
server/.Prisma was already installed with a complete 8-model schema, but the datasource was
bound to SQLite/libSQL. The work here is therefore a datasource conversion rather
than a from-scratch ORM install — the existing schema is preserved unchanged, and only
the database provider, driver adapter, and migration history are swapped to PostgreSQL.
Changes
prisma/schema.prismaprovidersqlite→postgresqlsrc/database/database.module.tsPrismaLibSql→PrismaPgadapter; now throws ifDATABASE_URLis unset instead of silently falling back to a localdev.dbfileprisma/migrations/20260819164517_init/prisma/migrations/migration_lock.tomlpostgresqlsrc/config/env.validation.tsDATABASE_URLis now required and must be apostgres(ql)://URIsrc/config/configuration.tsdb.url.env.examplepackage.json@libsql/client+@prisma/adapter-libsql; added@prisma/adapter-pg,pg,@types/pgdocker-compose.ymlNew scripts
npm run db:migrate / db:migrate:deploy / db:migrate:status / db:migrate:reset / db:studio
Verification
Run against a live PostgreSQL 16.14 instance:
SELECT version()returnedPostgreSQL 16.14; aCampaigncreate/read/delete round-tripped through the realPrismaPgadapter,confirming column defaults (
status='Active',totalFunded=0) andBigInthandling.prisma migrate statusreports "Database schemais up to date!"; all 8 tables plus
_prisma_migrationsare created.nest buildexits 0.libsql/sqlite/dev.dbreferences remain outside generated client code.Notes for reviewers
1. The migration history was reset — breaking for existing environments. The previous
SQLite migration used
DATETIMEand inlinePRIMARY KEYsyntax invalid in PostgreSQL, soit could not be carried forward. Existing environments need
npm run db:migrate:reset.2. Default port is 55432, not 5432 — avoids colliding with a system PostgreSQL.
3. Compose credentials are local-development only; production supplies
DATABASE_URLvia environment configuration.
Closes #24