diff --git a/README.md b/README.md index 8f5b8ca..7c5c5d0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This repository now contains a two-container stack: - `frontend/` – a Next.js 14 web UI that reimplements the original single-page experience -- `backend/` – an Express API with Prisma + SQLite that provides authentication, base/category/defense CRUD, statistics, and image uploads +- `backend/` – an Express API with Prisma + PostgreSQL that provides authentication, base/category/defense CRUD, statistics, and image uploads Everything runs via Docker so you can deploy directly to Dokploy (or any Docker-based host). @@ -12,7 +12,9 @@ Everything runs via Docker so you can deploy directly to Dokploy (or any Docker- The Dokploy-oriented compose files assume production domains. For a local smoke test you can temporarily override the variables at runtime: ```bash -JWT_SECRET=dev-secret docker compose -f docker-compose.backend.yml up --build -d +JWT_SECRET=dev-secret \ +DATABASE_URL="postgresql://basenoter:basenoter@localhost:5432/basenoter?schema=public" \ +docker compose -f docker-compose.backend.yml up --build -d NEXT_PUBLIC_BACKEND_URL=http://localhost:4000 docker compose -f docker-compose.frontend.yml up --build -d ``` @@ -25,11 +27,12 @@ Default environment variables ship in `backend/.env.example`. Copy it (e.g. to ` **Persistent data** -The compose file provisions two named volumes: +The compose file provisions a single named volume: -- `backend-data` – stores the Prisma SQLite database (`/app/dev.db`) - `backend-uploads` – stores uploaded base layout images (`/app/uploads`) +Because the API now targets PostgreSQL, you must supply an external database connection string via the `DATABASE_URL` environment variable (e.g., through Dokploy secrets pointing at your managed Postgres instance). + ## Backend details (`backend/`) - Express 4 REST API @@ -43,7 +46,7 @@ Environment variables (see `.env.example`): | Variable | Purpose | |-------------------|----------------------------------------------| -| `DATABASE_URL` | Prisma connection string (default SQLite) | +| `DATABASE_URL` | Prisma connection string (PostgreSQL) | | `JWT_SECRET` | Secret for signing JWT auth cookies | | `FRONTEND_ORIGIN` | CORS allowlist (e.g. `http://localhost:3100`) | | `COOKIE_SECURE` | Set to `true` when serving over HTTPS | @@ -69,7 +72,7 @@ Steps: 2. In Dokploy create two Compose apps, each pointing to the respective file above. 3. Provide secrets for `JWT_SECRET` (backend) and any overrides you need; TLS-terminated installs should leave `COOKIE_SECURE` as `true`. 4. Dokploy's Traefik proxy will use the embedded labels to route the domains listed earlier. Adjust `entrypoints`/`certresolver` if your installation uses different names. -5. Configure persistent volumes for `/app/dev.db` and `/app/uploads`, or switch Prisma to an external database before deployment. +5. Configure the `DATABASE_URL` secret to point at your managed Postgres instance and mount the `backend-uploads` volume, or adjust the compose file to include a local Postgres service for testing. ## Development without Docker @@ -86,6 +89,14 @@ npm run dev Set `NEXT_PUBLIC_BACKEND_URL=http://localhost:4100` for the frontend. +For the backend, provide a PostgreSQL connection string such as: + +``` +DATABASE_URL="postgresql://basenoter:basenoter@localhost:5432/basenoter?schema=public" +``` + +When developing locally you can point this URL at any Postgres instance you manage (Docker Desktop, remote cloud database, etc.). + ## Image handling Uploaded base images are saved to `/app/uploads` inside the backend container and served at `http:///uploads/`. You can switch to an object store by swapping the Multer storage in `src/server.js`. diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index f853145..9376b7e 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -3,7 +3,7 @@ generator client { } datasource db { - provider = "sqlite" + provider = "postgresql" url = env("DATABASE_URL") } diff --git a/docker-compose.backend.yml b/docker-compose.backend.yml index 0e9b389..4292396 100644 --- a/docker-compose.backend.yml +++ b/docker-compose.backend.yml @@ -3,12 +3,11 @@ services: build: context: ./backend environment: - DATABASE_URL: file:./dev.db + DATABASE_URL: ${DATABASE_URL:?Set DATABASE_URL in Dokploy secrets} JWT_SECRET: ${JWT_SECRET:?Set JWT_SECRET in Dokploy secrets} FRONTEND_ORIGIN: https://basetracker.lona-development.org COOKIE_SECURE: "true" volumes: - - backend-data:/app/dev.db - backend-uploads:/app/uploads ports: - "4000:4000" @@ -22,5 +21,4 @@ services: - traefik.http.services.backend.loadbalancer.server.port=4000 volumes: - backend-data: backend-uploads: