Skip to content

fix(db): migrate from SQLite to PostgreSQL for production readiness - #563

Merged
Abdulazeem-code merged 2 commits into
Abdulazeem-code:mainfrom
Chrogend:fix/migrate-sqlite-to-postgresql
Aug 30, 2026
Merged

fix(db): migrate from SQLite to PostgreSQL for production readiness#563
Abdulazeem-code merged 2 commits into
Abdulazeem-code:mainfrom
Chrogend:fix/migrate-sqlite-to-postgresql

Conversation

@Chrogend

Copy link
Copy Markdown
Contributor

Overview

This PR completes the migration from SQLite to PostgreSQL for production readiness. The Prisma schema and migrations were already targeting PostgreSQL, but the raw database access layer (src/db.js) still used SQLite via the sqlite3 package with generic-pool. This PR replaces the entire SQLite stack with pg (node-postgres) and updates all SQL queries to use PostgreSQL-compatible syntax.

Related Issue

Closes #502

Changes

Database Layer

  • [REWRITE] src/db.js

    • Replaced sqlite3 + generic-pool with pg (node-postgres) Pool
    • Schema initialization uses PostgreSQL-compatible CREATE TABLE IF NOT EXISTS with TIMESTAMPTZ
    • Added NODE_ENV=test guard to prevent process.exit(1) during test runs
    • Exports poolGet, poolRun, poolAll with PostgreSQL query interface
  • [MODIFY] package.json

    • Removed sqlite3 dependency
    • Added pg (node-postgres) dependency

SQL Query Updates

  • [MODIFY] server.js

    • Converted ? placeholders to $1 PostgreSQL syntax
    • Replaced COLLATE NOCASE with ILIKE for case-insensitive search
    • Added P2002 error code handling for PostgreSQL unique constraint violations
  • [MODIFY] src/routes/v1/userRoutes.js

    • All SQL queries converted to PostgreSQL syntax ($1 placeholders, ILIKE)
  • [MODIFY] src/routes/v1/webhookRoutes.js

    • SQL queries converted to PostgreSQL syntax
  • [MODIFY] src/routes/v1/statsRoutes.js

    • Column aliases quoted with double quotes for PostgreSQL compatibility
  • [MODIFY] src/webhookWorker.js

    • All SQL queries converted to PostgreSQL syntax

Docker Compose

  • [MODIFY] docker-compose.test.yml
    • Added postgres-test service (PostgreSQL 16 Alpine)
    • Updated api-test service to use DATABASE_URL pointing to PostgreSQL instead of DB_PATH for SQLite
    • Added depends_on with health check condition

Tests

  • [MODIFY] All test files (server.test.js, register-endpoint.test.js, register-multisigner.test.js, helmet.test.js, rate-limit.test.js, sentry.test.js)
    • Replaced sqlite3 and generic-pool mocks with pg Pool mocks

Verification Results

Test Suites: 24 passed, 24 total
Tests:       352 passed, 352 total

Acceptance Criteria

  • Prisma schema updated to PostgreSQL -- Already migrated (provider = "postgresql")
  • Migrations re-generated for PostgreSQL -- Already generated (migration_lock.toml = "postgresql")
  • Docker-compose updated for local testing -- docker-compose.test.yml now uses PostgreSQL
  • Raw SQLite queries replaced with PostgreSQL -- All poolGet/poolRun/poolAll queries converted
  • Tests pass -- 352/352 tests passing

Impact

  • Unlocks row-level locking, high concurrency, and robust scaling for the database layer
  • Removes SQLite dependency entirely from the production code path
  • Maintains backward compatibility with existing Prisma-based queries

- Replace sqlite3 + generic-pool with pg (node-postgres) in src/db.js
- Convert all raw SQL queries from ? placeholders to  PostgreSQL syntax
- Replace COLLATE NOCASE with ILIKE for PostgreSQL case-insensitive search
- Update docker-compose.test.yml to use PostgreSQL instead of SQLite
- Replace sqlite3 dependency with pg in package.json
- Update all test mocks from sqlite3/generic-pool to pg Pool
- Add PostgreSQL-compatible error code handling (P2002 for unique constraints)
- Add NODE_ENV=test guard for schema init to prevent process.exit in tests

Closes Abdulazeem-code#502
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

@Chrogend is attempting to deploy a commit to the Abdulazeem's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Abdulazeem-code

Copy link
Copy Markdown
Owner

KINDLY RESOLVE CONFLICTS

…-postgresql

# Conflicts:
#	docker-compose.test.yml
#	stellar-payment-platform/package-lock.json
#	stellar-payment-platform/package.json
#	stellar-payment-platform/register-endpoint.test.js
#	stellar-payment-platform/register-multisigner.test.js
#	stellar-payment-platform/server.js
#	stellar-payment-platform/server.test.js
#	stellar-payment-platform/src/db.js
#	stellar-payment-platform/src/routes/v1/statsRoutes.js
#	stellar-payment-platform/src/routes/v1/webhookRoutes.js
#	stellar-payment-platform/src/webhookWorker.js
#	stellar-payment-platform/tests/helmet.test.js
#	stellar-payment-platform/tests/rate-limit.test.js
#	stellar-payment-platform/tests/sentry.test.js
@Abdulazeem-code
Abdulazeem-code merged commit a91e953 into Abdulazeem-code:main Aug 30, 2026
7 of 10 checks 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.

Migrate from SQLite/basic DB to PostgreSQL for production readiness

2 participants