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>
14 lines
584 B
Plaintext
14 lines
584 B
Plaintext
|
|
## 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}}`.
|