Files
ilkerandClaude Opus 5.5 8556a50e94
ci / derle (push) Failing after 34s
hpcod: DEPLOY.md, and the changelog for v0.2.0
How someone else installs hpcod: the binary, sudo hpcod setup, what it
asks and what each step does, the simulated Proxmox, a closed network
with its own CA and DNS, verify, selftest, and what to back up. The
changelog says what was proven and what was not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:20:10 +01:00

43 lines
1.9 KiB
Markdown

# Control plane database
The numbered files are the schema, applied in order by
`hpcod setup` (the schema step), which runs on every deploy. The files are
embedded in the binary, so a binary always applies its own schema. Nothing
records which files have run: every one of them is applied every time.
**So every migration must be idempotent**: `IF NOT EXISTS`, `OR REPLACE`,
`ADD COLUMN IF NOT EXISTS`. A file that is not idempotent fails the second
deploy after it is added.
The DSN is not in this repository. It lives on the database host in
`/etc/hpcod/db.env` (mode 0640, root:hpcod) as `HPCOD_DB_DSN`, which is also
where the service reads it from.
## Running the store tests
`internal/store` is tested against a real PostgreSQL, because what it relies
on - a partial unique index, a generated column, an advisory lock - is
database behaviour that a fake would not reproduce. The tests skip unless
`HPCOD_TEST_DSN` is set.
Each test builds the schema in a scratch schema of its own and drops it
afterwards, and refuses to run if `current_schema()` is not that scratch
schema. So the DSN may point at the production database: the tests cannot
see or touch the clusters recorded there.
PostgreSQL listens on loopback only, so the tests run where it does. Ship a
cross-compiled binary rather than installing a Go toolchain on that host:
```bash
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go test -c -o store.test ./internal/store/
ssh $DBHOST mkdir -p /tmp/hpcodstore/internal/store /tmp/hpcodstore/db
scp store.test $DBHOST:/tmp/hpcodstore/internal/store/
scp db/001-schema.sql $DBHOST:/tmp/hpcodstore/db/
ssh $DBHOST "cd /tmp/hpcodstore/internal/store && \
sudo sh -c 'set -a; . /etc/hpcod/db.env; set +a; \
HPCOD_TEST_DSN=\"\$HPCOD_DB_DSN\" ./store.test -test.v'"
ssh $DBHOST rm -rf /tmp/hpcodstore
```
The password never leaves the host: the DSN is read from the env file there.