Skip to content

feat(backend): migrate database from hardcoded SQLite to environment-based PostgreSQL configuration #243

@portableDD

Description

@portableDD

Description

app.module.ts hardcodes SQLite as the database with synchronize: true. SQLite files are wiped on every deployment on ephemeral hosting platforms (Render, Railway, Fly.io). ByteChain Academy cannot deploy to production until switched to environment-based PostgreSQL.

Background

Current config: type: 'sqlite', database: 'database.sqlite', synchronize: true

  • SQLite file lost on every restart on cloud hosting
  • synchronize: true in production risks dropping columns on deploy
  • No connection pooling, no SSL support

Required additions to .env.example

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_DATABASE=bytechain_academy
DB_SSL=false
NODE_ENV=development

Implementation Guide

Replace TypeOrmModule.forRoot with TypeOrmModule.forRootAsync using ConfigService. Read all DB settings from env vars. Set synchronize: true only when NODE_ENV !== 'production'. Enable SSL when DB_SSL === 'true' with rejectUnauthorized: false. Update e2e tests to use SQLite in-memory override so CI does not need a PostgreSQL instance.

Acceptance Criteria

  • TypeOrmModule.forRootAsync with env-based PostgreSQL config
  • synchronize: true only when NODE_ENV !== 'production'
  • All DB vars in .env.example with comments
  • Application connects to PostgreSQL when vars are set
  • E2e tests still work with SQLite in-memory override
  • npm run start:dev works with local PostgreSQL

Complexity: High - 200 points
Join: https://t.me/ByteChainAcademy | Contact: contact@nexacore.org

Metadata

Metadata

Labels

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