A local nutrition tracking app powered by AI
YuHeng uses PostgreSQL as its primary database, with schema versioning managed by node-pg-migrate.
The database layer is located in lib/db/:
interface.ts: Defines the DatabaseAdapter interface.index.ts: The main entry point that initializes the PostgreSQL adapter.postgres.ts: Implementation of the DatabaseAdapter using postgres (via pg).YuHeng requires a PostgreSQL connection string to be set via environment variables:
DATABASE_URL: PostgreSQL connection string (required)Example connection string:
DATABASE_URL=postgresql://user:password@localhost:5432/yuheng
db object.YuHeng uses node-pg-migrate for database schema version management. This allows for:
# Run pending migrations
npm run db:migrate
# Rollback last migration
npm run db:migrate:down
# Create a new migration
npm run db:migrate:create migration-name
To set up PostgreSQL for local development:
docker-compose up -d
npm run db:migrate
npm run dev
The application will automatically connect to the PostgreSQL database using the connection string from .env.