- Move Iceberg secret from before_all hook to connection.secrets
- Fixes SQLMesh warning about unsupported @env_var syntax
- Uses Jinja templating {{ env_var() }} instead of @env_var()
- Remove database: ':memory:' (incompatible with catalogs)
- DuckDB doesn't allow both database and catalogs config
- Connection defaults to in-memory when no database specified
- Simplify before_all hooks to only handle ATTACH and schema setup
- Secret is now created automatically by SQLMesh
- Cleaner separation: connection config vs runtime setup
Based on:
- https://developers.cloudflare.com/r2/data-catalog/config-examples/duckdb/
- https://sqlmesh.readthedocs.io/en/latest/integrations/engines/duckdb/
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
2.3 KiB
YAML
69 lines
2.3 KiB
YAML
# --- Gateway Connection ---
|
|
# Single gateway connecting to R2 Iceberg catalog
|
|
# Local dev uses virtual environments (e.g., dev_<username>)
|
|
# Production uses the 'prod' environment
|
|
gateways:
|
|
prod:
|
|
connection:
|
|
type: duckdb
|
|
extensions:
|
|
- name: httpfs
|
|
- name: iceberg
|
|
secrets:
|
|
r2_secret:
|
|
type: iceberg
|
|
token: "{{ env_var('CLOUDFLARE_API_TOKEN') }}"
|
|
|
|
default_gateway: prod
|
|
|
|
# --- Catalog Configuration ---
|
|
# Configure the Iceberg catalog endpoint
|
|
# https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#execution-hooks
|
|
|
|
before_all:
|
|
- |
|
|
ATTACH '{{ env_var("R2_WAREHOUSE_NAME", "materia") }}' AS catalog (
|
|
TYPE ICEBERG,
|
|
ENDPOINT '{{ env_var("ICEBERG_REST_URI") }}'
|
|
);
|
|
- CREATE SCHEMA IF NOT EXISTS catalog.materia;
|
|
- USE catalog.materia;
|
|
|
|
# --- Model Defaults ---
|
|
# https://sqlmesh.readthedocs.io/en/stable/reference/model_configuration/#model-defaults
|
|
|
|
model_defaults:
|
|
dialect: duckdb
|
|
start: 2025-07-07 # Start date for backfill history
|
|
cron: '@daily' # Run models daily at 12am UTC (can override per model)
|
|
|
|
# --- Linting Rules ---
|
|
# Enforce standards for your team
|
|
# https://sqlmesh.readthedocs.io/en/stable/guides/linter/
|
|
|
|
linter:
|
|
enabled: true
|
|
rules:
|
|
- ambiguousorinvalidcolumn
|
|
- invalidselectstarexpansion
|
|
|
|
# FLOW: Minimal prompts, automatic changes, summary output
|
|
# https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#plan
|
|
|
|
plan:
|
|
no_diff: true # Hide detailed text differences for changed models
|
|
no_prompts: true # No interactive prompts
|
|
auto_apply: true # Apply changes automatically
|
|
|
|
# --- Optional: Set a default target environment ---
|
|
# This is intended for local development to prevent users from accidentally applying plans to the prod environment.
|
|
# It is a development only config and should NOT be committed to your git repo.
|
|
# https://sqlmesh.readthedocs.io/en/stable/guides/configuration/#default-target-environment
|
|
|
|
# Uncomment the following line to use a default target environment derived from the logged in user's name.
|
|
# default_target_environment: dev_{{ user() }}
|
|
|
|
# Example usage:
|
|
# sqlmesh plan # Automatically resolves to: sqlmesh plan dev_yourname
|
|
# sqlmesh plan prod # Specify `prod` to apply changes to production
|