YuHeng (玉衡)

A local nutrition tracking app powered by AI

View the Project on GitHub formaxcn/yuheng

Database Adapter

YuHeng uses PostgreSQL as its primary database, with schema versioning managed by node-pg-migrate.

Architecture

The database layer is located in lib/db/:

Database Configuration

YuHeng requires a PostgreSQL connection string to be set via environment variables:

Example connection string:

DATABASE_URL=postgresql://user:password@localhost:5432/yuheng

Features

Schema Versioning

YuHeng uses node-pg-migrate for database schema version management. This allows for:

Running Migrations

# 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

Local Development

To set up PostgreSQL for local development:

  1. Start PostgreSQL using Docker Compose:
    docker-compose up -d
    
  2. Run database migrations:
    npm run db:migrate
    
  3. Start the development server:
    npm run dev
    

The application will automatically connect to the PostgreSQL database using the connection string from .env.