算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
data-data-contracts【设计与创意】Use this skill when asked about data contract, data agreement, schema contract, producer/consumer contract, schema evolution, compatibility, data SLA, dbt contracts, or data product contract. This skill enforces: data contract definition with schema, semantics, SLA, and ownership, contract enforcement in CI/CD, schema compatibility checks (backward/f…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Design and enforce data contracts between producers and consumers covering schema, semantics, SLA, ownership, versioning, and compatibility — with automated enforcement in CI/CD pipelines.
Exact user phrases: "data contract", "data agreement", "schema contract", "producer consumer", "schema evolution", "compatibility", "data SLA", "dbt contracts", "data product contract", "contract testing", "breaking change schema".
Data contract specification with schema, SLA terms, ownership; CI/CD enforcement pipeline with compatibility checks; versioning strategy.
# Contract schema definition
# Semantic type definitions
# SLA configuration
# CI/CD enforcement pipeline
# Version compatibility matrix
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
350 lines of configuration.
contract:
version: "1.2.0"
dataset: analytics.fct_orders
schema:
columns:
- name: order_id
type: STRING
required: true
unique: true
semantic_type: ORDER_ID
tags: [PII, FINANCIAL]
- name: customer_id
type: STRING
required: true
semantic_type: CUSTOMER_ID
- name: total_amount
type: DECIMAL(18,2)
required: true
semantic_type: MONETARY_VALUE
constraints:
minimum: 0
maximum: 100000
| Type | Base Type | Validation | Example |
|---|---|---|---|
| ORDER_ID | STRING | Regex pattern | ORD-2026-001234 |
| CUSTOMER_ID | STRING | UUID format | a1b2c3d4-... |
| MONETARY_VALUE | DECIMAL | Positive | 150.00 |
| STRING | Email regex | user@org.com | |
| ISO_DATE | DATE | ISO 8601 | 2026-05-22 |
sla:
freshness:
max_age: 3600 # seconds
schedule: hourly
volume:
min_rows: 50000
max_rows: 200000
quality:
null_threshold_pct: 1.0
unique_threshold_pct: 99.9
distribution_drift_pct: 5.0
ownership:
producer: team-orders-engine
consumer: team-analytics
escalation: dgovernance@org.com
| Mode | Producer Can | Consumer Must | Use Case |
|---|---|---|---|
| BACKWARD | Delete column, add optional | Read old schema | Default |
| FORWARD | Add column, delete optional | Tolerate unknown | Stream consumers |
| FULL | Add optional only | Read any version | Strict governance |
| NONE | Any change | Recompile | Dev only |
models:
- name: fct_orders
config:
contract:
enforced: true
columns:
- name: order_id
data_type: string
constraints: [not_null, unique]
meta:
semantic_type: ORDER_ID
- name: total_amount
data_type: numeric
constraints: [not_null]
jobs:
contract-check:
steps:
- uses: actions/checkout@v4
- name: Validate Contract
run: |
python scripts/validate_contract.py \
--contract contracts/fct_orders.yaml \
--schema current_schema.json \
--compatibility backward
- name: Check Breaking Changes
run: |
python scripts/check_breaking.py \
--old contracts/fct_orders_v1.yaml \
--new contracts/fct_orders_v2.yaml
- name: Validate with dbt
run: dbt run --select fct_orders --fail-fast
Version scheme: MAJOR (breaking), MINOR (additive), PATCH (fixes). Breaking change = MAJOR bump. All consumers of previous version must acknowledge before MAJOR takes effect.
Contracts progress through stages: DRAFT (under development), REVIEW (submitted for consumer review), ACTIVE (enforced in production), DEPRECATED (replaced by newer version, 30-day notice), RETIRED (no longer in use). Each transition is tracked with who approved and when.
Beyond schema validation, test contracts with Great Expectations suites. For each contract column, auto-generate expectations: expect_column_to_exist, expect_column_values_to_not_be_null, expect_column_values_to_be_between, expect_column_values_to_match_regex. Run these as part of the data pipeline and report results back to the contract.
When a contract changes, compute the impact: which consumers are affected, which dashboards reference the dataset, which downstream pipelines depend on it. Use the catalog's lineage graph to compute impact. Notify all affected parties before the change takes effect.
New/updated contract
├── Batch data pipeline → BACKWARD
├── CDC/stream consumer → FORWARD
├── Regulated data (SOX, HIPAA) → FULL
├── Dev/test environment → NONE
└── dbt model → enforced via dbt contracts
Schema change proposed
├── Add column (nullable, default) → MINOR
├── Add column (required, no default) → MAJOR (breaking)
├── Remove column → MAJOR (breaking)
├── Widen type (INT->LONG) → MINOR
├── Narrow type (LONG->INT) → MAJOR (breaking)
├── Rename column → MAJOR (add new, deprecate old, remove later)
└── Add constraint (NOT NULL on existing) → MAJOR
Where to store contracts:
├── Same repo as producer code → Tightly coupled, easy to maintain
├── Dedicated contracts repo → Centralized governance, harder to sync
├── In catalog metadata → Always in sync with actual schema
└── In data product definition → Best for data mesh architectures
| Feature | dbt Contracts | Data Contract YAML | Schema Registry | Great Expectations |
|---|---|---|---|---|
| Scope | dbt models | Any dataset | Streaming topics | Data quality |
| Schema enforcement | Build time | CI/CD | Serialization | Runtime |
| SLA support | No | Yes | No | No |
| Ownership tracking | Basic | Structured | Basic | No |
| Compatibility checks | Implicit | Explicit | Native | No |
| Notification workflow | No | Yes | Limited | Yes (alerts) |
| Versioning | dbt version | Semver | Schema version | No |
Data contracts vs schema registry: schema registry handles technical schema compatibility at serialization time. Data contracts cover the full agreement: schema, SLA, semantics, ownership, and lifecycle. They work together: contract's schema section can reference schema registry subjects.
Data contracts vs data quality: quality tools validate data against expectations at runtime. Contracts define the expectations that quality tools should enforce. The contract is the "what" and quality tools are the "how."
| Tool | Purpose |
|---|---|
| dbt | Contract enforcement for data models |
| Great Expectations | Data quality expectations matching contract terms |
| Soda | Data quality monitoring, SLA enforcement |
| Monte Carlo | Data observability, drift detection |
| Marquez / OpenLineage | Lineage for impact analysis |
| Custom CI/CD scripts | Contract validation in GitHub/GitLab |
| DataHub / OpenMetadata | Contract storage and discovery |
| Apache Avro / Protobuf | Schema definition for contracts with schema registry integration |
violation_resolution:
trigger: "Contract check fails in CI/CD or production"
severity_levels:
critical:
description: "Blocking — data schema mismatch or SLA breach"
action: "Block deployment, notify all consumers immediately"
response_time: "1 hour"
warning:
description: "Non-breaking change or minor SLA deviation"
action: "Log violation, notify producer, continue deployment"
response_time: "24 hours"
info:
description: "Informational — contract drift within acceptable range"
action: "Log for quarterly review"
response_time: "Next review cycle"
resolution_flow:
- "Identify: which contract clause was violated (schema, SLA, quality)"
- "Notify: consumer and producer stakeholders"
- "Assess: is this a producer error or legitimate breaking change?"
- "If producer error: rollback change, fix and retry"
- "If breaking change needed: coordinate dual-run period"
- "Document: violation in contract version history"
- "Update: review contract terms if pattern repeats"
# dbt schema.yml with contract enforcement
version: 2
models:
- name: fct_orders
config:
contract:
enforced: true # Enforce column names, types, nullability
columns:
- name: order_id
data_type: string
constraints:
- not_null: true
- unique: true
- name: total_amount
data_type: decimal(18,2)
constraints:
- not_null: true
- name: customer_id
data_type: string
constraints:
- not_null: true
- name: status
data_type: string
constraints:
- not_null: true
- name: created_at
data_type: timestamp
constraints:
- not_null: true
# dbt contracts require:
# - All columns explicitly listed with data_type
# - No extra columns in the model SQL beyond the contract
# - Column types match the model output exactly
# - Constraints enforced at build time (dbt build)
# Cross-dataset contract relationships
contract_catalog:
source_contracts:
- dataset: raw.orders
owner: "source-team@org.com"
contract_version: "2.1.0"
staging_contracts:
- dataset: staging.orders
owner: "data-eng@org.com"
upstream_contract: raw.orders@2.1.0
contract_version: "1.0.0"
transformations:
- "order_id: STRING → STRING (unchanged)"
- "total_amount: DECIMAL(10,2) → DECIMAL(18,2) (widened)"
- "status: STRING → ENUM (constrained values)"
mart_contracts:
- dataset: analytics.fct_orders
owner: "analytics-eng@org.com"
upstream_contract: staging.orders@1.0.0
contract_version: "1.0.0"
sla:
freshness: "1 hour"
min_rows: 10000
max_rows: 10000000
# Contract propagation: upstream change cascades
# staging.orders contract update → analytics.fct_orders re-validation
# Automated notification: "Upstream contract changed, re-validate downstream"
migration_strategy:
minor_change:
description: "Adding optional field, deprecating field"
process:
- "Add new column as nullable"
- "Update contract version (MINOR bump)"
- "Notify consumers of new available field"
- "Deprecate old field in contract documentation"
consumer_action: "Optional: start using new field"
compatibility: BACKWARD
major_change:
description: "Removing field, changing type, renaming column"
process:
- "Create new contract version (MAJOR bump)"
- "Run dual-producer for 14+ days (both old and new schemas)"
- "Notify all consumers with migration deadline"
- "Track consumer migration progress"
- "After deadline: remove old schema, enforce new contract"
consumer_action: "Required: migrate before deadline"
compatibility: BREAKING
emergency_change:
description: "Security fix, data corruption prevention"
process:
- "Immediate deployment with new contract"
- "Within 24 hours: notify all consumers"
- "Within 7 days: formalize contract version"
consumer_action: "Fix broken downstream immediately"
compatibility: BREAKING (emergency)
# Contract publishing endpoint
contract_api:
endpoints:
get_contract:
method: GET
path: "/contracts/{dataset_fqn}"
response: |
{
"version": "1.2.0",
"dataset": "analytics.fct_orders",
"schema": [...],
"sla": {
"freshness": "1 hour",
"min_rows": 10000,
"max_rows": 10000000,
"quality_score": "> 0.95"
},
"owner": "analytics-eng@org.com",
"status": "active"
}
validate_contract:
method: POST
path: "/contracts/validate"
body: |
{
"dataset": "analytics.fct_orders",
"schema": [...]
}
response: |
{
"compatible": true/false,
"breaking_changes": [...],
"current_version": "1.2.0",
"recommended_action": "none | minor | major"
}
Dataset criticality?
├── Tier 1 (executive dashboards, financial, customer-facing)
│ ├── dbt contract enforced (build fails on mismatch)
│ ├── CI/CD schema compatibility check required
│ └── SLA monitoring with PagerDuty alerts
├── Tier 2 (operational reports, team analytics)
│ ├── dbt contract enforced (build warns on mismatch)
│ ├── CI/CD schema compatibility check recommended
│ └── SLA monitoring with email alerts
└── Tier 3 (experimental, ad-hoc)
├── dbt contract documented but not enforced
└── No automated contract checks
Does the change break existing consumers?
├── Adding a new optional column → COMPATIBLE (MINOR)
├── Adding a new required column → BREAKING (major migration)
├── Removing a column → BREAKING (requires dual-run)
├── Widening a type (INT→BIGINT, STRING→TEXT) → COMPATIBLE
├── Narrowing a type (BIGINT→INT) → BREAKING
├── Renaming a column → BREAKING (add alias, deprecate old)
├── Adding a constraint (NOT NULL) → BREAKING if data has nulls
└── Removing a constraint (NOT NULL) → COMPATIBLE
data-data-quality for quality dimension enforcement in contracts. data-data-catalog for contract metadata. data-data-observability for SLA monitoring. data-schema-registry for schema registry integration.