Logo

Sharing Excess

Food Rescue Platform
For DevelopersShared Packages

Database Package (packages/db)

Drizzle ORM schema and utilities for Neon PostgreSQL.

Structure

  • src/db.schema.ts — All enums, tables, relations
  • src/utils/dbml.ts — Generates DBML and assets (consumed by server Docker build)
  • drizzle.config.ts — CLI config: schema path, dialect, credentials from DATABASE_URL

Schema highlights (src/db.schema.ts)

  • Enums from @sharingexcess/types for partner types/categories, rescue/transfer types/statuses, user permissions, location hour types
  • Tables: users, partners, locations, rescues, transfers, wholesale_markets, location_hours, location_tags, partner_images, partner_tags
  • Constraints: soft-deletes on primary entities; check constraints (e.g., day_of_week in range)
  • Relations declared via relations(...)

Generation pipeline

  • Server Docker build runs bun run generate_schema_files in this package to produce static assets: DBML/HTML/SVG under server assets/ (served at /schema* routes)

Migrations

  • Managed via Drizzle Kit push commands from root scripts (db_push:<env>), using drizzle.config.ts
  • Schema-first; avoid divergent migration files; use extreme caution in production