Metabase represents database metadata — synced databases, their tables, and their fields — as a tree of YAML files. Files are diff-friendly: numeric IDs are omitted entirely, and foreign keys use natural-key tuples like ["Sample Database", "PUBLIC", "ORDERS"] instead of database identifiers.
This repository contains the specification, examples, and a CLI that converts the JSON returned by Metabase's GET /api/database/metadata endpoint into YAML.
- core-spec/v1/spec.md — Full specification (v1.0.0) covering entity keys, field types, folder structure, and each entity shape.
- examples/v1/ — Reference output using the Sample Database.
- src/ / bin/ — The CLI implementation.
| Entity | Description |
|---|---|
| Database | A connected data source (Postgres, MySQL, BigQuery, etc.) |
| Table | A physical table (or view) inside a database |
| Field | A column on a table, including JSON-unfolded nested fields |
See core-spec/v1/spec.md for the full schema of each entity.
The CLI operates on a JSON snapshot produced by Metabase's GET /api/database/metadata endpoint. Fetch it against any running Metabase instance:
mkdir -p .metabase
curl "https://my.metabase/api/database/metadata" \
-H "X-Metabase-Session: $SESSION_TOKEN" \
> .metabase/metadata.jsonThe response is a flat structure with three arrays — databases, tables, and fields — streamed for large schemas. Authenticate with either a session token (X-Metabase-Session) or an API key (X-API-Key).
bunx @metabase/database-metadata extract-metadata <input-file> <output-folder><input-file>— path to themetadata.jsonproduced by the API.<output-folder>— destination directory. By convention this is.metabase/databasesat the project root (see spec.md). Database folders are created directly under it.
The typical end-to-end invocation:
bunx @metabase/database-metadata extract-metadata .metabase/metadata.json .metabase/databasesCopy the bundled spec.md to a target file:
bunx @metabase/database-metadata extract-spec --file ./spec.mdOmit --file to write spec.md into the current directory.
Releases are published automatically by the Release to NPM GitHub Actions workflow on every push to main. The workflow compares the version in package.json against the version published on npm and publishes (with the latest dist-tag) if they differ.
To cut a release, bump version in package.json and merge to main.
The workflow requires an NPM_RELEASE_TOKEN secret with publish access to the @metabase npm org.
bun install
bun bin/cli.js extract-metadata examples/v1/metadata.json /tmp/.metabase/databasesThe Validate GitHub workflow regenerates the bundled examples on every push and fails if they drift from what's checked in.