Skip to main content

Database Operations

Eve Horizon provides managed Postgres databases provisioned through your manifest, plus a full suite of CLI tools for migrations, schema inspection, SQL access, and credential management. Databases are scoped to environments -- each environment gets its own isolated tenant.

Managed database overview​

Managed databases are platform-provisioned Postgres instances declared in your manifest. Unlike regular services, managed DB services are not rendered into Kubernetes manifests -- the orchestrator provisions a tenant when you deploy an environment.

The provisioning lifecycle follows this flow:

Key characteristics:

  • Provisioning occurs on first deploy for each environment
  • Each environment gets an isolated database tenant
  • Credentials are managed by the platform and available via interpolation
  • Tenant connection URLs trust the platform-managed CA bundle; app code should not need rejectUnauthorized: false
  • Managed DB availability depends on platform configuration -- ask an admin if provisioning is disabled

Provisioning via manifest​

Declare a managed database as a service with x-eve.role: managed_db:

services:
db:
x-eve:
role: managed_db
managed:
class: db.p1
engine: postgres
engine_version: "16"

Configuration fields​

FieldRequiredDescription
roleYesMust be managed_db
classYesDatabase tier -- db.p1, db.p2, or db.p3
engineYesDatabase engine (currently postgres)
engine_versionNoEngine version (e.g., "16")
extensionsNoPostgres extensions to preload before app migrations
rolesNoLeast-privilege logins for app services (see Declared roles)

Extensions and TLS trust​

Managed Postgres can preload approved extensions for a tenant:

services:
db:
x-eve:
role: managed_db
managed:
class: db.p2
engine: postgres
extensions:
- pgcrypto
- vector

Eve gates extension names against the platform allowlist and applies them before app migrations run. Use this for extensions your schema requires at migration time.

For TLS, Eve injects database connection settings that trust the managed database CA. Client libraries should use normal certificate validation. Avoid disabling verification in application code; if a tenant URL fails TLS validation, treat it as a platform configuration issue and inspect the managed DB status.

Database tiers​

TierUse case
db.p1Development and testing
db.p2Staging and light production
db.p3Production workloads

Referencing managed values​

Other services reference managed database values using interpolation placeholders that are resolved at deploy time:

services:
db:
x-eve:
role: managed_db
managed:
class: db.p1
engine: postgres
engine_version: "16"
roles:
- name: app
grants: readwrite

api:
build:
context: ./apps/api
ports: [3000]
environment:
DATABASE_URL: ${managed.db.roles.app.url}
depends_on:
db:
condition: service_healthy
x-eve:
ingress:
public: true
port: 3000

The ${managed.<service>.<field>} syntax resolves to the provisioned values when the environment is deployed. Use eve db status to confirm tenant readiness before relying on managed values.

PlaceholderValue
${managed.db.url}Owner connection URL
${managed.db.host}, .port, .database, .username, .passwordParts of the owner credential
${managed.db.roles.<name>.url}Connection URL for a declared role
${managed.db.roles.<name>.username}, .passwordRole login and password

Declared roles​

Every managed database has one owner login. Declare extra least-privilege logins for app services with roles:

roles:
- name: app
grants: readwrite # SELECT, INSERT, UPDATE, DELETE in public
- name: reports
grants: readonly # SELECT in public
- name: auth
grants: { schema: auth, owner: true } # owns the auth schema (from 0.1.330)
  • readwrite and readonly cover tables and sequences in public, including ones the owner creates later, but cannot create objects. Run migrations with the owner URL in a role: job service.
  • A schema-owner role suits a component that runs its own migrations in its own schema, such as an auth server. It can create, change and drop objects in that schema and gets no grants of its own in public. The other roles get nothing in its schema; the owner can read it, so snapshots include it. The schema name is a plain lower-case identifier, never public, pg_* or information_schema, with one owner role.
  • A schema that already exists and is owned by the database owner is handed over to the role, with its objects, at the next deploy. Removing the role from the manifest hands the schema back to the owner before the login is dropped.
  • Role names match ^[a-z][a-z0-9_]{0,15}$, and a database declares at most 8 roles. Roles added later are created on the next deploy; removed roles are revoked and dropped.
  • eve db rotate-credentials rotates every role's password with the owner's, eve db destroy drops the roles, and eve db reset resets public only, so an owned schema is kept.
  • eve db status --env <env> lists declared and provisioned roles (names and logins, never passwords).
  • Roles need the local managed database provider.
Owner URL under the strict profile

Under the strict security profile, a long-running service whose environment, command or entrypoint reads ${managed.<db>.url} or ${managed.<db>.password} is refused at deploy, naming the declared-role form ${managed.<db>.roles.<role>.url}. Job services (x-eve.role: job, such as migrations) still receive the owner credential, and the non-secret parts (host, port, database, username) are unaffected.

Connection limits​

On every security profile:

  • Each managed database accepts only its own logins.
  • Each login (the owner and each role) gets its class's connection limit unless it already has one: 25 for db.p1, 100 for db.p2 and 200 for db.p3. A limit an operator set on a login is never changed.
  • The database as a whole gets its class maximum plus 5 connections reserved for Eve's own work (30, 105 or 205). This is set only when the database has no limit, so a limit an operator set, lower or higher, is kept.

Size each service's connection pool within its login's limit. When a login or the database runs near its limit, scale to a larger class with eve db scale.

Database status and credentials​

Checking status​

Verify that your managed database is provisioned and ready:

eve db status --env staging

This shows the provisioning state, connection details, and health of the managed database for the specified environment.

Credential rotation​

Rotate database credentials when needed for security compliance:

eve db rotate-credentials --env staging

After rotation, redeploy services that reference managed database values so they pick up the new credentials. Rotation covers the owner and every declared role.

Migrations​

Eve ships a purpose-built migration container image with each platform release, ghcr.io/eve-horizon/eve-horizon/migrate:<version> (for example 0.1.332), for database migrations. It is signed like the platform images and runs as a numeric non-root user. Pin the version of the platform you run.

Creating a new migration​

eve db new create_users_table

This creates a new migration file under db/migrations/ with the naming convention YYYYMMDDHHmmss_create_users_table.sql. The timestamp prefix ensures migrations execute in the correct order.

You can specify a custom migrations directory:

eve db new create_users_table --path db/custom-migrations

Migration file conventions​

Eve-migrate expects:

  • db/migrations/ directory for migration files
  • Timestamped names: YYYYMMDDHHmmss_description.sql
  • Regex: /^(\d{14})_([a-z0-9_]+)\.sql$/
  • One file = one migration (multiple SQL statements allowed)

Behavior:

  • Each migration runs in its own transaction.
  • schema_migrations tracks name, checksum, and applied_at.
  • SHA256 checksums prevent silent drift after a migration has run.
  • pgcrypto and uuid-ossp extensions are installed when needed.
  • Baseline migration behavior handles pre-existing schema objects safely.

Running migrations​

Apply pending migrations to an environment:

eve db migrate --env staging

To use a custom migrations path:

eve db migrate --env staging --path db/migrations

Migration commands with direct URLs​

All migration commands support --url to bypass managed DB resolution:

eve db migrate --url "postgres://app:app@localhost:5432/myapp" --path db/migrations
eve db migrations --url "postgres://app:app@localhost:5432/myapp"

Listing applied migrations​

View which migrations have been applied:

eve db migrations --env staging

Migration as a pipeline step​

For automated workflows, you can run migrations as a pipeline step using a service with x-eve.role: job:

services:
migrate:
image: ghcr.io/eve-horizon/eve-horizon/migrate:0.1.332
environment:
DATABASE_URL: ${managed.db.url} # owner URL: allowed in job services
MIGRATIONS_DIR: /migrations
x-eve:
role: job
files:
- source: db/migrations
target: /migrations

pipelines:
deploy:
steps:
- name: build
action: { type: build }
- name: release
depends_on: [build]
action: { type: release }
- name: migrate
depends_on: [release]
action: { type: job, service: migrate }
- name: deploy
depends_on: [migrate]
action: { type: deploy }

This ensures migrations run before the application deploy step, and the pipeline fails if the migration fails.

To use a custom migration engine (for example Flyway), keep the same x-eve.files mount and replace image/command:

services:
migrate:
image: flyway/flyway:10
command: >-
-url=${DATABASE_URL}
-locations=filesystem:/migrations
migrate
x-eve:
role: job
files:
- source: db/migrations
target: /migrations

Local migration workflow​

For local compose stacks:

# docker-compose.yml
migrate:
image: ghcr.io/eve-horizon/eve-horizon/migrate:0.1.332
environment:
DATABASE_URL: postgres://app:app@db:5432/myapp
volumes:
- ./db/migrations:/migrations:ro
depends_on:
db:
condition: service_healthy
docker compose run --rm migrate
docker compose down -v && docker compose up -d db && docker compose run --rm migrate # reset

Schema management​

Inspecting the schema​

View the current database schema for an environment:

eve db schema --env staging

To scope to a specific project:

eve db schema --env staging --project proj_xxx

Row-level security​

Inspect the RLS policies configured on your database:

eve db rls --env staging

This shows all active row-level security policies, which tables they apply to, and the policy expressions.

Initialize or refresh the default RLS scaffolding:

eve db rls init --env staging --with-groups

SQL access​

The eve db sql command provides direct SQL access to environment databases. This is useful for ad hoc queries, debugging, and data inspection.

Read queries​

# Inline query
eve db sql --env staging --sql "SELECT count(*) FROM users"

# Query from a file
eve db sql --env staging --file ./queries/user-report.sql

Write queries​

Write operations require the --write flag as a safety measure:

eve db sql --env staging --sql "UPDATE users SET active = true WHERE id = 42" --write
warning

The --write flag is a safety gate, not a permission check. Always verify your SQL before running write operations against production environments.

SQL access patterns​

PatternCommand
Quick counteve db sql --env staging --sql "SELECT count(*) FROM orders"
Table inspectioneve db sql --env staging --sql "SELECT * FROM users LIMIT 10"
Report from fileeve db sql --env staging --file ./reports/monthly.sql
Data fixeve db sql --env staging --sql "UPDATE ..." --write

Scaling​

Scale a managed database to a different tier:

eve db scale --env staging --class db.p2

This changes the database tier for the specified environment. The operation may involve a brief maintenance window depending on the platform configuration.

Database wipe​

Wipe drops and recreates the database without running migrations:

eve db wipe --env staging --force

Both reset and wipe support direct URL mode for non-managed databases:

eve db reset --url "postgres://app:app@localhost:5432/myapp" --force
eve db wipe --url "postgres://app:app@localhost:5432/myapp" --force

Snapshots and restore​

Eve provides per-tenant database snapshots backed by pg_dump and stored in S3. Snapshots give you point-in-time backups at the individual database level -- no need to touch the underlying RDS instance or affect other tenants.

Creating a snapshot​

eve db snapshot --env production

This runs pg_dump against the environment's managed database and streams the output directly to S3. The snapshot uses the custom format with compression for efficient storage and fast restores.

Override the default retention period for a one-off snapshot:

eve db snapshot --env production --retention 90d

Listing and inspecting snapshots​

# List all snapshots for an environment
eve db snapshots --env production

# Filter by status
eve db snapshots --env production --status completed --limit 10

# Show full details for a specific snapshot
eve db snapshot show <snapshot_id>

Restoring from a snapshot​

Restore overwrites the current database with the contents of a snapshot:

eve db restore --env staging --snapshot <snapshot_id> --force

Before restoring, the platform automatically creates a safety snapshot of the current state (so you can roll back if the restore was a mistake). Skip this with --skip-safety-snapshot if you don't need it.

Cross-environment restore is supported -- restore a production snapshot into staging for debugging:

eve db restore --env staging --snapshot <snapshot_id> --source-env production --force
warning

Restore terminates all active connections to the target database. Coordinate with your team before restoring production environments.

Deleting a snapshot​

eve db snapshot delete <snapshot_id> --force

Backup schedule and status​

Check the current backup configuration and last snapshot time for an environment:

eve db backup-status --env production

This shows the schedule, retention policy, last and next snapshot times, and whether snapshot-on-delete is enabled.

Automatic snapshots​

Production-class databases (db.p2 and db.p3) get automatic protection out of the box:

TierDefault ScheduleDefault RetentionSnapshot-on-DeleteSnapshot-on-Reset
db.p1Off (opt-in)7 daysOffOff
db.p2Daily at 02:00 UTC30 daysOnOn
db.p3Daily at 02:00 UTC90 daysOnOn

Configure backup settings in your manifest under the managed DB service:

services:
db:
x-eve:
role: managed_db
managed:
class: db.p2
engine: postgres
engine_version: "16"
backup:
schedule: "0 2 * * *" # Cron expression (daily at 02:00 UTC)
retention: 30d # How long to keep snapshots
snapshot_on_delete: true # Snapshot before eve db destroy
snapshot_on_reset: true # Snapshot before eve db reset

Override per environment for tighter production schedules:

environments:
production:
overrides:
services:
db:
x-eve:
managed:
backup:
schedule: "0 */6 * * *" # Every 6 hours
retention: 90d

To explicitly disable automatic snapshots on a production-class tier:

backup:
schedule: false
snapshot_on_delete: false

Snapshot portability​

Snapshots are standard pg_dump custom-format files. You can download them and restore to any Postgres instance outside Eve:

# Download a snapshot
eve db snapshot download <snapshot_id> --output ./backup.dump

# Restore with standard pg_restore -- no Eve required
pg_restore --clean --if-exists --no-owner --no-acl \
-d postgres://user:pass@host:5432/mydb ./backup.dump

Database reset and destroy​

Resetting a database​

Reset drops and recreates the database, then runs migrations:

