cdc-scd-patterns
Skill30 starsChanged 4 days agoApache-2.0View on GitHub
Guides Change Data Capture (CDC) ingestion via Datastream and Slowly Changing Dimension (SCD) modeling in BigQuery/Dataform. Use when replicating an operational database, designing history-tracking dimension tables, or implementing SCD Type 1/2 merge logic.
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 27
Serving Rule: Never expose the raw bronze change-log directly to reporting or BI tools.
- Very specific: line 59
Claude Code: Run scaffold_scd2_dataform.py in the workspace shell to generate SQLX models.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CDC & SCD Patterns Skill
Overview
This skill guides the design and implementation of Change Data Capture (CDC) replication pipelines and Slowly Changing Dimension (SCD) modeling in Google Cloud BigQuery and Dataform. It acts as a Senior Data Engineer and Dimensional Modeling Specialist, ensuring accurate historical point-in-time tracking, idempotent MERGE statements, and clean transition from raw change logs to queryable dimension tables.
When to Use
Trigger Scenarios
- Replicating relational databases (Cloud SQL, AlloyDB, Oracle, Postgres) into BigQuery using Datastream.
- Designing dimensional models requiring historical auditability (SCD Type 1 vs. Type 2).
- Authoring Dataform
.sqlxmodels to deduplicate CDC event streams into current-state snapshots. - Generating automated SCD Type 2 merge SQL statements.
When NOT to Use
- High-level GCP cloud architecture and tool selection: Route to
gcp-data-engineering. - Query execution plan and indexing diagnostics: Route to
bigquery-query-optimization. - Application relational database migrations: Route to
database-migration-expert.
Process
Phase 1: Datastream CDC Ingestion & Bronze Landing
- Log-based CDC: Datastream streams inserts, updates, and deletes from the database transaction log into BigQuery bronze tables without impacting source database CPU.
- Bronze Table Metadata: Each record contains metadata columns (
_metadata_timestamp,_metadata_deleted,_metadata_change_type). - Serving Rule: Never expose the raw bronze change-log directly to reporting or BI tools. Materialize a silver table representing current state or an SCD Type 2 dimension.
Phase 2: Dimension Classification Matrix (SCD Types 0–6)
| Type | Behavior | Business Use Case |
| Type 0 | Retain original value permanently. | Original signup timestamp, initial creation dates. |
| Type 1 | Overwrite in place; no history preserved. | Typo corrections, attributes where history has zero analytical value. |
| Type 2 | New row per change with valid_from, valid_to, is_current. | Default choice: Customer addresses, pricing tiers, account statuses. |
| Type 3 | Add previous_value column. | Tracking only the immediately prior state alongside current. |
| Type 4 | Separate current table and historical log table. | Extremely high-churn dimensions where current queries must remain fast. |
| Type 6 | Hybrid: Type 2 versioning with a Type 1 current column. | Fast lookups without self-joins while retaining full historical auditability. |
Phase 3: Type 2 Merge Implementation & Scaffolding
Scaffold the parameterized Dataform .sqlx model implementing atomic SCD Type 2 merge logic:
python3 ./skills/cdc-scd-patterns/scripts/scaffold_scd2_dataform.py <table_name> <key_column> <tracked_columns_comma_separated>The script implements proper MERGE ... WHEN MATCHED logic, updates valid_to timestamps, and sets is_current = FALSE on superseded records in a single atomic transaction.
Usage
Commands & Automation Scripts
# Scaffold an SCD Type 2 Dataform model for a customer dimension
python3 ./skills/cdc-scd-patterns/scripts/scaffold_scd2_dataform.py dim_customer customer_id name,email,address,tierExample Prompts
- "Design an SCD Type 2 dimension in Dataform for tracking customer address changes replicated via Datastream."
- "How should we handle soft deletes from Cloud SQL in our BigQuery silver layer?"
- "Generate an idempotent MERGE statement to maintain current state from Datastream change logs."
Host Execution Instructions
- Claude Code: Run
scaffold_scd2_dataform.pyin the workspace shell to generate SQLX models. - Antigravity: Generate Dataform pipelines and compile with Dataform CLI to verify SQL syntax.
Red Flags
- Comparing nullable columns with
=instead ofIS DISTINCT FROM(treatingNULL = NULLasNULL, missing changes). - Forgetting to close historical rows (
valid_to = current_timestamp, is_current = FALSE) when inserting a new version. - Querying raw append-only Datastream logs in BI dashboards, producing duplicate row counts.
- Running non-idempotent insert pipelines that create duplicates on backfill reruns.
Verification
- SCD model generated using automation script:
python3 ./skills/cdc-scd-patterns/scripts/scaffold_scd2_dataform.py <table_name> <key_column> <tracked_columns> - Change detection uses
IS DISTINCT FROMacross all tracked columns. - Every natural key has exactly one row where
is_current = TRUEandvalid_to IS NULL. - Re-running the pipeline with unchanged data produces zero new rows.
References
For full SQL templates and production-ready merge queries:
- SCD Type 2 SQL Reference
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-challengerSkill
- agent-metricsSkill
- bigquery-query-optimizationSkill
- blackbox-testerSkill
- build-and-ci-gatesSkill
- code-criticSkill
- code-implementerSkill
- code-smells-expertSkill
- commit-expertSkill
- compliance-verifierSkill
- context-captureSkill
- context-restoreSkill
- database-migration-expertSkill
- design-spec-expertSkill
- documentation-expertSkill
- flutter-architecture-decisionsSkill
- flutter-performance-profilingSkill
- flutter-release-engineeringSkill
- flutter-review-checklistSkill
- flutter-senior-orchestrationSkill
- flutter-test-strategySkill
- flutter-upgrade-migrationSkill
- gcp-data-engineeringSkill
- guidelines-karpathySkill
- loop-engineeringSkill
- performance-scalabilitySkill
- product-analystSkill
- pull-request-expertSkill
- python-expertSkill
- qa-testerSkill
- refactoring-code-expertSkill
- repo-researchSkill
- security-auditSkill
- senior-architect-engineeringSkill
- senior-dev-orchestratorSkill
- sql-query-optimizationSkill
- test-driven-developmentSkill
- testing-expertSkill
- ui-ux-designerSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

