Skip to content

Backend: Add PostgreSQL support as alternative to SQLite #284

@joelpeace48-cell

Description

@joelpeace48-cell

Summary

The backend uses SQLite via the DAL abstraction (backend/src/dal/). SQLite is great for development and single-instance setups but is unsuitable for production deployments that require horizontal scaling, concurrent writes at volume, or managed cloud database hosting. The DAL abstraction already separates repository interfaces from implementations — adding a PostgreSQL backend is the natural next step.

Problem

  • SQLite has limited concurrent write throughput (WAL mode helps but doesn't eliminate the bottleneck)
  • No native replication or failover
  • Incompatible with multi-instance (horizontal) deployments
  • Cloud platforms (Railway, Render, Fly.io) recommend PostgreSQL for persistent workloads

Acceptance Criteria

  • Create backend/src/dal/pgCampaignRepository.js and backend/src/dal/pgAuditLogRepository.js implementing the same interfaces as the SQLite versions
  • Use pg (node-postgres) or @databases/pg as the database client
  • Add a DATABASE_URL env variable; when present and prefixed with postgres://, use the PG implementation
  • Add SQL migration files in backend/src/db/migrations/ compatible with both SQLite and PostgreSQL schemas
  • Add integration tests using a real PostgreSQL instance (can use Docker in CI)
  • Update backend/.env.example with PostgreSQL configuration examples
  • Update compose.yaml to add an optional postgres service profile (like the existing redis profile)
  • Document PostgreSQL setup in backend/README.md

References

  • backend/src/dal/index.js — DAL factory
  • backend/src/dal/sqliteCampaignRepository.js — reference implementation
  • compose.yaml — Docker Compose for adding postgres service
  • backend/.env.example

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programarea: backendBackend API (Node/Express)difficulty: hardLarger or subtle changesinfraDeployment, docker, runtimemainnetCritical for mainnet launchperformancePerf and scalability

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions