feat(deploy): auto-run db migrations + seed on stack deploy

Add a migrator Dockerfile target (drizzle-kit migrate + tier-definitions
seed, both idempotent) and wire it as a one-shot compose service that web
waits on via service_completed_successfully. No more manual exec step
after first deploy — runs safely on every redeploy.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-01 16:23:54 +02:00
parent 4a90ad910c
commit a4fb62c86c
3 changed files with 25 additions and 9 deletions
+5 -7
View File
@@ -29,14 +29,12 @@ OPENROUTER_API_KEY=
5. Deploy the stack. Portainer builds `web` from the repo's root `Dockerfile` (see `build:` in compose.prod.yml) — no separate image push needed.
6. Enable GitOps updates (webhook or polling) on the stack if you want redeploy-on-push.
## First deploy: run migrations + seed
## Migrations + seed
Compose does not auto-migrate. After the stack is up, exec into the `web` container once (or run a one-off container against the same network) with `DATABASE_URL` set, then:
```bash
pnpm db:migrate
pnpm db:seed # tier definitions — first deploy only
```
Handled automatically. The `migrate` service builds from the `migrator` Dockerfile target,
runs `drizzle-kit migrate` then the tier-definitions seed, and exits; `web` waits for it to
complete successfully before starting (`depends_on: migrate: condition: service_completed_successfully`).
Both are idempotent — safe to re-run on every stack redeploy, not just the first one.
## Traefik (separate LXC, file provider)