Database migrations
Auto-migration on boot
Section titled “Auto-migration on boot”By default, the brain runs pending migrations on start. This is idempotent and safe to leave on.
Disable with Z4J_AUTOMIGRATE=false - then run migrations manually.
Manual migration
Section titled “Manual migration”docker run --rm \ -e Z4J_DATABASE_URL=... \ z4jdev/z4j:v1.0.0 z4j-brain migrateOr inside an existing container:
docker exec -it z4j-brain z4j-brain migrateStatus
Section titled “Status”z4j-brain migrate --statusLists applied / pending revisions.
Forward-only policy
Section titled “Forward-only policy”Migrations are forward-only. We don’t ship downgrade scripts. If you need to roll back, restore Postgres from backup.
Multi-replica (v1.1+)
Section titled “Multi-replica (v1.1+)”For N-replica deploys, run migrations from a one-shot job before rolling out the new brain image:
# kubernetes exampleapiVersion: batch/v1kind: Jobmetadata: name: z4j-migrate-v1-1-0spec: template: spec: containers: - name: migrate image: z4jdev/z4j:v1.1.0 command: ["z4j-brain", "migrate"] env: [...] restartPolicy: NeverThen update the Deployment’s image.
Schema reference
Section titled “Schema reference”See database schema for the authoritative table + column list.
Underlying tool
Section titled “Underlying tool”Alembic (SQLAlchemy 2.0). Revisions live in packages/z4j-brain/backend/alembic/versions/. Each revision includes a descriptive message and never loses data without explicit, commented-out intent.