chore: use shared postgres for family wishlist

This commit is contained in:
Vaka.pro
2026-04-25 17:25:28 +03:00
parent a7d5260ce3
commit 2adb03ff33
5 changed files with 46 additions and 42 deletions

View File

@@ -5,7 +5,7 @@ A small, private wishlist app for two users. Each user has their own profile, sl
- **Backend**: Node.js 20, Fastify 4, Prisma 5, PostgreSQL 16
- **Frontend**: React 18, Vite 5, Tailwind CSS, TanStack Query, React Hook Form + Zod
- **Monorepo**: pnpm workspaces
- **Deploy**: Docker Compose (Postgres + backend + nginx-served frontend)
- **Deploy**: Docker Compose (shared Postgres + backend + nginx-served frontend)
---
@@ -32,7 +32,7 @@ apps/
packages/
shared/ zod schemas + DTO types shared between backend and frontend
docker/ Dockerfiles + nginx.conf
docker-compose.yml prod stack (postgres + backend + frontend)
docker-compose.yml prod stack (shared postgres + backend + frontend)
docker-compose.dev.yml dev helper (postgres only)
.env.example full env template
```
@@ -127,10 +127,11 @@ Review the rest of `.env`:
- `USER1_USERNAME`, `USER1_SLUG`, `USER1_DISPLAY_NAME`
- `USER2_USERNAME`, `USER2_SLUG`, `USER2_DISPLAY_NAME`
- `POSTGRES_*` (used by Docker)
- `DB_HOST=postgres_budget`, `DB_PORT=5432`, `DB_NAME=db_family`
- `DB_USER`, `DB_PASSWORD`, `DATABASE_URL` (sensitive values stay only in `.env`)
- `PUBLIC_APP_URL` (used for CORS in production)
### 3. Run everything via Docker
### 3. Run the shared Docker stack
```bash
docker compose up --build
@@ -139,12 +140,18 @@ docker compose up --build
Opens:
- Frontend: http://localhost:8080
- Backend API: http://localhost:8080/api (proxied by nginx) or http://localhost:3000 if you map `backend`
- Postgres: internal only
- Backend API: http://localhost:8080/api (proxied by nginx) or http://localhost:3000 if you map `family-wishlist-backend`
Before first start, create a dedicated database and user for this project in the existing Postgres host:
- host: `postgres_budget`
- port: `5432`
- database: `db_family`
- user/password: set only in `.env` and do not commit them
On first start, the backend:
1. Runs `prisma db push` against the Postgres service (creates tables from `schema.prisma`; idempotent).
1. Runs `prisma db push` against the configured shared Postgres database (creates tables from `schema.prisma`; idempotent).
2. Seeds/upserts both users from env (public fields only — password hash stays in env).
3. Starts Fastify on port 3000.
4. Registers the daily trash-purge cron (runs at 03:17 UTC, also once on startup).
@@ -159,7 +166,7 @@ Run Postgres in a container, apps on the host:
```bash
docker compose -f docker-compose.dev.yml up -d
# Override DATABASE_URL to point to localhost:
# DATABASE_URL=postgresql://wishlist:change_me@localhost:5432/family_wishlist
# DATABASE_URL=postgresql://<DB_USER>:<DB_PASSWORD>@localhost:5432/db_family
pnpm --filter @family-wishlist/backend prisma:push # apply schema (first time and on schema changes)
pnpm --filter @family-wishlist/backend seed # upsert two users from env into DB
@@ -170,6 +177,9 @@ This starts both apps in parallel:
- Frontend: http://localhost:5173 (proxying `/api` and `/uploads` to http://localhost:3000)
- Backend: http://localhost:3000
- Dev Postgres: `localhost:5432` for local-only development data
The dev compose file stays isolated from the shared `postgres_budget` instance. Keep production credentials and local credentials in `.env`, and never hardcode them in compose files or source code.
### 5. Useful scripts