bricksentry 0.1.18__tar.gz → 0.1.19__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.
- {bricksentry-0.1.18 → bricksentry-0.1.19}/CHANGELOG.md +13 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/PKG-INFO +2 -2
- {bricksentry-0.1.18 → bricksentry-0.1.19}/README.md +1 -1
- bricksentry-0.1.19/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/pyproject.toml +1 -1
- {bricksentry-0.1.18 → bricksentry-0.1.19}/scripts/render_demo_image.py +2 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/server.json +2 -2
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/demo.py +12 -1
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/history.py +19 -1
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/job_demo.py +6 -1
- bricksentry-0.1.19/templates/job-check/README.md +31 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/databricks_template_schema.json +22 -21
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/README.md.tmpl +5 -2
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +2 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_0114.py +61 -21
- bricksentry-0.1.18/deploy/databricks-app/requirements.txt +0 -1
- bricksentry-0.1.18/templates/job-check/README.md +0 -13
- {bricksentry-0.1.18 → bricksentry-0.1.19}/.gitignore +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/LICENSE +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/SECURITY.md +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/action.yml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/assess.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/backends/databricks_backend.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/cli.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/diff.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/job.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/models.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/policy.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/conftest.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_0110.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_0112.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_018.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_019.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_demo.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_diff.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.18 → bricksentry-0.1.19}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.19 (2026-11-12)
|
|
4
|
+
|
|
5
|
+
- `bricksentry demo` showed black boxes instead of colored verdict labels in macOS Terminal, which doesn't support 24-bit color. Terminals that don't set `COLORTERM=truecolor` now get the standard named colors; the others keep the website's colors.
|
|
6
|
+
- When the scratch schema's catalog doesn't exist, `check-last-change`, the job task and the demo task say so and how to fix it, instead of a raw `NO_SUCH_CATALOG` error.
|
|
7
|
+
- README: how to run the demo inside a Databricks or Jupyter notebook (`%pip install`, then `run_demo()`).
|
|
8
|
+
- The job template pins 0.1.19 by default.
|
|
9
|
+
|
|
10
|
+
Bundle template changes, already live because `bundle init` reads the template from GitHub:
|
|
11
|
+
|
|
12
|
+
- `tables` is optional: leave it empty to deploy only the demo job and see a block before choosing your own tables. The only input without a default is now `warehouse_id`. The demo question comes first.
|
|
13
|
+
- The template README documents non-interactive init (`--config-file`) for CI, scripts and AI agents.
|
|
14
|
+
- `scratch_schema` defaults to `<your default catalog>.bricksentry_scratch` instead of `main.bricksentry_scratch`. Workspaces without a `main` catalog had their first demo run fail with "catalog not found" instead of the intended BLOCK.
|
|
15
|
+
|
|
3
16
|
## 0.1.18 (2026-11-12)
|
|
4
17
|
|
|
5
18
|
See a block in your own workspace within minutes of `bundle init`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.19
|
|
4
4
|
Summary: Change-safety for Databricks pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
|
|
5
5
|
Project-URL: Homepage, https://bricksentry.org
|
|
6
6
|
Project-URL: Documentation, https://bricksentry.org/docs
|
|
@@ -69,7 +69,7 @@ Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
|
69
69
|
uvx --from "bricksentry[duckdb]" bricksentry demo
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
(Or `pip install "bricksentry[duckdb]"` and then `bricksentry demo`.) No Databricks account and nothing leaves your machine: it runs on a 20,000-row revenue table in local DuckDB. An AI agent previews a DELETE on a clone (production untouched), gets its pull request **blocked** for a join that duplicates 40 orders, fixes it, and is routed to the owners of a certified table downstream. Then a nightly pipeline commits a bad MERGE anyway: bricksentry finds it in the table history, skips the OPTIMIZE after it, **blocks** it for 25 duplicate keys, prints the `RESTORE` and applies it.
|
|
72
|
+
(Or `pip install "bricksentry[duckdb]"` and then `bricksentry demo`. In a Databricks or Jupyter notebook, run `%pip install "bricksentry[duckdb]"` in one cell, then `from bricksentry.demo import run_demo; run_demo()` in the next; on Databricks, add `dbutils.library.restartPython()` after the install.) No Databricks account and nothing leaves your machine: it runs on a 20,000-row revenue table in local DuckDB. An AI agent previews a DELETE on a clone (production untouched), gets its pull request **blocked** for a join that duplicates 40 orders, fixes it, and is routed to the owners of a certified table downstream. Then a nightly pipeline commits a bad MERGE anyway: bricksentry finds it in the table history, skips the OPTIMIZE after it, **blocks** it for 25 duplicate keys, prints the `RESTORE` and applies it.
|
|
73
73
|
|
|
74
74
|

