dbt-preflight 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. dbt_preflight-0.3.5/.editorconfig +18 -0
  2. dbt_preflight-0.3.5/.github/workflows/ci.yml +36 -0
  3. dbt_preflight-0.3.5/.github/workflows/release.yml +52 -0
  4. dbt_preflight-0.3.5/.gitignore +16 -0
  5. dbt_preflight-0.3.5/CHANGELOG.md +141 -0
  6. dbt_preflight-0.3.5/CLAUDE.md +98 -0
  7. dbt_preflight-0.3.5/CONTRIBUTING.md +70 -0
  8. dbt_preflight-0.3.5/LICENSE +201 -0
  9. dbt_preflight-0.3.5/Makefile +26 -0
  10. dbt_preflight-0.3.5/PKG-INFO +254 -0
  11. dbt_preflight-0.3.5/README.ko.md +114 -0
  12. dbt_preflight-0.3.5/README.md +219 -0
  13. dbt_preflight-0.3.5/SECURITY.md +30 -0
  14. dbt_preflight-0.3.5/docs/ci-integration.md +187 -0
  15. dbt_preflight-0.3.5/docs/configuration.md +101 -0
  16. dbt_preflight-0.3.5/docs/index.html +417 -0
  17. dbt_preflight-0.3.5/examples/ci-workflow/dbt-plan.yml +108 -0
  18. dbt_preflight-0.3.5/examples/sample-project/README.md +60 -0
  19. dbt_preflight-0.3.5/examples/sample-project/base/compiled/dim_customers.sql +6 -0
  20. dbt_preflight-0.3.5/examples/sample-project/base/compiled/fct_daily_sales.sql +8 -0
  21. dbt_preflight-0.3.5/examples/sample-project/base/compiled/int_order_enriched.sql +7 -0
  22. dbt_preflight-0.3.5/examples/sample-project/base/manifest.json +32 -0
  23. dbt_preflight-0.3.5/examples/sample-project/current/target/compiled/sample/models/dim_customers.sql +7 -0
  24. dbt_preflight-0.3.5/examples/sample-project/current/target/compiled/sample/models/dim_publishers.sql +6 -0
  25. dbt_preflight-0.3.5/examples/sample-project/current/target/compiled/sample/models/fct_daily_sales.sql +9 -0
  26. dbt_preflight-0.3.5/examples/sample-project/current/target/compiled/sample/models/int_order_enriched.sql +7 -0
  27. dbt_preflight-0.3.5/examples/sample-project/current/target/manifest.json +39 -0
  28. dbt_preflight-0.3.5/examples/sample-project/run-example.sh +55 -0
  29. dbt_preflight-0.3.5/pyproject.toml +62 -0
  30. dbt_preflight-0.3.5/src/dbt_plan/__init__.py +37 -0
  31. dbt_preflight-0.3.5/src/dbt_plan/cli.py +976 -0
  32. dbt_preflight-0.3.5/src/dbt_plan/columns.py +62 -0
  33. dbt_preflight-0.3.5/src/dbt_plan/config.py +118 -0
  34. dbt_preflight-0.3.5/src/dbt_plan/diff.py +95 -0
  35. dbt_preflight-0.3.5/src/dbt_plan/formatter.py +220 -0
  36. dbt_preflight-0.3.5/src/dbt_plan/manifest.py +193 -0
  37. dbt_preflight-0.3.5/src/dbt_plan/predictor.py +436 -0
  38. dbt_preflight-0.3.5/src/dbt_plan/py.typed +0 -0
  39. dbt_preflight-0.3.5/tests/__init__.py +0 -0
  40. dbt_preflight-0.3.5/tests/conftest.py +25 -0
  41. dbt_preflight-0.3.5/tests/dbt_project/.user.yml +1 -0
  42. dbt_preflight-0.3.5/tests/dbt_project/dbt_project.yml +6 -0
  43. dbt_preflight-0.3.5/tests/dbt_project/models/marts/dim_books.sql +7 -0
  44. dbt_preflight-0.3.5/tests/dbt_project/models/marts/fct_orders.sql +12 -0
  45. dbt_preflight-0.3.5/tests/dbt_project/models/staging/stg_orders.sql +7 -0
  46. dbt_preflight-0.3.5/tests/dbt_project/profiles.yml +6 -0
  47. dbt_preflight-0.3.5/tests/dbt_project/target/compiled/test_project/models/marts/dim_books.sql +7 -0
  48. dbt_preflight-0.3.5/tests/dbt_project/target/compiled/test_project/models/marts/fct_orders.sql +9 -0
  49. dbt_preflight-0.3.5/tests/dbt_project/target/compiled/test_project/models/staging/stg_orders.sql +7 -0
  50. dbt_preflight-0.3.5/tests/dbt_project/target/graph.gpickle +0 -0
  51. dbt_preflight-0.3.5/tests/dbt_project/target/graph_summary.json +1 -0
  52. dbt_preflight-0.3.5/tests/dbt_project/target/manifest.json +1 -0
  53. dbt_preflight-0.3.5/tests/dbt_project/target/semantic_manifest.json +1 -0
  54. dbt_preflight-0.3.5/tests/fixtures/cte_chain.sql +29 -0
  55. dbt_preflight-0.3.5/tests/fixtures/explicit_columns.sql +38 -0
  56. dbt_preflight-0.3.5/tests/fixtures/select_star.sql +19 -0
  57. dbt_preflight-0.3.5/tests/fixtures/union_staging.sql +16 -0
  58. dbt_preflight-0.3.5/tests/fixtures/variant_access.sql +12 -0
  59. dbt_preflight-0.3.5/tests/fixtures/window_functions.sql +10 -0
  60. dbt_preflight-0.3.5/tests/test_adversarial_sql.py +573 -0
  61. dbt_preflight-0.3.5/tests/test_childmap_edge_cases.py +454 -0
  62. dbt_preflight-0.3.5/tests/test_ci_workflow_quality.py +329 -0
  63. dbt_preflight-0.3.5/tests/test_cli.py +1198 -0
  64. dbt_preflight-0.3.5/tests/test_column_ordering.py +250 -0
  65. dbt_preflight-0.3.5/tests/test_columns.py +296 -0
  66. dbt_preflight-0.3.5/tests/test_config.py +198 -0
  67. dbt_preflight-0.3.5/tests/test_dbt_cloud_layout.py +318 -0
  68. dbt_preflight-0.3.5/tests/test_dbt_e2e.py +161 -0
  69. dbt_preflight-0.3.5/tests/test_dialect_migration.py +608 -0
  70. dbt_preflight-0.3.5/tests/test_diff.py +260 -0
  71. dbt_preflight-0.3.5/tests/test_ecommerce_project.py +772 -0
  72. dbt_preflight-0.3.5/tests/test_example_project.py +230 -0
  73. dbt_preflight-0.3.5/tests/test_exception_audit.py +825 -0
  74. dbt_preflight-0.3.5/tests/test_false_safe_hunt.py +1299 -0
  75. dbt_preflight-0.3.5/tests/test_formatter.py +400 -0
  76. dbt_preflight-0.3.5/tests/test_github_pr_quality.py +602 -0
  77. dbt_preflight-0.3.5/tests/test_integration.py +222 -0
  78. dbt_preflight-0.3.5/tests/test_json_pipeline.py +782 -0
  79. dbt_preflight-0.3.5/tests/test_large_manifest.py +746 -0
  80. dbt_preflight-0.3.5/tests/test_manifest.py +487 -0
  81. dbt_preflight-0.3.5/tests/test_multi_dialect.py +237 -0
  82. dbt_preflight-0.3.5/tests/test_mutation_analysis.py +684 -0
  83. dbt_preflight-0.3.5/tests/test_null_safety.py +550 -0
  84. dbt_preflight-0.3.5/tests/test_oncall_triage.py +935 -0
  85. dbt_preflight-0.3.5/tests/test_package_developer.py +531 -0
  86. dbt_preflight-0.3.5/tests/test_packaging.py +335 -0
  87. dbt_preflight-0.3.5/tests/test_platform_deploy.py +698 -0
  88. dbt_preflight-0.3.5/tests/test_predict_exhaustive.py +1164 -0
  89. dbt_preflight-0.3.5/tests/test_predictor.py +943 -0
  90. dbt_preflight-0.3.5/tests/test_real_project.py +555 -0
  91. dbt_preflight-0.3.5/tests/test_run_subprocess.py +814 -0
  92. dbt_preflight-0.3.5/tests/test_snapshot_lifecycle.py +545 -0
  93. dbt_preflight-0.3.5/tests/test_snapshot_recovery.py +668 -0
  94. dbt_preflight-0.3.5/tests/test_stats_accuracy.py +634 -0
  95. dbt_preflight-0.3.5/tests/test_user_journeys.py +527 -0
  96. dbt_preflight-0.3.5/tests/test_verbose_debugging.py +688 -0
  97. dbt_preflight-0.3.5/uv.lock +1504 -0
