‹ 首页

dbt-versioning

@signalpilot-labs · 收录于 5 天前 · 上游提交 6 天前

Load when task involves dbt model versioning, creating v2 of a model, or backward-compatible model changes. Covers versions YAML config, defined_in, latest_version, and ref() with version pins.

适合你,如果需要在 dbt 中创建或管理模型的多版本

/ 通过 npx 安装 校验哈希
npx oh-my-skill add signalpilot-labs/signalpilot/dbt-versioning
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- signalpilot-labs/signalpilot/dbt-versioning
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify signalpilot-labs/signalpilot/dbt-versioning
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
473GitHub stars
~677上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 436a4c4 · 表述以原文为准
它做什么

当需要为dbt模型创建新版本(如v2)或进行向后兼容修改时,Claude会使用dbt原生版本控制功能,通过配置versions YAML和正确命名文件来管理版本,并能使用ref()锁定指定版本。

什么时候触发

当用户要求创建dbt模型的新版本(如v2)、进行向后兼容的改动或管理版本时触发。

装好后可以这样说
Claude会基于原模型编写SELECT重命名
Claude会确保下游模型正确锁定版本
技能原文 SKILL.md作者撰写 · Apache-2.0 · 436a4c4

dbt Model Versioning

1. Versioned Model vs Standalone Copy

When a task says "create a v2," "add a new version," or "backward-compatible change," use dbt's native versions: config (dbt-core 1.6+). Do NOT create a standalone model with a _v2 suffix - that produces a separate node (model.project.dim_customers_v2) instead of a version node (model.project.dim_customers.v2).

2. YAML Structure

Declare versions inside the model's .yml file under the model entry:

models:
 - name: dim_customers
    latest_version: 1
    versions:
 - v: 1
 - v: 2
        defined_in: dim_customers_v2

Rules:

  • versions: is a list of v: entries inside the models: block, under the model name.
  • defined_in: maps a version to its SQL filename (without .sql). Omit defined_in when the filename matches the default <model_name>_v<N>.sql.
  • latest_version: controls which version ref('dim_customers') resolves to. If the task says "not yet the primary version," set latest_version to the old version number.
3. File Naming

Version SQL files use the pattern <model_name>_v<N>.sql.

  • dim_customers.sql - original model, becomes v1 implicitly.
  • dim_customers_v2.sql - new version.

Do NOT rename or move the original SQL file. It remains v1 without changes.

4. How ref() Works with Versions
  • ref('dim_customers') resolves to whichever version latest_version specifies.
  • ref('dim_customers', v=2) pins to version 2 regardless of latest_version.

Downstream models that need the new version must use ref('dim_customers', v=2). Models using bare ref('dim_customers') continue to get the old version until latest_version is updated.

5. Writing the v2 SQL

Read the original model's SQL first. If the v2 only renames or adds columns, write a thin wrapper:

select
    customer_id,
    customer_name,
    account_status as customer_status  -- renamed column
from {{ ref('dim_customers', v=1) }}

Do NOT duplicate all upstream logic into the v2 file when a SELECT-with-renames suffices.

6. Verification

After creating the versioned model, run:

dbt ls --select dim_customers --output json

Confirm the output contains nodes model.<project>.dim_customers.v1 and model.<project>.dim_customers.v2. If these nodes are missing, the versions: YAML is wrong.

Rules
  • NEVER create a standalone _v2 model without versions: YAML - dbt will not register it as a version.
  • NEVER rename or move the original SQL file when adding a new version.
  • ALWAYS set latest_version explicitly - omitting it defaults to the highest version number, which may break downstream refs.
  • ALWAYS read test files in tests/ before writing models - they reveal required dbt features the task may only hint at.
按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。