coreapp new --postgres: apps with their own database

A template overlay (templates/postgres) adds DEPENDS="postgresql", DB_*
settings with a random password, an install that creates the user and
database on the Core's PostgreSQL (safe to re-run), an uninstall that
drops them, and a Python example that counts visits. Tested with a
throwaway app: deploy, redeploy and a reboot of the Core keep the data,
remove drops the database and user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:06:55 -07:00
co-authored by Claude Opus 5.5
parent 1108060432
commit 74bdc13f0f
12 changed files with 211 additions and 9 deletions
+13
View File
@@ -0,0 +1,13 @@
## Database
The app has its own database on the Core's shared PostgreSQL
(`DEPENDS="postgresql"` in `service`):
- `install` creates the user and database `{{DBNAME}}`, with the random
`DB_PASSWORD` from `.env`; `uninstall` drops both (`coreapp remove`
deletes the data).
- The app reads `DB_HOST` (`postgresql.<domain>`, which only resolves on the
Core's `core` network), `DB_PORT`, `DB_NAME`, `DB_USER` and `DB_PASSWORD`
from its environment. `app.py` shows how, with `psycopg`.
- Look at the data: `coreapp-vm ssh docker exec -it postgresql psql -U postgres {{DBNAME}}`.