@@ -0,0 +1,18 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ charset = utf-8
6
+ trim_trailing_whitespace = true
7
+ insert_final_newline = true
8
+
9
+ [*.py]
10
+ indent_style = space
11
+ indent_size = 4
12
+
13
+ [*.yml]
14
+ indent_style = space
15
+ indent_size = 2
16
+
17
+ [*.md]
18
+ trim_trailing_whitespace = false
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ concurrency:
10
+ group: ci-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ lint:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+ - run: pip install -e ".[dev]"
22
+ - run: ruff check src/ tests/
23
+ - run: ruff format --check src/ tests/
24
+
25
+ test:
26
+ runs-on: ubuntu-latest
27
+ strategy:
28
+ matrix:
29
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: ${{ matrix.python-version }}
35
+ - run: pip install -e ".[test]"
36
+ - run: pytest -v --cov=dbt_plan --cov-report=term-missing
@@ -0,0 +1,52 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ release:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: write
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+
18
+ # Verify tag matches pyproject.toml version
19
+ - name: Verify version consistency
20
+ run: |
21
+ TAG_VERSION="${GITHUB_REF_NAME#v}"
22
+ PKG_VERSION=$(python -c "
23
+ import re
24
+ text = open('pyproject.toml').read()
25
+ print(re.search(r'version\s*=\s*\"(.+?)\"', text).group(1))
26
+ ")
27
+ echo "Tag: $TAG_VERSION, Package: $PKG_VERSION"
28
+ if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
29
+ echo "ERROR: Tag $TAG_VERSION does not match pyproject.toml version $PKG_VERSION"
30
+ exit 1
31
+ fi
32
+
33
+ # Run tests before release
34
+ - name: Test gate
35
+ run: |
36
+ pip install -e ".[test]"
37
+ pytest -q
38
+
39
+ # Build
40
+ - run: pip install build
41
+ - run: python -m build
42
+
43
+ # PyPI first — fail fast before creating GitHub Release
44
+ - uses: pypa/gh-action-pypi-publish@release/v1
45
+ with:
46
+ password: ${{ secrets.PYPI_API_TOKEN }}
47
+
48
+ # GitHub Release only after PyPI succeeds
49
+ - uses: softprops/action-gh-release@v2
50
+ with:
51
+ files: dist/*
52
+ generate_release_notes: true
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ dist/
4
+ build/
5
+ .dbt-plan/
6
+ .pytest_cache/
7
+ *.pyc
8
+ .venv/
9
+ .env
10
+ .coverage
11
+ .claude/
12
+ tests/dbt_project/logs/
13
+ .ruff_cache/
14
+ tests/dbt_project/.dbt-plan/
15
+ tests/dbt_project/target/run_results.json
16
+ tests/dbt_project/target/partial_parse.msgpack
@@ -0,0 +1,141 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.3.5] - 2026-04-11
11
+
12
+ ### Added
13
+ - Real-world dbt SQL test fixtures (window functions, CTE chains, UNION ALL)
14
+ - 216 tests total, 93% coverage
15
+
16
+ ### Fixed
17
+ - mypy strict type annotations — 0 errors (deque[str], dict[str, Any])
18
+ - Release workflow: version-tag consistency check + test gate before publish
19
+
20
+ ## [0.3.4] - 2026-04-11
21
+
22
+ ### Fixed
23
+ - `dbt-plan run` no longer crashes when git is not installed (graceful error with fallback instructions)
24
+ - `dbt-plan run` detects non-git directories and shows manual workflow alternative
25
+ - `--select` with no matching changed models now warns on stderr
26
+
27
+ ### Changed
28
+ - README feature table updated to v0.3.3 with all current features
29
+ - 211 tests, 93% coverage
30
+
31
+ ## [0.3.3] - 2026-04-10
32
+
33
+ ### Fixed
34
+ - **Duplicate column names no longer produce FALSE SAFE**: columns with duplicates (e.g., from JOINs) now return REVIEW REQUIRED instead of potentially wrong SAFE
35
+
36
+ ### Changed
37
+ - Landing page: added "Safe by design" and "200+ tests" feature cards
38
+ - Test coverage: 206 tests, 93% overall, 6/8 modules at 100%
39
+
40
+ ## [0.3.2] - 2026-04-10
41
+
42
+ ### Changed
43
+ - PyPI classifier: `Alpha` → `Beta` (reflecting production readiness)
44
+ - Added License, Python version classifiers for PyPI discoverability
45
+ - Documentation URL added to PyPI metadata
46
+
47
+ ### Fixed
48
+ - README feature table version v0.2.0 → v0.3.1
49
+ - CONTRIBUTING.md stale version reference and Good First Issues
50
+ - CHANGELOG entries moved from Unreleased to proper version sections
51
+ - CI now enforces coverage threshold (`--cov` flag)
52
+
53
+ ### Added
54
+ - `SECURITY.md` with vulnerability reporting policy
55
+ - CI concurrency groups (cancel duplicate runs)
56
+ - 200 tests total, config.py at 100% coverage
57
+
58
+ ## [0.3.1] - 2026-04-08
59
+
60
+ ### Added
61
+ - **`compile_command` config**: customizable compile command via CLI flag, env var, or `.dbt-plan.yml`
62
+ - Supports `uv run dbt compile`, `poetry run dbt compile`, custom scripts
63
+ - Priority: CLI flag > env var > config file > default (`dbt compile`)
64
+ - **Landing page updates**: All Commands table, Configuration section, CI integration steps
65
+
66
+ ## [0.3.0] - 2026-04-08
67
+
68
+ ### Added
69
+ - **Cascade impact analysis**: detect downstream broken column references and build failures
70
+ - `BROKEN_REF`: downstream SQL references a dropped column (word-boundary matching)
71
+ - `BUILD_FAILURE`: downstream incremental with `on_schema_change=fail`
72
+ - Table/view downstream models checked for broken column refs (SQL will fail even though DDL is safe)
73
+ - Removed models trigger cascade analysis (all base columns treated as removed)
74
+ - `incremental+ignore` correctly skips cascade (no physical schema change)
75
+ - Safety escalation: cascade risks affect exit code (broken_ref → DESTRUCTIVE)
76
+ - Cascade risk count in summary line and JSON output
77
+ - Shown in all output formats (text, github, json)
78
+ - **Config change detection**: detect materialization and `on_schema_change` policy changes
79
+ - `MATERIALIZATION CHANGED: table -> incremental` shown as WARNING
80
+ - `on_schema_change CHANGED: ignore -> sync_all_columns` shown as WARNING
81
+ - Helps catch dangerous policy transitions (e.g., accumulated schema drift)
82
+ - **`dbt-plan run`**: one-command check (compile baseline → compile current → check)
83
+ - Stashes uncommitted changes, compiles baseline, restores, compiles current, runs check
84
+ - Requires dbt to be installed (convenience wrapper, not a core dependency)
85
+ - **`dbt-plan ci-setup`**: generates GitHub Actions workflow for dbt-plan CI
86
+ - Creates `.github/workflows/dbt-plan.yml` with snapshot → check → gate pipeline
87
+ - **Landing page**: `docs/index.html` for GitHub Pages
88
+
89
+ ### Fixed
90
+ - **Exit code for WARNING predictions**: `BUILD FAILURE`, `STALE COLUMNS`, and other WARNING-level predictions now correctly return `warning_exit_code` (default 2) instead of 0
91
+ - **Disabled models excluded**: models with `enabled: false` are no longer indexed, preventing false `MODEL REMOVED` warnings
92
+ - Exit code bounds validation: `warning_exit_code` now requires 0-255 range
93
+ - Graceful handling of unreadable downstream SQL files during cascade analysis
94
+ - `--format text` correctly overrides config `format: github`
95
+ - `_do_init` exit code consistency (1 → 2)
96
+ - Unknown `on_schema_change` shows operation name in output
97
+
98
+ ## [0.2.0] - 2026-04-06
99
+
100
+ ### Added
101
+ - **Config system**: `.dbt-plan.yml` + 7 environment variables (`DBT_PLAN_*`)
102
+ - **New commands**: `dbt-plan init` (generates config + updates .gitignore), `dbt-plan stats` (project analysis)
103
+ - **New flags**: `--format json`, `--select` / `-s`, `--verbose` / `-v`, `--no-color`, `--dialect`
104
+ - **Manifest column fallback**: resolves SELECT * models using dbt column definitions
105
+ - **Package model filtering**: auto-excludes dbt package models
106
+ - **Multi-dialect support**: snowflake, bigquery, postgres, mysql, duckdb, trino
107
+ - **CI workflow template**: `examples/ci-workflow/dbt-plan.yml` with PR comment posting
108
+ - **CI summary line**: grepable `dbt-plan: N checked, X safe, Y warning, Z destructive`
109
+ - **ANSI color output**: red/yellow/green safety labels (auto-disabled when piped)
110
+ - **PyPI publishing**: `pip install dbt-plan`
111
+
112
+ ### Fixed
113
+ - Qualified star (`SELECT t.*`) correctly returns `["*"]`
114
+ - Removed ephemeral models return SAFE (no physical object)
115
+ - Snapshot materialization handled explicitly (WARNING)
116
+ - Column reordering detected for `sync_all_columns`
117
+ - Stale column warnings for `append_new_columns`
118
+ - Unaliased expression ambiguity detection
119
+ - Flat compiled dir layout support
120
+ - Multi-project dir safety (ValueError on ambiguity)
121
+ - Actionable error messages
122
+ - Exit code 0 for no-args help
123
+
124
+ ### Performance
125
+ - O(1) node index, streaming manifest, SQL caching, lazy imports
126
+ - Memoized batch downstream BFS, file-size fast path
127
+
128
+ ## [0.1.0] - 2026-04-03
129
+
130
+ ### Added
131
+ - `dbt-plan check` command: diff compiled SQL and predict DDL impact
132
+ - `dbt-plan snapshot` command: save baseline compiled state + manifest
133
+ - SQLGlot-based column extraction (Snowflake dialect)
134
+ - DDL prediction rules for all materialization x on_schema_change combinations
135
+ - Downstream impact discovery via manifest child_map (BFS with cycle protection)
136
+ - Text and GitHub markdown output formats
137
+ - Exit codes: 0 (safe), 1 (destructive), 2 (parse error/warning)
138
+ - Parse failure safety: never returns SAFE when columns cannot be extracted
139
+ - SELECT * detection: returns WARNING instead of false predictions
140
+ - Removed model detection: DESTRUCTIVE regardless of materialization
141
+ - Base manifest fallback: finds removed models in snapshot manifest
@@ -0,0 +1,98 @@
1
+ # dbt-plan
2
+
3
+ ## Identity
4
+
5
+ dbt-plan은 `dbt run` 전에 위험을 경고하는 **정적 분석 도구**다.
6
+ 실행하지 않는다. Warehouse에 접속하지 않는다. 경고한다.
7
+
8
+ `terraform plan`의 dbt 버전. 모든 warehouse 지원 (Snowflake, BigQuery, Redshift, Postgres 등).
9
+
10
+ ## Core Principles
11
+
12
+ 1. **놓치면 안 된다 (False Safe 금지)**
13
+ - 파싱 실패 시 SAFE가 아니라 WARNING 반환 (None → REVIEW REQUIRED)
14
+ - 컬럼 추출 불가 시 절대 safe 반환 금지
15
+
16
+ 2. **오탐은 괜찮다 (False Warning 허용)**
17
+ - 위험하지 않은 변경에 WARNING은 OK
18
+ - 사용자가 `ignore_models`로 필터링 가능
19
+
20
+ 3. **가볍고 빠르다 (No Runtime Dependency)**
21
+ - sqlglot 외 런타임 의존성 없음
22
+ - Warehouse 접속 불필요
23
+ - 200개 모델 프로젝트에서 < 5초
24
+
25
+ 4. **CI 친화적이다**
26
+ - exit code로 판정 (0=safe, 1=destructive, 2=warning)
27
+ - JSON/GitHub markdown 출력
28
+ - 한 줄 요약 (grep 가능)
29
+
30
+ ## Scope — DO / DO NOT
31
+
32
+ ### DO (범위 안)
33
+ - 컴파일 SQL 컬럼 변경 감지
34
+ - materialization × on_schema_change 규칙 기반 위험도 판정
35
+ - 하위 모델 cascade 영향 분석 (broken ref, build failure)
36
+ - materialization/on_schema_change 설정 변경 감지
37
+
38
+ ### DO NOT (범위 밖)
39
+ - `dbt run` 시뮬레이션 — 런타임 동작은 범위 밖
40
+ - Warehouse 접속 — 순수 파일 분석만
41
+ - `full_refresh` 모드 판정 — 런타임 플래그는 CI 환경에서 결정
42
+ - `seed`/`source` 변경 감지 — 컴파일 SQL 기반 도구
43
+ - `pre_hook`/`post_hook` DDL 분석 — 복잡성 대비 가치 낮음
44
+
45
+ ## Architecture
46
+
47
+ ```
48
+ src/dbt_plan/
49
+ ├── columns.py # SQLGlot 기반 컬럼 추출 (multi-dialect)
50
+ ├── config.py # .dbt-plan.yml + env var 설정
51
+ ├── predictor.py # DDL 예측 규칙 + cascade 분석
52
+ ├── manifest.py # manifest.json 파싱, node index, downstream BFS
53
+ ├── diff.py # compiled SQL 디렉토리 비교 (캐싱)
54
+ ├── formatter.py # text (color) / github / json 출력
55
+ └── cli.py # CLI: snapshot, check, init, stats, run, ci-setup
56
+ ```
57
+
58
+ ## Development
59
+
60
+ ```bash
61
+ uv sync --extra test
62
+ make test
63
+ ```
64
+
65
+ ## Rules
66
+
67
+ - sqlglot 외 런타임 의존성 추가 금지
68
+ - 파싱 실패 시 safe 반환 절대 금지 — None 반환 → 호출자가 review로 처리
69
+ - 테스트 없는 기능 추가 금지 (TDD)
70
+ - SELECT \* → ["*"] 반환 (manifest column fallback 지원)
71
+ - Multi-dialect 지원 via --dialect (기본값: snowflake)
72
+ - `enabled: false` 모델은 인덱싱에서 제외
73
+
74
+ ## DDL Prediction Rules
75
+
76
+ | materialization | on_schema_change | DDL | Safety |
77
+ |---|---|---|---|
78
+ | table | * | CREATE OR REPLACE TABLE | SAFE |
79
+ | view | * | CREATE OR REPLACE VIEW | SAFE |
80
+ | ephemeral | * | (no physical object) | SAFE |
81
+ | snapshot | * | REVIEW REQUIRED | WARNING |
82
+ | incremental | ignore | no DDL | SAFE |
83
+ | incremental | fail | build failure | WARNING |
84
+ | incremental | append_new_columns | ADD COLUMN only | SAFE |
85
+ | incremental | sync_all_columns | ADD + DROP COLUMN | DESTRUCTIVE if removed |
86
+ | any | (model removed) | MODEL REMOVED | DESTRUCTIVE |
87
+ | any | (unknown osc) | UNKNOWN on_schema_change | WARNING |
88
+
89
+ ## Testing
90
+
91
+ ```bash
92
+ make test # all tests
93
+ make test-cov # with coverage
94
+ make lint # ruff check
95
+ pytest tests/test_columns.py # specific module
96
+ ```
97
+
98
+ Test fixtures in `tests/fixtures/` contain real-world compiled SQL patterns.
@@ -0,0 +1,70 @@
1
+ # Contributing to dbt-plan
2
+
3
+ ## Development Setup
4
+
5
+ ```bash
6
+ git clone https://github.com/PresentJay/dbt-plan
7
+ cd dbt-plan
8
+ uv sync --extra test # or: pip install -e ".[dev]"
9
+ make test # all tests should pass
10
+ dbt-plan --version # should show installed version
11
+ ```
12
+
13
+ ## Adding Features
14
+
15
+ 1. Write failing test first (TDD)
16
+ 2. Implement the minimal code to pass
17
+ 3. Run `make test` to verify
18
+ 4. Run `make lint` to check style
19
+ 5. Commit with conventional commits (`feat:`, `fix:`, `docs:`, `test:`)
20
+
21
+ ## Architecture
22
+
23
+ ```text
24
+ src/dbt_plan/
25
+ ├── columns.py # SQLGlot column extraction (multi-dialect)
26
+ ├── config.py # .dbt-plan.yml + env var configuration
27
+ ├── predictor.py # DDL prediction rules (materialization x on_schema_change)
28
+ ├── manifest.py # manifest.json parsing, node index, downstream BFS
29
+ ├── diff.py # compiled SQL directory comparison with caching
30
+ ├── formatter.py # text (color) / GitHub markdown / JSON output
31
+ └── cli.py # CLI: snapshot, check, init, stats, run, ci-setup
32
+ ```
33
+
34
+ Data flow: `diff_compiled_dirs` -> `extract_columns` -> `predict_ddl` -> `find_downstream_batch` -> `format_text/github/json`
35
+
36
+ ## Key Rules
37
+
38
+ - No runtime dependencies beyond sqlglot
39
+ - Parse failure must never return "safe" (return None, caller handles as WARNING)
40
+ - SELECT * must return `["*"]` with manifest column fallback
41
+ - Every feature needs tests before implementation
42
+ - Multi-dialect support via `--dialect` (default: snowflake)
43
+
44
+ ## Good First Issues
45
+
46
+ - Add compiled SQL fixtures in `tests/fixtures/` for edge cases (UNION, subqueries, MERGE)
47
+ - Add `pre-commit` hooks configuration
48
+ - Add type checking with mypy
49
+ - Add `SECURITY.md` with vulnerability reporting instructions
50
+
51
+ ## Testing
52
+
53
+ ```bash
54
+ make test # all tests (verbose)
55
+ make test-quick # quick run
56
+ make test-cov # with coverage report
57
+ make lint # ruff check
58
+ make format # auto-format
59
+ pytest -k "test_sync" # by name pattern
60
+ ```
61
+
62
+ Test fixtures in `tests/fixtures/` contain real-world compiled SQL patterns from production dbt projects.
63
+
64
+ ## Design Decisions
65
+
66
+ See [docs/architecture-decisions.md](docs/architecture-decisions.md) for the rationale behind key decisions:
67
+ - Why SQLGlot (ADR-2)
68
+ - Why INFORMATION_SCHEMA is needed (ADR-3)
69
+ - Why PR merge is the only interception point (ADR-4)
70
+ - DDL prediction rules from dbt-snowflake source (ADR-5)
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,26 @@
1
+ .PHONY: test test-quick test-cov lint format format-check dev clean
2
+
3
+ test:
4
+ uv run --extra test pytest -v
5
+
6
+ test-quick:
7
+ uv run --extra test pytest -q
8
+
9
+ test-cov:
10
+ uv run --extra test pytest --cov=dbt_plan --cov-report=term-missing
11
+
12
+ lint:
13
+ uv run ruff check src/ tests/
14
+
15
+ format:
16
+ uv run ruff format src/ tests/
17
+
18
+ format-check:
19
+ uv run ruff format --check src/ tests/
20
+
21
+ dev:
22
+ uv sync --extra test --extra dbt
23
+
24
+ clean:
25
+ rm -rf .venv .pytest_cache src/*.egg-info
26
+ find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true