No description
- TypeScript 74.7%
- JavaScript 18.1%
- HTML 5.1%
- CSS 1.6%
- Shell 0.5%
## Ticket [IRRIGOAPI-117](http://192.168.2.100:7123/home/browse/IRRIGOAPI-117/) API silently dies if Postgres isn't ready at boot (host reboot race + bun --watch masks crash) After the 2026-09-26 host reboot, the API hit Postgres `57P03` in `verifyMigrations` and threw uncaught. `bun --watch` kept the dead process alive, and with no healthcheck the container sat "Up" with nothing on 9753 for ~3.5h. ## Summary - `waitForDbReady` (`api/db/wait-for-db-ready.ts`): bounded 60s `select 1` probe before `verifyMigrations`. It retries transient SQLSTATE/socket errors (`57P03`, `ECONNREFUSED`, Docker DNS `ESERVFAIL`/`ENOTFOUND`, …) and throws on timeout or a non-transient error. - New shared `findPgErrorCause` (`api/db/pg-error.ts`) walks `.cause`, because Drizzle's `db.execute` wraps driver errors in `DrizzleQueryError` without copying `.code`. It also fixes a latent bug: verify-migrations' "not migrated" (42P01/3F000) branch was unreachable in production. - `runMain` (`api/run-main.ts`) is now the single startup exit point. Any startup error is logged and ends in `exit(1)`. `bootstrap` no longer calls `process.exit` itself. - docker-compose: `command: ${API_COMMAND:-bun start}`. The live stack runs without the file watcher, so a crash exits and `restart: unless-stopped` recovers it. Worktrees opt into hot reload with `API_COMMAND=bun run dev` (documented in `.env.example` and `CLAUDE.md`). - docker-compose: a Bun-fetch healthcheck on `127.0.0.1:9753/health` (the image has no curl/wget) with `start_period` 120s, plus the `autoheal=true` label. - Live-verified on the primary stack: - `docker restart irrigo-db irrigo-api` → the API recovers unaided and reaches healthy. - DB stopped → retries for ~60s, then `"startup: fatal error, exiting"`, and the container cycles instead of sitting Up. After DB start it recovers. - Tests 1090/1090 and type-check pass. - Operational note: the primary stack no longer hot-reloads. Run `docker restart irrigo-api` after editing `api/` code there. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #15 |
||
|---|---|---|
| .claude | ||
| .devcontainer | ||
| .forgejo/workflows | ||
| .vscode | ||
| api | ||
| app | ||
| shared | ||
| .env.example | ||
| .gitignore | ||
| build-apk.sh | ||
| CLAUDE.md | ||
| docker-compose.yml | ||
| Dockerfile.dev | ||
| Dockerfile.metro | ||
| migrate.sh | ||
| seed.sh | ||