Move the database to Postgres #2
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #1. This comes first: the teams work adds a team column to nearly every table, so doing Postgres first means those migrations are written once, for one database.
Today
modernc.org/sqlite) on a PVC,SetMaxOpenConns(1)and WAL (internal/db/db.go).database/sql, no ORM.internal/db/migrations/001..010_*.sql, tracked inschema_migrations.Scope
TERDUT_DB_DSNreplacesTERDUT_DB_PATHininternal/config/config.go.internal/db/db.goopens Postgres (pgx) with a sane pool, dropping the single-connection limit.001_baseline.sql; timestamps stay BIGINT epochs, the JSON columns becamejsonb.internal/api/for?placeholders (become$1),RETURNINGsupport and anyLIMIT/OFFSETdifferences. 170 placeholders, plus four things a search and replace would not have caught — see the commit message.TERDUT_TEST_DSNsays where,make test-dblocally and a service container inci.yaml. An unset DSN fails rather than skips.scripts/that reads the SQLite file and writes Postgres, run by hand once and then deleted. The binary gets no subcommand.pvc.yaml, drop the backup sidecar fromvalues.yaml, take a DSN (with the password from a Secret).Ryuvia/charts: anacid.zalan.do/v1 postgresqlCR with ak8up.io/backupcommand: pg_dumpannotation, followinggitea/templates/postgres.yamlandimmich, rework the k8up schedule off the SQLite dump, and open the network policy to Postgres.Notes
go.moduntil the migration script is deleted. Remove both once this install is migrated, so it doesn't become permanent.Done when
A fresh install comes up against Postgres ✅, the existing SQLite data is migrated with no loss,
make fmt lint test helm-lintis green ✅, and a k8up backup produces a restorable pg_dump.Deployed and verified in the cluster, 2026-09-20.
Ryuvia/charts#231merged, Flux reconciled, and the namespace is on Postgres:Verified, each from a command that ran:
public,schema_migrationsholds001_baseline.sql./api/alertmanager/webhookand got 200, and the row landed: 1 alert, 0 incidents, which is correct because the alert is Watchdog and Watchdog is a dead man's switch.Backupselectedterdut-server-postgres-0, ran thepg_dump --cleanbackupcommand from its annotation and streamed it to restic as/terdut-server-postgres.sql—new files: 1, errors: 0, bytes processed: 58932. Only the database pod contributed; the app pod carries no annotation and holds no data.The data migration was deliberately skipped. This install is not production, and the decision was to let the server bootstrap a fresh database rather than carry the old rows across.
scripts/sqlite-to-postgres.gowas still verified end to end before the release, against a SQLite database built at the old schema and seeded in every table.Two things left behind, neither harmful:
pvc-c5ef5aa7-017d-4550-ab93-c17f640e0c1f(1Gi,Released,Retain) still holds the old SQLite database. Helm deleted theterdut-server-dataPVC whenpvc.yamlleft the chart — a template removal deletes the live object, which is worth knowing for any future chart that drops a volume. The data survived only because the storage class retains. Delete it when you are sure you want it gone.modernc.org/sqlitedependency are still in the tree. They exist for an upgrade that is now not going to happen here, so they can be deleted whenever — that is the follow-up this issue's note asked for.Two dead tags for the record: v0.11.0 published nothing (release.yaml's test job had no database; fixed in
a8ee742), alongside v0.10.0 and v0.10.1. The shipped version is v0.11.1.