eve db reset --env staging --force

On database tiers with snapshot-on-reset enabled (db.p2+ by default), a safety snapshot is created before the reset. Skip it with --skip-snapshot:

eve db reset --env staging --force --skip-snapshot

Destroying a managed database​

Remove a managed database tenant from an environment:

eve db destroy --env staging --force

The --force flag is required to confirm destruction. On database tiers with snapshot-on-delete enabled (db.p2+ by default), a safety snapshot is created before the destroy. Skip it with --skip-snapshot:

eve db destroy --env staging --force --skip-snapshot
danger

Database destruction is irreversible. Without --skip-snapshot, a safety snapshot is created automatically on production-class tiers, but always verify your backup strategy before destroying a database.

Admin APIs​

Platform administrators can manage managed database instances directly:

EndpointMethodPurpose
/admin/managed-db/instancesGETList all managed DB instances
/admin/managed-db/instancesPOSTRegister a new instance
/admin/managed-db/instances/:idGETGet instance details

Per-environment tenant endpoints:

EndpointMethodPurpose
/projects/:id/envs/:env/db/managedGETGet tenant status
/projects/:id/envs/:env/db/managed/rotatePOSTRotate credentials
/projects/:id/envs/:env/db/managed/scalePOSTChange tier
/projects/:id/envs/:env/db/managedDELETEDestroy tenant

Snapshot and restore endpoints:

EndpointMethodPurpose
/projects/:id/envs/:env/db/snapshotsPOSTCreate a snapshot
/projects/:id/envs/:env/db/snapshotsGETList snapshots
/projects/:id/envs/:env/db/snapshots/:sidGETShow snapshot details
/projects/:id/envs/:env/db/snapshots/:sidDELETEDelete a snapshot
/projects/:id/envs/:env/db/snapshots/:sid/downloadGETGet signed download URL
/projects/:id/envs/:env/db/restorePOSTRestore from a snapshot
/projects/:id/envs/:env/db/backup-statusGETBackup schedule and status

CLI reference​

Most eve db commands accept --url <postgres-url> as an alternative to --env for direct connection mode.

CommandPurpose
eve db status --env <name>Check managed DB provisioning state
eve db status --url <postgres-url>Check DB status for direct URL mode
eve db schema --env <name>Inspect database schema
eve db schema --url <postgres-url>Inspect schema for direct URL
eve db rls --env <name>View row-level security policies
eve db rls --url <postgres-url>View RLS policies for direct URL
eve db rls init --env <name> --with-groupsBootstrap RLS scaffolding for groups
eve db rls init --url <postgres-url> --with-groupsBootstrap RLS scaffolding in direct URL mode
eve db sql --env <name> --sql "..."Execute read query
eve db sql --env <name> --sql "..." --writeExecute write query
eve db sql --env <name> --file ./query.sqlExecute query from file
eve db sql --url <postgres-url> --sql "..."Execute read query in direct URL mode
eve db migrate --env <name>Run pending migrations
eve db migrate --url <postgres-url>Run pending migrations for direct URL mode
eve db migrations --env <name>List applied migrations
eve db migrations --url <postgres-url>List applied migrations for direct URL mode
eve db new <description>Create new migration file
eve db new <description> --path <dir>Create migration in custom local path
eve db rotate-credentials --env <name>Rotate database credentials
eve db reset --env <name> --forceDrop/recreate and rerun migrations
eve db reset --env <name> --force --skip-snapshotReset without creating a safety snapshot
eve db reset --url <postgres-url> --forceDrop/recreate direct URL and rerun migrations
eve db wipe --env <name> --forceDrop/recreate without migration replay
eve db wipe --url <postgres-url> --forceDrop/recreate direct URL without migration replay
eve db scale --env <name> --class <tier>Change database tier
eve db snapshot --env <name>Create a point-in-time snapshot
eve db snapshot --env <name> --retention 90dCreate snapshot with custom retention
eve db snapshot show <snapshot_id>Show snapshot details
eve db snapshot delete <snapshot_id> --forceDelete a snapshot
eve db snapshot download <snapshot_id> --output <path>Download snapshot as a portable dump file
eve db snapshots --env <name>List all snapshots for an environment
eve db snapshots --env <name> --status completedList snapshots filtered by status
eve db restore --env <name> --snapshot <id> --forceRestore database from a snapshot
eve db restore --env <name> --snapshot <id> --source-env <env> --forceCross-environment restore
eve db backup-status --env <name>Show backup schedule and status
eve db destroy --env <name> --forceRemove database tenant
eve db destroy --env <name> --force --skip-snapshotDestroy without creating a safety snapshot

See CLI Commands for the full command reference.