|
|
75
75
|
|
|
@@ -22,7 +22,7 @@ Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
|
22
22
|
uvx --from "bricksentry[duckdb]" bricksentry demo
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
(Or `pip install "bricksentry[duckdb]"` and then `bricksentry demo`.) No Databricks account and nothing leaves your machine: it runs on a 20,000-row revenue table in local DuckDB. An AI agent previews a DELETE on a clone (production untouched), gets its pull request **blocked** for a join that duplicates 40 orders, fixes it, and is routed to the owners of a certified table downstream. Then a nightly pipeline commits a bad MERGE anyway: bricksentry finds it in the table history, skips the OPTIMIZE after it, **blocks** it for 25 duplicate keys, prints the `RESTORE` and applies it.
|
|
25
|
+
(Or `pip install "bricksentry[duckdb]"` and then `bricksentry demo`. In a Databricks or Jupyter notebook, run `%pip install "bricksentry[duckdb]"` in one cell, then `from bricksentry.demo import run_demo; run_demo()` in the next; on Databricks, add `dbutils.library.restartPython()` after the install.) No Databricks account and nothing leaves your machine: it runs on a 20,000-row revenue table in local DuckDB. An AI agent previews a DELETE on a clone (production untouched), gets its pull request **blocked** for a join that duplicates 40 orders, fixes it, and is routed to the owners of a certified table downstream. Then a nightly pipeline commits a bad MERGE anyway: bricksentry finds it in the table history, skips the OPTIMIZE after it, **blocks** it for 25 duplicate keys, prints the `RESTORE` and applies it.
|
|
26
26
|
|
|
27
27
|

