metabase-representation-format
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMetabase Representation Format
Metabase表示格式
Metabase represents user-created content as a tree of YAML files. Each file is one entity (a collection, card, dashboard, etc.). The format is portable across Metabase instances: numeric database IDs are replaced with human-readable names and entity IDs.
The format is defined by a spec bundled alongside this file as (upstream source: the npm package). The same package ships a CLI () that validates a tree of YAML files against the format.
spec.md@metabase/representationsnpx @metabase/representations validate-schemaMetabase将用户创建的内容表示为YAML文件树。每个文件对应一个实体(集合、卡片、仪表盘等)。该格式在Metabase实例之间具有可移植性:数字数据库ID被替换为人类可读的名称和实体ID。
此格式由与本文件捆绑在一起的规范定义(上游来源: npm包)。同一包还提供了一个CLI工具(),用于根据格式验证YAML文件树。
spec.md@metabase/representationsnpx @metabase/representations validate-schemaEntities
实体
The format defines 11 entity types.
| Entity | SerDes Model | Description |
|---|---|---|
| Collection | | Folder-like container for organizing content. Hierarchy via |
| Card | | Question, model, or metric. Holds an MBQL or native |
| Dashboard | | Grid layout (24 columns) of cards with filter parameters and optional tabs. Contains |
| Document | | Rich text page using ProseMirror AST. Can embed cards via |
| Segment | | Saved filter definition scoped to a table. Definition is a pMBQL query with a single stage containing only |
| Measure | | Saved aggregation definition scoped to a table. Definition is a pMBQL query with a single stage containing only |
| Snippet | | Reusable SQL fragment referenced in native queries via |
| Transform | | Materializes query or Python script results into a database table. Source is either MBQL/native query or Python script. |
| TransformTag | | Label for categorizing transforms. Built-in types: |
| TransformJob | | Scheduled job (cron) that executes transforms matching specific tags. |
| PythonLibrary | | Shared Python source file available to Python-based transforms. |
该格式定义了11种实体类型。
| 实体 | SerDes模型 | 描述 |
|---|---|---|
| Collection | | 用于组织内容的类文件夹容器。通过 |
| Card | | 问题、模型或度量。包含MBQL或原生 |
| Dashboard | | 包含筛选参数和可选标签页的卡片网格布局(24列)。包含用于卡片布局的 |
| Document | | 使用ProseMirror AST的富文本页面。可通过 |
| Segment | | 作用于特定表的已保存筛选器定义。定义为单阶段pMBQL查询,仅包含 |
| Measure | | 作用于特定表的已保存聚合定义。定义为单阶段pMBQL查询,仅包含 |
| Snippet | | 可重用SQL片段,在原生查询中通过 |
| Transform | | 将查询或Python脚本结果物化到数据库表中。来源可以是MBQL/原生查询或Python脚本。 |
| TransformTag | | 用于对转换进行分类的标签。内置类型: |
| TransformJob | | 执行匹配特定标签的转换的定时任务(cron)。 |
| PythonLibrary | | 可供基于Python的转换使用的共享Python源文件。 |
Ownership and hierarchy
所有权与层级结构
Critical — folder layout is decorative. Where an entity lands in Metabase is decided entirely by its fields, not by where its YAML file sits in the tree. Moving a file without updating the fields changes nothing. Updating the fields without moving the file still works correctly. Always treat the fields below as the source of truth.
The fields that actually determine placement:
- (entity_id of a collection) — places the entity in that collection.
collection_idor omitted → root collection.null - on a collection — this, and only this, sets the collection's own parent. A collection's position in the folder tree is ignored on import; without
parent_id(or withparent_id) the collection becomes a root-level collection, no matter how deep its folder is nested. To nest one collection under another, setparent_id: nullto the parent collection'sparent_id.entity_id - /
dashboard_idon a card — nests a card under a dashboard or document. Such a card must also setdocument_idto match the parent'scollection_id. A card never sets both.collection_id
On disk, cards nested under a dashboard or document live in a subfolder next to the parent YAML (e.g. sitting next to ) — but again, this is purely for human navigation; the fields are what Metabase reads.
my_dashboard/card.yamlmy_dashboard.yaml重要提示——文件夹布局仅用于展示。 实体在Metabase中的位置完全由其字段决定,而非其YAML文件在文件树中的位置。移动文件但不更新字段不会产生任何变化。更新字段但不移动文件仍能正常工作。始终将以下字段视为权威来源。
实际决定实体位置的字段:
- (集合的entity_id)——将实体放置在该集合中。
collection_id或省略则放入根集合。null - 集合的****——只有此字段能设置集合的父级。导入时会忽略集合在文件夹树中的位置;如果没有
parent_id(或parent_id),无论文件夹嵌套多深,该集合都会成为根级集合。要将一个集合嵌套在另一个集合下,需将parent_id: null设置为父集合的parent_id。entity_id - 卡片的**** /
dashboard_id——将卡片嵌套在仪表盘或文档下。此类卡片必须同时将document_id设置为与父级的collection_id匹配。卡片不能同时设置这两个字段。collection_id
在磁盘上,嵌套在仪表盘或文档下的卡片位于父级YAML文件旁的子文件夹中(例如与同级)——但同样,这仅为方便人类导航;Metabase读取的是字段内容。
my_dashboard/card.yamlmy_dashboard.yamlImport paths
导入路径
Metabase only imports YAML from these top-level directories; anything outside is ignored:
- — all user content (cards, dashboards, documents, snippets, transforms, etc.), partitioned by namespace:
collections/,main/,snippets/.transforms/ - — only the
databases/andsegments/subdirectories under each table are imported.measures/ - (also accepted as
python_libraries/).python-libraries/ - — contains
transforms/andtransform_jobs/.transform_tags/
Metabase仅从以下顶级目录导入YAML文件;其他目录的内容会被忽略:
- ——所有用户内容(卡片、仪表盘、文档、代码片段、转换等),按命名空间划分:
collections/、main/、snippets/。transforms/ - ——仅导入每个表下的
databases/和segments/子目录。measures/ - (也支持
python_libraries/)。python-libraries/ - ——包含
transforms/和transform_jobs/。transform_tags/
serdes/meta
serdes/metaserdes/meta
serdes/metaEvery entity carries a top-level array that encodes its identity path. Each entry is — is the slugified name and is present on entities keyed by NanoID. Example:
serdes/meta{id, model, label?}labelyaml
serdes/meta:
- id: NDzkGoTCdRcaRyt7GOepg
label: my_entity_name
model: Cardvalidate-schemaserdes/metaspec.md每个实体都带有一个顶级数组,用于编码其标识路径。每个条目为——是名称的slug化形式,在使用NanoID作为键的实体中存在。示例:
serdes/meta{id, model, label?}labelyaml
serdes/meta:
- id: NDzkGoTCdRcaRyt7GOepg
label: my_entity_name
model: Cardvalidate-schemaserdes/metaspec.mdReading the spec
阅读规范
This skill ships with a local snapshot of the spec as alongside .
spec.mdSKILL.mdBeyond the per-entity shapes summarized in this SKILL, also covers: MBQL query form (stages, field references, joins, expressions, aggregations, filter/expression operators, temporal bucketing, binning), native queries and template tags (, , , , , , , , ), visualization settings, click behavior, and dashboard/card parameters. Reach for whenever edits touch any of those.
spec.mdtextnumberdatebooleandimensiontemporal-unitcardsnippettablespec.mdRead on demand, not eagerly. Open only when you are about to read or modify content files for the entities listed above — e.g. the user asks to edit a card, add a dashcard, tweak a transform, or similar work that implies YAML edits. Do not open it at session start or for tasks unrelated to representation YAML.
spec.mdIf the bundled copy looks out of date with the upstream package, the skill's own documents how to refresh it with .
README.mdextract-spec本技能随附了一份本地快照版规范,与放在一起。
spec.mdSKILL.md除了本SKILL中总结的各实体结构外,还涵盖:MBQL查询形式(阶段、字段引用、连接、表达式、聚合、筛选/表达式运算符、时间分桶、分箱)、原生查询和模板标签(、、、、、、、、)、可视化设置、点击行为以及仪表盘/卡片参数。当编辑涉及这些内容时,请查阅。
spec.mdtextnumberdatebooleandimensiontemporal-unitcardsnippettablespec.md按需阅读,无需提前通读。 仅当您要读取或修改上述实体的内容文件时才打开——例如用户要求编辑卡片、添加仪表盘卡片、调整转换,或其他涉及YAML编辑的类似工作。不要在会话开始时或与表示YAML无关的任务中打开它。
spec.md如果捆绑的副本与上游包版本不符,本技能的文档说明了如何使用刷新它。
README.mdextract-specValidating
验证
Validate edits with the built-in CLI:
sh
npx @metabase/representations validate-schema --folder <path>Pass the top-level export folder, or the git repository root. The tool walks the import paths listed above, reads on each file to pick the right validation rules, and exits non-zero on failure. Prefer running this over manually cross-checking field shapes. It's essentially instant, so invoke it whenever useful — after each edit, between edits, whenever the shape of a file feels uncertain. No reason to batch.
serdes/meta使用内置CLI工具验证编辑内容:
sh
npx @metabase/representations validate-schema --folder <path>传入顶级导出文件夹或Git仓库根目录。该工具会遍历上述导入路径,读取每个文件的以选择正确的验证规则,验证失败时会返回非零退出码。优先使用此工具,而非手动检查字段结构。它几乎瞬间完成,因此只要有用就可以调用——每次编辑后、编辑过程中、对文件结构不确定时都可以。无需批量操作。
serdes/metaGenerating entity IDs
生成实体ID
Every entity needs a 21-character NanoID for . Generate one (or several) with the bundled CLI:
entity_idsh
npx @metabase/representations generate-entity-id每个实体都需要一个21字符的NanoID作为。使用捆绑的CLI工具生成一个(或多个):
entity_idsh
npx @metabase/representations generate-entity-id→ LZfXLFzPPR4NNrgjlWDxn
→ LZfXLFzPPR4NNrgjlWDxn
npx @metabase/representations generate-entity-id --count 5
undefinednpx @metabase/representations generate-entity-id --count 5
undefinedGenerating UUIDs
生成UUID
Some fields in the format require v4 UUIDs rather than NanoIDs — notably on MBQL aggregation clauses (referenced from and later stages) and the on dashboard/card parameters. Generate them with:
lib/uuidorder-byidsh
npx @metabase/representations generate-uuid该格式中的某些字段需要v4 UUID而非NanoID——特别是MBQL聚合子句中的(在及后续阶段中引用)以及仪表盘/卡片参数的。使用以下命令生成:
lib/uuidorder-byidsh
npx @metabase/representations generate-uuid→ 1d4e9fdf-49ae-4fbe-ae27-05e7c6a5cfe8
→ 1d4e9fdf-49ae-4fbe-ae27-05e7c6a5cfe8
npx @metabase/representations generate-uuid --count 3
undefinednpx @metabase/representations generate-uuid --count 3
undefined