Skip to main content

schemabrain apply

Walks an on-disk project tree and applies each subdirectory’s YAML files to the store. The tree shape mirrors what schemabrain init --emit-yaml-dir and schemabrain {entities,metrics,joins} export-all produce, so the full store ↔ YAML round-trip closes here.
schemabrain apply ./schemabrain --url-env DATABASE_URL
Expected layout:
<project_dir>/
├── entities/
│   ├── users.yaml
│   └── orders.yaml
├── metrics/
│   └── daily_revenue.yaml
└── joins/
    └── user_orders.yaml
Missing subdirectories are skipped cleanly. The walker applies in a deliberate order — entities first, then metrics and joins which reference entities. The per-resource apply commands enforce FK invariants internally, so a broken reference fails the inner command and surfaces in the outer summary; the outer walker does not abort on a single bad file.

Flags

Argument / FlagDefaultPurpose
project_dir (positional)./schemabrainPath to the project tree.
--source URL(none)Source URL the YAMLs attach to. Deprecated when the URL contains a password.
--url-env VARNAME(none)Env var holding the source URL. Preferred.
--store-path PATH./schemabrain.dbPath to the local SQLite store.

How it relates to per-resource apply

You want to …Use
Apply a whole project treeschemabrain apply <dir>
Apply one entity fileschemabrain entities apply <file>
Apply one metric fileschemabrain metrics apply <file>
Apply one join fileschemabrain joins apply <file>
The top-level apply is a convenience over the three per-resource apply commands; it never does anything the per-resource commands can’t.

Examples

Round-trip: snapshot the store to disk, then re-apply

# Snapshot
schemabrain entities export-all --dir ./schemabrain/entities
schemabrain metrics export-all  --dir ./schemabrain/metrics
schemabrain joins export-all    --dir ./schemabrain/joins

# Commit
git add ./schemabrain && git commit -m "snapshot semantic layer"

# Re-apply on another machine
schemabrain apply ./schemabrain --url-env DATABASE_URL

Bootstrap from init --emit-yaml-dir

schemabrain init --url-env DATABASE_URL --emit-yaml-dir ./schemabrain
# Edit the YAMLs to your heart's content
schemabrain apply ./schemabrain --url-env DATABASE_URL
schemabrain diff ./schemabrain --url-env DATABASE_URL && \
  schemabrain apply ./schemabrain --url-env DATABASE_URL
diff exits 0 only when there’s no drift; chain with && to apply only on clean state.

schemabrain diff

Drift check between project tree and store before applying.

schemabrain init --emit-yaml-dir

Produces the project tree this command consumes.

schemabrain entities

Per-resource apply / export commands.

schemabrain metrics

Per-resource apply / export for metrics.