|
|
28
28
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.19
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.19"
|
|
8
8
|
description = "Change-safety for Databricks pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import html
|
|
11
11
|
import io
|
|
12
|
+
import os
|
|
12
13
|
import re
|
|
13
14
|
import sys
|
|
14
15
|
from contextlib import redirect_stdout
|
|
@@ -25,6 +26,7 @@ BASIC = {30: "#1e293b", 31: "#e5484d", 32: "#22c55e", 33: "#e5a93b", 34: "#60a5f
|
|
|
25
26
|
def capture() -> str:
|
|
26
27
|
import click
|
|
27
28
|
|
|
29
|
+
os.environ["COLORTERM"] = "truecolor" # keep the website's exact verdict colors in the image
|
|
28
30
|
from bricksentry.demo import run_demo
|
|
29
31
|
|
|
30
32
|
buf = io.StringIO()
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.19",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.19",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -10,6 +10,7 @@ versions itself; on Databricks the same check reads Delta history.
|
|
|
10
10
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
|
+
import os
|
|
13
14
|
from pathlib import Path
|
|
14
15
|
from typing import Any
|
|
15
16
|
|
|
@@ -78,7 +79,17 @@ SELECT order_id, region, round(amount * 1.05, 2), status FROM sales.orders WHERE
|
|
|
78
79
|
"""
|
|
79
80
|
|
|
80
81
|
# Same verdict colors as the website: pass green, warn amber, needs_human orange, block red.
|
|
81
|
-
|
|
82
|
+
_RGB_COLORS: dict[str, Any] = {"pass": (29, 160, 100), "warn": (214, 160, 40), "needs_human": (235, 115, 40), "block": (210, 40, 50)}
|
|
83
|
+
# Terminals without 24-bit color (macOS Terminal.app) misread RGB codes, e.g. as a black
|
|
84
|
+
# background, so they get the standard named colors instead.
|
|
85
|
+
_NAMED_COLORS: dict[str, Any] = {"pass": "green", "warn": "yellow", "needs_human": "bright_yellow", "block": "red"}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _truecolor() -> bool:
|
|
89
|
+
return os.environ.get("COLORTERM", "").lower() in ("truecolor", "24bit")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
_COLORS: dict[str, Any] = _RGB_COLORS if _truecolor() else _NAMED_COLORS
|
|
82
93
|
|
|
83
94
|
|
|
84
95
|
def _verdict(v: str) -> str:
|
|
@@ -129,6 +129,24 @@ def _scratch_name(schema: str, table: str, version: int, run: str) -> str:
|
|
|
129
129
|
return f"{schema}.bs_check_{short}_v{version}_{run}"
|
|
130
130
|
|
|
131
131
|
|
|
132
|
+
def _missing_catalog(e: Exception) -> bool:
|
|
133
|
+
m = str(e).upper()
|
|
134
|
+
return any(k in m for k in ("NO_SUCH_CATALOG", "CATALOG_NOT_FOUND", "CATALOG DOES NOT EXIST"))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _ensure_scratch(db: Any, schema: str) -> None:
|
|
138
|
+
try:
|
|
139
|
+
db.ensure_schema(schema)
|
|
140
|
+
except Exception as e:
|
|
141
|
+
if _missing_catalog(e):
|
|
142
|
+
where = f"catalog {schema.split('.')[0]!r}" if "." in schema else "the default catalog"
|
|
143
|
+
raise RuntimeError(
|
|
144
|
+
f"The scratch schema {schema} is in {where}, which doesn't exist in this "
|
|
145
|
+
"workspace or you can't use it. Set the scratch schema (sandbox_schema, or --scratch-schema in a "
|
|
146
|
+
"job) to catalog.schema in a catalog you can create tables in.") from None
|
|
147
|
+
raise
|
|
148
|
+
|
|
149
|
+
|
|
132
150
|
def check_change(
|
|
133
151
|
sentry: Sentry,
|
|
134
152
|
table: str,
|
|
@@ -160,7 +178,7 @@ def check_change(
|
|
|
160
178
|
run = uuid.uuid4().hex[:8]
|
|
161
179
|
base = _scratch_name(scratch, table, change.base_version, run)
|
|
162
180
|
cand = _scratch_name(scratch, table, change.version, run)
|
|
163
|
-
db
|
|
181
|
+
_ensure_scratch(db, scratch)
|
|
164
182
|
try:
|
|
165
183
|
for target, v in ((base, change.base_version), (cand, change.version)):
|
|
166
184
|
try:
|
|
@@ -52,8 +52,13 @@ def run(argv: list[str] | None = None, backend: Any = None, out=print) -> int:
|
|
|
52
52
|
from bricksentry.backends.databricks_backend import DatabricksBackend
|
|
53
53
|
|
|
54
54
|
backend = DatabricksBackend(warehouse_id=args.warehouse_id)
|
|
55
|
+
from bricksentry.history import _ensure_scratch
|
|
56
|
+
|
|
55
57
|
t = backend.qualified(args.table)
|
|
56
|
-
|
|
58
|
+
try:
|
|
59
|
+
_ensure_scratch(backend, ".".join(args.table.split(".")[:2]))
|
|
60
|
+
except RuntimeError as e:
|
|
61
|
+
raise SystemExit(str(e)) from None
|
|
57
62
|
backend.execute(SEED_SQL.format(t=t))
|
|
58
63
|
out(f"Created {args.table}: 20,000 orders, one row per order_id.")
|
|
59
64
|
backend.execute(BAD_MERGE_SQL.format(t=t))
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Databricks Asset Bundle: check every pipeline run
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check
|
|
5
|
+
cd bricksentry_check && databricks bundle deploy
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
You're asked for the tables to watch, a SQL warehouse ID, a scratch schema, the policy and
|
|
9
|
+
(optionally) a Slack webhook secret. The bundle deploys a serverless job with a table update
|
|
10
|
+
trigger: when a watched table changes, the job checks the change (`bricksentry.job`, which uses
|
|
11
|
+
`bricksentry check-last-change`), alerts, and prints the `RESTORE` that undoes it. The generated
|
|
12
|
+
README shows how to put the same check inside your own pipeline job so a `block` stops the
|
|
13
|
+
tasks downstream.
|
|
14
|
+
|
|
15
|
+
## Without prompts (CI, scripts, AI agents)
|
|
16
|
+
|
|
17
|
+
`bundle init` asks its questions interactively. To answer them from a file instead:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cat > bricksentry-init.json <<'JSON'
|
|
21
|
+
{"project_name": "bricksentry_check", "demo": "yes", "tables": "",
|
|
22
|
+
"warehouse_id": "<your SQL warehouse ID>"}
|
|
23
|
+
JSON
|
|
24
|
+
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check \
|
|
25
|
+
--config-file bricksentry-init.json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Every other input has a default. `scratch_schema` defaults to `<your default catalog>.bricksentry_scratch`;
|
|
29
|
+
set it if you want the scratch tables elsewhere. The full list with descriptions is in
|
|
30
|
+
[`databricks_template_schema.json`](databricks_template_schema.json). Leave `tables` empty to
|
|
31
|
+
deploy only the demo job.
|
{bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/databricks_template_schema.json
RENAMED
|
@@ -9,44 +9,45 @@
|
|
|
9
9
|
"pattern_match_failure_message": "Use letters, digits and underscores only.",
|
|
10
10
|
"order": 1
|
|
11
11
|
},
|
|
12
|
-
"
|
|
12
|
+
"demo": {
|
|
13
13
|
"type": "string",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
14
|
+
"default": "yes",
|
|
15
|
+
"enum": [
|
|
16
|
+
"yes",
|
|
17
|
+
"no"
|
|
18
|
+
],
|
|
19
|
+
"description": "Add a demo job that makes a known-bad change to a demo table in your scratch schema, so your first run shows a block (recommended)",
|
|
17
20
|
"order": 2
|
|
18
21
|
},
|
|
22
|
+
"tables": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "Tables to watch, comma-separated catalog.schema.table names (up to 10). Leave empty to try only the demo first; you can add tables later",
|
|
25
|
+
"pattern": "^([A-Za-z0-9_]+\\.[A-Za-z0-9_]+\\.[A-Za-z0-9_]+(\\s*,\\s*[A-Za-z0-9_]+\\.[A-Za-z0-9_]+\\.[A-Za-z0-9_]+){0,9})?$",
|
|
26
|
+
"pattern_match_failure_message": "Enter 1 to 10 full names like main.sales.orders, separated by commas, or leave empty.",
|
|
27
|
+
"order": 3,
|
|
28
|
+
"default": ""
|
|
29
|
+
},
|
|
19
30
|
"keys": {
|
|
20
31
|
"type": "string",
|
|
21
32
|
"default": "",
|
|
22
33
|
"description": "Key columns for tables without a PRIMARY KEY: table=col1,col2 separated by ';' (e.g. main.sales.orders=order_id). Leave empty to use each table's PRIMARY KEY",
|
|
23
34
|
"pattern": "^(\\s*[A-Za-z0-9_]+\\.[A-Za-z0-9_]+\\.[A-Za-z0-9_]+\\s*=\\s*[A-Za-z0-9_]+(\\s*,\\s*[A-Za-z0-9_]+)*\\s*(;|$))*$",
|
|
24
35
|
"pattern_match_failure_message": "Use catalog.schema.table=col1,col2; separate tables with ';'. Or leave empty.",
|
|
25
|
-
"order":
|
|
36
|
+
"order": 4
|
|
26
37
|
},
|
|
27
38
|
"warehouse_id": {
|
|
28
39
|
"type": "string",
|
|
29
40
|
"description": "SQL warehouse ID (SQL Warehouses -> your warehouse -> Connection details)",
|
|
30
41
|
"pattern": "^[A-Za-z0-9]+$",
|
|
31
42
|
"pattern_match_failure_message": "Paste the warehouse ID only, e.g. 1a2b3c4d5e6f7a8b.",
|
|
32
|
-
"order":
|
|
43
|
+
"order": 5
|
|
33
44
|
},
|
|
34
45
|
"scratch_schema": {
|
|
35
46
|
"type": "string",
|
|
36
|
-
"default": "main.bricksentry_scratch",
|
|
37
|
-
"description": "catalog.schema for the temporary shallow clones (created if missing
|
|
47
|
+
"default": "{{if eq (default_catalog) \"\"}}main{{else}}{{default_catalog}}{{end}}.bricksentry_scratch",
|
|
48
|
+
"description": "catalog.schema for the temporary shallow clones and the demo table (created if missing). Defaults to your workspace's default catalog",
|
|
38
49
|
"pattern": "^[A-Za-z0-9_]+\\.[A-Za-z0-9_]+$",
|
|
39
50
|
"pattern_match_failure_message": "Use catalog.schema.",
|
|
40
|
-
"order": 5
|
|
41
|
-
},
|
|
42
|
-
"demo": {
|
|
43
|
-
"type": "string",
|
|
44
|
-
"default": "yes",
|
|
45
|
-
"enum": [
|
|
46
|
-
"yes",
|
|
47
|
-
"no"
|
|
48
|
-
],
|
|
49
|
-
"description": "Add a demo job that makes a known-bad change to a demo table in the scratch schema, so your first run shows a block (recommended)",
|
|
50
51
|
"order": 6
|
|
51
52
|
},
|
|
52
53
|
"policy": {
|
|
@@ -85,12 +86,12 @@
|
|
|
85
86
|
},
|
|
86
87
|
"bricksentry_version": {
|
|
87
88
|
"type": "string",
|
|
88
|
-
"default": "0.1.
|
|
89
|
+
"default": "0.1.19",
|
|
89
90
|
"description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
|
|
90
91
|
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
91
|
-
"pattern_match_failure_message": "Use a version like 0.1.
|
|
92
|
+
"pattern_match_failure_message": "Use a version like 0.1.19.",
|
|
92
93
|
"order": 10
|
|
93
94
|
}
|
|
94
95
|
},
|
|
95
|
-
"success_message": "\nCreated {{.project_name}}. Next:\n cd {{.project_name}}\n databricks bundle deploy\n{{if eq .demo \"yes\"}} databricks bundle run bricksentry_demo # about 2 minutes; ends red with BLOCK, which is the point\n{{end}}Then any change to the watched tables is checked automatically. See {{.project_name}}/README.md."
|
|
96
|
+
"success_message": "\nCreated {{.project_name}}. Next:\n cd {{.project_name}}\n databricks bundle deploy\n{{if eq .demo \"yes\"}} databricks bundle run bricksentry_demo # about 2 minutes; ends red with BLOCK, which is the point\n{{end}}{{if .tables}}Then any change to the watched tables is checked automatically. {{else}}To check your own tables, add them to resources/bricksentry_check.job.yml (see README.md). {{end}}See {{.project_name}}/README.md."
|
|
96
97
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# {{.project_name}}: bricksentry checks for your tables
|
|
2
2
|
|
|
3
|
-
This bundle deploys
|
|
3
|
+
{{if .tables}}This bundle deploys a serverless job, **bricksentry check ({{.project_name}})**. When any of
|
|
4
4
|
these tables changes, it runs and checks what changed:
|
|
5
5
|
|
|
6
6
|
{{.tables}}
|
|
7
|
-
|
|
7
|
+
{{else}}This bundle has no tables to watch yet{{if eq .demo "yes"}}, only the demo job{{end}}. To check your own tables, re-run
|
|
8
|
+
`databricks bundle init` with them, or copy the `bricksentry_check` job from the bricksentry
|
|
9
|
+
template README (https://github.com/bricksentry/bricksentry/tree/main/templates/job-check).
|
|
10
|
+
{{end}}
|
|
8
11
|
For each table it compares the version before the change with the version after it (two
|
|
9
12
|
shallow clones in `{{.scratch_schema}}`, dropped after the check; your tables are only read).
|
|
10
13
|
It reports rows added, removed and changed, duplicate or NULL keys, schema changes and totals
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# start a run; they have no data change, so the run just finishes ("nothing to check").
|
|
4
4
|
resources:
|
|
5
5
|
jobs:
|
|
6
|
+
{{- if .tables}}
|
|
6
7
|
bricksentry_check:
|
|
7
8
|
name: bricksentry check ({{.project_name}})
|
|
8
9
|
max_concurrent_runs: 1
|
|
@@ -57,6 +58,7 @@ resources:
|
|
|
57
58
|
# Pinned: serverless resolves the dependencies once and caches them, so a range
|
|
58
59
|
# would not pick up new releases. To upgrade, change the version and redeploy.
|
|
59
60
|
- bricksentry[databricks]=={{.bricksentry_version}}
|
|
61
|
+
{{- end}}
|
|
60
62
|
{{- if eq .demo "yes"}}
|
|
61
63
|
|
|
62
64
|
# Demo: makes a known-bad change to a demo table in {{.scratch_schema}}, then checks it.
|
|
@@ -306,7 +306,7 @@ def _render(text: str, values: dict) -> str:
|
|
|
306
306
|
"""Render the subset of Go templates the bundle uses: {{.x}}, {{`raw`}}, nested
|
|
307
307
|
{{if .x}} / {{if eq .x "y"}} ... {{end}}, with optional {{- trimming."""
|
|
308
308
|
text = re.sub(r"\{\{`(.*?)`\}\}", lambda m: m.group(1).replace("{{", "\x00").replace("}}", "\x01"), text)
|
|
309
|
-
tok = re.compile(r"(\s*)\{\{(-?) ?(if (?:eq )?\.\w+(?: \"[^\"]*\")?|end)\}\}")
|
|
309
|
+
tok = re.compile(r"(\s*)\{\{(-?) ?(if (?:eq )?\.\w+(?: \"[^\"]*\")?|else|end)\}\}")
|
|
310
310
|
|
|
311
311
|
def cond(expr: str) -> bool:
|
|
312
312
|
m = re.fullmatch(r"if (eq )?\.(\w+)(?: \"([^\"]*)\")?", expr)
|
|
@@ -321,6 +321,8 @@ def _render(text: str, values: dict) -> str:
|
|
|
321
321
|
expr = m.group(3)
|
|
322
322
|
if expr == "end":
|
|
323
323
|
stack.pop()
|
|
324
|
+
elif expr == "else":
|
|
325
|
+
stack[-1] = not stack[-1]
|
|
324
326
|
else:
|
|
325
327
|
stack.append(cond(expr))
|
|
326
328
|
pos = m.end()
|
|
@@ -332,18 +334,28 @@ def _render(text: str, values: dict) -> str:
|
|
|
332
334
|
return text.replace("\x00", "{{").replace("\x01", "}}")
|
|
333
335
|
|
|
334
336
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
337
|
+
TABLES = "main.sales.orders, main.sales.customers"
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
@pytest.mark.parametrize("slack,keys,demo,tables", [
|
|
341
|
+
("bricksentry/slack_webhook", "main.sales.orders=order_id", "yes", TABLES),
|
|
342
|
+
("", "", "no", TABLES), ("", "", "yes", TABLES), ("", "", "yes", ""),
|
|
343
|
+
])
|
|
344
|
+
def test_bundle_template_renders(slack, keys, demo, tables):
|
|
338
345
|
from pathlib import Path
|
|
339
346
|
|
|
340
347
|
import yaml
|
|
341
348
|
|
|
342
349
|
root = Path(__file__).resolve().parents[1] / "templates" / "job-check"
|
|
343
350
|
schema = json.loads((root / "databricks_template_schema.json").read_text())
|
|
351
|
+
# Databricks evaluates templated defaults at init; {{default_catalog}} is the workspace default
|
|
352
|
+
dc = 'if eq (default_catalog) ""}}main{{else}}{{default_catalog}}{{end}}'
|
|
353
|
+
assert schema["properties"]["scratch_schema"]["default"] == "{{" + dc + ".bricksentry_scratch"
|
|
344
354
|
values = {k: p.get("default", "") for k, p in schema["properties"].items()}
|
|
355
|
+
values["scratch_schema"] = "main.bricksentry_scratch"
|
|
345
356
|
assert values["bricksentry_version"] == __import__("bricksentry").__version__
|
|
346
|
-
|
|
357
|
+
assert [k for k, p in schema["properties"].items() if "default" not in p] == ["warehouse_id"]
|
|
358
|
+
values.update(tables=tables, warehouse_id="abc123", slack_secret=slack,
|
|
347
359
|
keys=keys, demo=demo)
|
|
348
360
|
for k, p in schema["properties"].items():
|
|
349
361
|
if "pattern" in p:
|
|
@@ -352,22 +364,25 @@ def test_bundle_template_renders(slack, keys, demo):
|
|
|
352
364
|
bundle = yaml.safe_load(_render((proj / "databricks.yml.tmpl").read_text(), values))
|
|
353
365
|
assert bundle["bundle"]["name"] == "bricksentry_check"
|
|
354
366
|
job_yml = yaml.safe_load(_render((proj / "resources" / "bricksentry_check.job.yml.tmpl").read_text(), values))
|
|
355
|
-
j = job_yml["resources"]["jobs"]["bricksentry_check"]
|
|
356
|
-
assert j["trigger"]["table_update"]["table_names"] == ["main.sales.orders", "main.sales.customers"]
|
|
357
|
-
task = j["tasks"][0]
|
|
358
|
-
params = task["spark_python_task"]["parameters"]
|
|
359
|
-
assert params[:2] == ["--tables", "{{job.trigger.table_update.updated_tables}}"]
|
|
360
|
-
assert "{{workspace.url}}/jobs/{{job.id}}/runs/{{job.run_id}}" in params
|
|
361
|
-
assert ("--slack-secret" in params) == bool(slack)
|
|
362
|
-
assert ("--keys" in params) == bool(keys)
|
|
363
|
-
assert task["max_retries"] == 0 and task["disable_auto_optimization"] is True
|
|
364
|
-
assert j["environments"][0]["spec"]["dependencies"] == [f"bricksentry[databricks]=={values['bricksentry_version']}"]
|
|
365
|
-
assert task["environment_key"] == j["environments"][0]["environment_key"]
|
|
366
|
-
assert j["environments"][0]["spec"]["dependencies"][0].startswith("bricksentry[databricks]")
|
|
367
|
-
# the job task's argv parses, and an unresolved trigger value falls back to --default-tables
|
|
368
|
-
args = job.build_parser().parse_args(params)
|
|
369
|
-
assert args.fail_on == "block" and args.since_minutes == 60
|
|
370
367
|
jobs = job_yml["resources"]["jobs"]
|
|
368
|
+
assert ("bricksentry_check" in jobs) == bool(tables)
|
|
369
|
+
j = jobs.get("bricksentry_check")
|
|
370
|
+
if j:
|
|
371
|
+
assert j["trigger"]["table_update"]["table_names"] == ["main.sales.orders", "main.sales.customers"]
|
|
372
|
+
task = j["tasks"][0]
|
|
373
|
+
params = task["spark_python_task"]["parameters"]
|
|
374
|
+
assert params[:2] == ["--tables", "{{job.trigger.table_update.updated_tables}}"]
|
|
375
|
+
assert "{{workspace.url}}/jobs/{{job.id}}/runs/{{job.run_id}}" in params
|
|
376
|
+
assert ("--slack-secret" in params) == bool(slack)
|
|
377
|
+
assert ("--keys" in params) == bool(keys)
|
|
378
|
+
assert task["max_retries"] == 0 and task["disable_auto_optimization"] is True
|
|
379
|
+
assert j["environments"][0]["spec"]["dependencies"] == [f"bricksentry[databricks]=={values['bricksentry_version']}"]
|
|
380
|
+
assert task["environment_key"] == j["environments"][0]["environment_key"]
|
|
381
|
+
assert j["environments"][0]["spec"]["dependencies"][0].startswith("bricksentry[databricks]")
|
|
382
|
+
# the job task's argv parses, and an unresolved trigger value falls back to --default-tables
|
|
383
|
+
args = job.build_parser().parse_args(params)
|
|
384
|
+
assert args.fail_on == "block" and args.since_minutes == 60
|
|
385
|
+
|
|
371
386
|
assert ("bricksentry_demo" in jobs) == (demo == "yes")
|
|
372
387
|
if demo == "yes":
|
|
373
388
|
dj = jobs["bricksentry_demo"]
|
|
@@ -379,11 +394,14 @@ def test_bundle_template_renders(slack, keys, demo):
|
|
|
379
394
|
assert dargs.since is None and dargs.since_minutes is None and dargs.fail_on == "block"
|
|
380
395
|
assert (dargs.slack_secret is not None) == bool(slack)
|
|
381
396
|
assert all(t["max_retries"] == 0 and t["disable_auto_optimization"] for t in dj["tasks"])
|
|
382
|
-
assert dj["environments"] ==
|
|
397
|
+
assert dj["environments"][0]["spec"]["dependencies"] == [
|
|
398
|
+
f"bricksentry[databricks]=={values['bricksentry_version']}"]
|
|
383
399
|
msg = _render(schema["success_message"], values)
|
|
384
400
|
assert ("bundle run bricksentry_demo" in msg) == (demo == "yes")
|
|
385
401
|
readme = _render((proj / "README.md.tmpl").read_text(), values)
|
|
386
402
|
assert ("See a block first" in readme) == (demo == "yes")
|
|
403
|
+
assert ("no tables to watch yet" in readme) == (not tables)
|
|
404
|
+
assert ("Then any change" in msg) == bool(tables)
|
|
387
405
|
assert "{{job.start_time.iso_datetime}}" in readme
|
|
388
406
|
assert (proj / "src" / "bricksentry_check.py").exists()
|
|
389
407
|
|
|
@@ -475,3 +493,25 @@ def test_job_demo_change_is_blocked_end_to_end():
|
|
|
475
493
|
text = "\n".join(lines)
|
|
476
494
|
assert code == 1 and "BLOCK" in text and "duplicate-keys: 25" in text
|
|
477
495
|
assert 'TO VERSION AS OF 1' in text
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def test_missing_scratch_catalog_message():
|
|
499
|
+
from bricksentry import job_demo
|
|
500
|
+
|
|
501
|
+
class NoCatalog(FakeDelta):
|
|
502
|
+
def ensure_schema(self, schema):
|
|
503
|
+
raise RuntimeError("[NO_SUCH_CATALOG_EXCEPTION] Catalog 'main' was not found. SQLSTATE: 42704")
|
|
504
|
+
|
|
505
|
+
with pytest.raises(RuntimeError, match="scratch is in the default catalog, which doesn't exist"):
|
|
506
|
+
sentry(NoCatalog()).check_change("sales.orders")
|
|
507
|
+
b = RecordingBackend()
|
|
508
|
+
b.ensure_schema = NoCatalog.ensure_schema.__get__(b)
|
|
509
|
+
with pytest.raises(SystemExit, match="Set the scratch schema"):
|
|
510
|
+
job_demo.run(["--table", "main.scratch.bricksentry_demo_orders"], backend=b)
|
|
511
|
+
|
|
512
|
+
class Other(FakeDelta):
|
|
513
|
+
def ensure_schema(self, schema):
|
|
514
|
+
raise RuntimeError("PERMISSION_DENIED")
|
|
515
|
+
|
|
516
|
+
with pytest.raises(RuntimeError, match="PERMISSION_DENIED"):
|
|
517
|
+
sentry(Other()).check_change("sales.orders")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.18
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Databricks Asset Bundle: check every pipeline run
|
|
2
|
-
|
|
3
|
-
```bash
|
|
4
|
-
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check
|
|
5
|
-
cd bricksentry_check && databricks bundle deploy
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
You're asked for the tables to watch, a SQL warehouse ID, a scratch schema, the policy and
|
|
9
|
-
(optionally) a Slack webhook secret. The bundle deploys a serverless job with a table update
|
|
10
|
-
trigger: when a watched table changes, the job checks the change (`bricksentry.job`, which uses
|
|
11
|
-
`bricksentry check-last-change`), alerts, and prints the `RESTORE` that undoes it. The generated
|
|
12
|
-
README shows how to put the same check inside your own pipeline job so a `block` stops the
|
|
13
|
-
tasks downstream.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.18 → bricksentry-0.1.19}/examples/databricks/bricksentry_hr_walkthrough.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.18 → bricksentry-0.1.19}/templates/job-check/template/{{.project_name}}/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|