Databases from the API and CI
Everything the console does with a managed database is on the API, so you need no extra tooling. The samples use the helper from Using the Zaroz API ($ZAROZ_API and $AUTH) and jq. $DB is the database's service instance id: the id in the console address of the database, or the service_instance_id your purchase returned.
Use an API token scoped to one project, holding only the permissions the script needs. Revealing or rotating the password counts as operating the database, so a token that only reads cannot do it.
Operations
Changes that take time (a backup, a restore, an export, a rotation, an upgrade) answer 202 with an operation. Poll it until its state is succeeded, failed or cancelled:
Code
progress (0 to 100) and phase say how far it got. A failed operation says whether it was rolled back (rolled_back) and whether retrying is safe (retryable).
Create a database
A managed database is bought like any other product (Subscriptions and billing). Send an Idempotency-Key header on the purchase so a retried request never buys twice. When the service is ready, GET /service-instances/$DB/database describes it: engine, version, copies, health and what it supports.
Connection details and the password
Code
Every reveal is recorded on the database's timeline and in your organization's audit log. Prefer linked variables for apps on Zaroz (Connect an app to a managed database): the app gets the password without anyone reading it.
Rotate the password
Code
grace is how long the old password keeps working: none (it stops at once), one_hour or twenty_four_hours. Restart the apps that use the database within that time; linked variables pick up the new password on restart.
Back up and wait
Code
Export and download
Code
PostgreSQL exports as sql, sql_gz or pg_custom (the format pg_restore reads). The file is kept for seven days; each call to /link gives a fresh download address valid for 24 hours.
Allow a source address
From outside Zaroz, a database with public access can be limited to the addresses you list:
Code
GET .../network shows public access, the rules and how many you may add (max_rules). Apps in the same project never need a rule.
Read the timeline
Code
The timeline holds lifecycle changes, operations, health changes, maintenance, backups and access (password viewed or rotated, users, network changes). Filter with kinds= (comma-separated) and page with the next cursor (after_created_at and after_id). An event never carries a password.
Databases in CI
Tests: use a throwaway database
Run your tests against a database container that lives as long as the CI job, not against a managed database. It is faster, free, and a test can never touch real data. GitHub Actions:
Code
Forgejo Actions and GitLab CI accept the same services: idea; see CI overview.
Migrations on deploy
Run migrations against the managed database as a step of your deploy, with a backup just before it:
Code
A restore can itself be undone for a while (POST .../restore/undo), so trying one is safe.
Reaching the database from a CI runner
A CI runner is outside Zaroz. Either turn on public access and add the runner's outgoing address range as an allowed source, or run the migration from inside your project (for example as a step of the app's start command, or a job on Zaroz), where no rule is needed.
