Skip to content

feat(server): migrate database layer from SQLite to PostgreSQL - #193

Merged
Dannyswiss1 merged 3 commits into
Cylo-Traders:masterfrom
nasarajoe:feat/postgres-database-24
Aug 29, 2026
Merged

feat(server): migrate database layer from SQLite to PostgreSQL#193
Dannyswiss1 merged 3 commits into
Cylo-Traders:masterfrom
nasarajoe:feat/postgres-database-24

Conversation

@nasarajoe

Copy link
Copy Markdown
Contributor

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

File Change
prisma/schema.prisma Datasource provider sqlitepostgresql
src/database/database.module.ts PrismaLibSqlPrismaPg adapter; now throws if DATABASE_URL is unset instead of silently falling back to a local dev.db file
prisma/migrations/20260819164517_init/ New PostgreSQL initial migration
prisma/migrations/migration_lock.toml Provider → postgresql
src/config/env.validation.ts DATABASE_URL is now required and must be a postgres(ql):// URI
src/config/configuration.ts Removed the SQLite default from db.url
.env.example Documents the PostgreSQL connection string format
package.json Removed @libsql/client + @prisma/adapter-libsql; added @prisma/adapter-pg, pg, @types/pg
docker-compose.yml New — PostgreSQL 16 with healthcheck and named volume

New 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:

  • DB connects successfullySELECT version() returned PostgreSQL 16.14; a
    Campaign create/read/delete round-tripped through the real PrismaPg adapter,
    confirming column defaults (status='Active', totalFunded=0) and BigInt handling.
  • Migration runs without errorsprisma migrate status reports "Database schema
    is up to date!"; all 8 tables plus _prisma_migrations are created.
  • Build passesnest build exits 0.
  • Tests pass — 58/58 across 4 suites.
  • No libsql / sqlite / dev.db references remain outside generated client code.

Notes for reviewers

1. The migration history was reset — breaking for existing environments. The previous
SQLite migration used DATETIME and inline PRIMARY KEY syntax invalid in PostgreSQL, so
it 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_URL
via environment configuration.

Closes #24

nasarajoe and others added 3 commits August 19, 2026 18:02
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>
@Dannyswiss1
Dannyswiss1 merged commit 25b0cd2 into Cylo-Traders:master Aug 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] feat: Setup PostgreSQL Database

2 participants