pipeline-stage
Scaffold a new transform stage in the data pipeline — create the transformation script, schema contract, idempotency logic, and tests. Use when adding a new dbt model or pandas transform, when a new business metric needs a dedicated stage, or when asked to "add a {name} stage to the pipeline".
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 18
- Forks
- 1
01 前言 Front Matter
- name
- pipeline-stage
- metadata
- { "forged-by": "codex-agent", "last-used": "2026-06-02", "forged-from": "session-2026-02-28", "usage-count": "19", "forged-reason": "Added customer_ltv, order_summary, and refund_rate stages in one sprint; each needed the same skeleton: transform file, contract, idempotency test, registration" }
- description
- Scaffold a new transform stage in the data pipeline — create the transformation script, schema contract, idempotency logic, and tests. Use when adding a new dbt model or pandas transform, when a new business metric needs a dedicated stage, or when asked to "add a {name} stage to the pipeline".
03 SKILL.md 正文
Pipeline Stage
Create a new transform stage with idempotency guarantees, a schema contract, and tests.
Inputs
- Stage name (snake_case, e.g.,
customer_ltv) - Input tables/models (list of upstream stage names or raw tables)
- Output table name (usually matches stage name)
- Grain (the primary key or unique key, e.g.,
customer_id,(order_id, date)) - Layer (
staging,intermediate,marts)
Steps
-
Create the transform file
For dbt:
models/{layer}/{stage_name}.sql{{ config( materialized='table', unique_key='{grain}' ) }} select {grain}, -- TODO: add business logic current_timestamp as updated_at from {{ ref('{input_table}') }}For pandas ETL:
pipelines/transforms/{stage_name}/transform.pydef run(df: pd.DataFrame) -> pd.DataFrame: """Transform {input_table} → {stage_name}.""" # TODO: add business logic return df -
Define the schema contract Create
models/{layer}/schema/{stage_name}.yaml(dbt) orpipelines/transforms/{stage_name}/schema.py:- name: {stage_name} columns: - name: {grain} tests: - unique - not_nullEvery non-nullable column must have
not_nulltest; every unique key must haveuniquetest. -
Add idempotency logic
- For
materialized='table': dbt handles full replacement — no extra work. - For incremental models: use
is_incremental()filter onupdated_ator an event timestamp. - For pandas: the output must be deterministic given the same input; add a dedup step on
{grain}.
- For
-
Write tests
tests/transforms/test_{stage_name}.pyRequired tests:
- Input fixture → expected output shape (column names, row count)
- Idempotency: running twice produces identical output
- Null check: no nulls in required columns after transform
-
Register in the pipeline DAG Add the stage after its upstream dependencies:
# dags/pipeline.py {stage_name}_task = DbtRunOperator( task_id="{stage_name}", models="{stage_name}", ) {upstream_task} >> {stage_name}_task -
Run locally
dbt run --select {stage_name} dbt test --select {stage_name} # or for pandas: python -m pytest tests/transforms/test_{stage_name}.py -v
Conventions
- Layer hierarchy:
raw→staging→intermediate→marts - Never skip a layer (e.g., don't read from
rawin amartsmodel) - All stages have at least one
unique+not_nulltest on the grain column - Incremental models use
updated_atas the watermark; add it to every model
Edge Cases
- Fan-out (multiple downstream consumers): Create the stage at the
intermediatelayer; let downstreammartsmodels reference it. - Slowly changing dimension (SCD): Use dbt's
snapshotmaterialization or addvalid_from/valid_tocolumns manually. - Cross-database join: Materialize both inputs to the same database first, then join; cross-database SQL is not portable.
- Very wide table (>200 columns): Split into a core model plus an extension model; document the split in the schema YAML.
04 同仓库更多 Skills
skillforge
Create or update a reusable agent skill. Use when you notice a repeated pattern, when a workflow should be persisted for future sessions, or when asked to forge/create/scaffold a new skill.
skillforge
Create or update a reusable agent skill. Use when you notice a repeated pattern, when a workflow should be persisted for future sessions, or when asked to forge/create/scaffold a new skill.
deploy-preview
Deploy a preview branch to the staging environment for review. Use when a feature branch is ready for visual review, when someone asks to "deploy this for review", or before opening a PR.
component-scaffold
Create a new React component with co-located test, story, and styles. Use when creating new UI components, when asked to scaffold/generate a component, or when building new pages.
bug-triage
Triage a bug report into an actionable GitHub issue with severity, reproduction steps, and assignment. Use when a bug is reported, when error logs need investigation, or when asked to file/triage an issue.
api-endpoint
Scaffold a REST API endpoint with route, controller, validation, and tests. Use when creating new API endpoints, adding resources, or when asked to build a new backend route.