Skip to content

Commit eb94c81

Browse files
committed
feat!: sensors as functions, provider secrets and a reworked sqb dev
Upgrade the server and every location together: 1. Pause schedules and sensors, start no manual runs, and leave the scheduler running. 2. Let queued and running runs finish, or cancel them. 3. Upgrade the server, which applies control store migrations 0004 and 0005. 4. Upgrade and restart every location, so each publishes again. 5. Resume schedules and sensors. A migrated source sensor fires once more for each source's current version. feat(sensors): sensors are decorated functions, with operator skip, a trial command, masked provider secrets and per-sensor failure isolation feat(providers): load provider settings from the project .env and stop runs that miss required secrets before they reach the warehouse feat(dev): rework the sqb dev terminal, with prompt stops and full errors feat(server): apply a job's settings and permissions to ad-hoc builds and plan previews that name it feat(location): resume dynamic models whose build went silent after each completed sync feat(ui): add people who sign in with passwords, edit roles inline, title every page and quiet the lineage hover feat(rules): add clause nodes to the custom-rule syntax tree fix(scheduler): isolate unreadable snapshots, triggers and requests so each fails on its own fix(worker): refuse a run request the worker can't fully read and keep the JSON report out of run output fix(format): format models whose whole body is one macro call on Snowflake fix(functions): let Rules read partitioned Python table function calls fix(test): test a function's current code or fail with T006, and read a partitioned call's fixture once fix(ui): draw a plan's graph and fit the Checks list perf(ui): share and revalidate one check list per location build(deps): pin SQLQuack 0.22.1 and SQLClean 0.11.1 BREAKING CHANGE: This release changes sensors, provider settings, sqb dev, the control API and custom Rules. - Sensors: `@sensor(description=..., when=...)` is always a decorator on the function it runs. The `sensor(..., run=...)` form, `run=` and the positional name are removed. The sensor is named after the function (or `name=`), returns `RunRequest(job=...)`, and its `SensorContext` carries `event`. Every sensor needs a serving location. - Sensors: migration 0005 deletes old-form sensors' tick history and pending work, hides them until their location publishes again, and makes run keys unique per job. - Provider settings: a default `.env` the parser rejects fails every command with exit 1. A provider field without a default counts as a required secret, whatever its type. Secret-typed fields with a default no longer appear in `sqb debug`. - Location health: reports require the provider list, so the server rejects a report from an older location. - Ad-hoc runs: run requests and plan work carry the named job's settings. An older location refuses those plans and runs such builds without the job's settings. - Job concurrency: a published job's `resolved_concurrency` is `{limit}`. Its `source` and the `ConcurrencySource` schema are removed, and `sqb build --verbose` no longer names the source. Until a location publishes again, its job pages, group runs and ad-hoc runs fail. - sqb dev: stopping cancels runs in flight, which can take up to 30 seconds. A second Ctrl+C or Ctrl+\ forces the stop. Ctrl+Z is unsupported. Exit statuses are 0 for q, 130 for Ctrl+C, 143 for SIGTERM, 129 for SIGHUP, 2 when it didn't start (including a failed first warehouse connection) and 1 when a service failed after it was ready. - sqb dev: plain output uses the live screen's step, problem and event lines. NO_COLOR only turns colour off; use --plain for plain output. Typed sign-in input isn't echoed. - sqb server: local workers run in their own process groups. A terminal's Ctrl+C reaches only the server, which stops them, and SIGHUP stops the server and scheduler like SIGTERM. - Custom Rules: the syntax tree's kinds are snake_case, such as `cte`, `join`, `subquery` and `star`, `nodes(kind=...)` matches them exactly, and clause nodes are new parents of their contents. - SQLClean: PostgreSQL, BigQuery and Databricks SQL nested more than 512 levels is reported as rules-unevaluated.
1 parent 3f8d8d9 commit eb94c81

820 files changed

Lines changed: 35641 additions & 5896 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/verify.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,8 @@ jobs:
10241024
needs: [changes, lockfile]
10251025
if: needs.changes.outputs.performance == 'true' && needs.changes.outputs.full == 'true'
10261026
runs-on: ubuntu-24.04
1027-
timeout-minutes: 45
1027+
# Two release builds: about 20 minutes on a warm cache, past 40 when Cargo.lock changed.
1028+
timeout-minutes: 60
10281029
strategy:
10291030
fail-fast: false
10301031
matrix:

‎Cargo.lock‎

Lines changed: 47 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ publish = false
8383
rust-version = "1.88"
8484

8585
[workspace.dependencies]
86+
# Reads the project env file with dotenv semantics; sqlx-postgres already depends on it.
87+
dotenvy = "0.15.7"
8688
argon2 = "0.5.3"
8789
axum = { version = "0.8", default-features = false, features = ["http1", "json", "query", "tokio"] }
8890
axum-server = { version = "0.8", default-features = false, features = ["tls-rustls-no-provider"] }
@@ -152,11 +154,15 @@ errno = "0.3"
152154
windows-sys = { version = "0.61", default-features = false, features = ["Win32_System_Diagnostics_Debug"] }
153155
# Recall's local store: SQLite compiled in, so every build has the same engine version.
154156
rusqlite = { version = "0.37", features = ["bundled", "column_decltype"] }
155-
rustix = { version = "1.1.4", default-features = false, features = ["fs", "process", "std", "stdio", "termios"] }
157+
rustix = { version = "1.1.4", default-features = false, features = ["event", "fs", "process", "pty", "std", "stdio", "termios"] }
156158
saphyr-parser = "0.1"
157159
regex = "1"
158160
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
159161
serde = { version = "1", features = ["derive"] }
162+
# Reports every field a decode ignores; a worker refuses a run request it can only partly read.
163+
serde_ignored = "0.1"
164+
# Names where a decode failed; with serde_ignored, a worker names any part of a run request it can't read.
165+
serde_path_to_error = "0.1"
160166
# Every crate relies on insertion-ordered JSON objects, which the extension has always built with.
161167
serde_json = { version = "1", features = ["preserve_order"] }
162168
sha2 = "0.10"
@@ -203,22 +209,22 @@ sqlbuild-scopes = { path = "crates/sqlbuild-scopes" }
203209
sqlbuild-sqltext = { path = "crates/sqlbuild-sqltext" }
204210
sqlbuild-state = { path = "crates/sqlbuild-state" }
205211
# SQL lint Rules, quality Rules and the formatter.
206-
sqlclean = { git = "https://github.com/sqlstack-io/sqlclean.git", rev = "bbc94e556dc51e936e86fa4c85111c87a7915fc5" }
212+
sqlclean = { git = "https://github.com/sqlstack-io/sqlclean.git", rev = "b0728bb990b7d8ff196cb00cc20545f2fa4df555" }
207213
# SQL change fingerprints over SQLQuack's tokenizers.
208-
sqlquack-fingerprint = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890", features = ["bigquery", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
214+
sqlquack-fingerprint = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed", features = ["bigquery", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
209215
# Scopes, name resolution, types and lineage for the native analysis route.
210-
sqlquack-semantics = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890", features = ["bigquery", "clickhouse", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
216+
sqlquack-semantics = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed", features = ["bigquery", "clickhouse", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
211217
# SQLQuack's Snowflake-family parser and tokenizer, reached as SQLQuack exposes them.
212-
sqlquack-parse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
218+
sqlquack-parse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
213219
# SQLQuack's syntax tree and lossless tokens.
214-
sqlquack-syntax = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
215-
sqlquack-syntax-bigquery = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
216-
sqlquack-syntax-clickhouse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
217-
sqlquack-syntax-databricks = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
218-
sqlquack-syntax-duckdb = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
219-
sqlquack-syntax-postgres = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
220-
sqlquack-syntax-sqlite = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
221-
sqlquack-syntax-sqlserver = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
220+
sqlquack-syntax = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
221+
sqlquack-syntax-bigquery = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
222+
sqlquack-syntax-clickhouse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
223+
sqlquack-syntax-databricks = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
224+
sqlquack-syntax-duckdb = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
225+
sqlquack-syntax-postgres = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
226+
sqlquack-syntax-sqlite = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
227+
sqlquack-syntax-sqlserver = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
222228
stacker = "0.1"
223229
# Counts heap allocations in growth tests, which measure work instead of time.
224230
stats_alloc = "0.1"

‎benchmarks/duckshop/edge_cases/named_selectors/orchestration/sensors/on_orders_built_sensor.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from orchestration.sensors._orders_conditions import landed_after
44

5-
from sqlbuild.orchestration import sensor
5+
from sqlbuild.orchestration import RunRequest, sensor
66

7-
on_orders_built = sensor(
8-
"on_orders_built_sensor",
7+
8+
@sensor(
99
description="Refresh order totals after the totals model",
1010
when=landed_after("order_totals"),
11-
run="orders_folder_job",
1211
)
12+
def on_orders_built_sensor(ctx):
13+
return RunRequest(job="orders_folder_job")
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""A condition whose select is not a string literal cannot be counted and is reported."""
22

3-
from sqlbuild.orchestration import node_event, sensor
3+
from sqlbuild.orchestration import RunRequest, node_event, sensor
44

55
ORDERS_SELECTION = "stg_orders"
66

7-
on_orders_computed = sensor(
8-
"on_orders_computed_sensor",
7+
8+
@sensor(
99
description="Refresh totals when staged orders change",
1010
when=node_event(select=ORDERS_SELECTION, kinds=["success"]),
11-
run="orders_folder_job",
1211
)
12+
def on_orders_computed_sensor(ctx):
13+
return RunRequest(job="orders_folder_job")
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Starts the repair job when any of four models fails: one over the limit, bound to a name."""
22

3-
from sqlbuild.orchestration import node_event, sensor
3+
from sqlbuild.orchestration import RunRequest, node_event, sensor
44

55
ORDERS_FAILED = node_event(
66
select="stg_orders stg_payments int_orders order_totals", kinds=["failure"]
77
)
88

9-
on_orders_failure = sensor(
10-
"on_orders_failure_sensor",
9+
10+
@sensor(
1111
description="Repair orders after a failure",
1212
when=ORDERS_FAILED,
13-
run="orders_repair_job",
1413
)
14+
def on_orders_failure_sensor(ctx):
15+
return RunRequest(job="orders_repair_job")

‎benchmarks/duckshop/edge_cases/named_selectors/orchestration/sensors/on_orders_landed_sensor.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from orchestration.sensors._orders_conditions import ORDERS_LANDED
44

5-
from sqlbuild.orchestration import sensor
5+
from sqlbuild.orchestration import RunRequest, sensor
66

7-
on_orders_landed = sensor(
8-
"on_orders_landed_sensor",
7+
8+
@sensor(
99
description="Refresh order totals after orders land",
1010
when=ORDERS_LANDED,
11-
run="orders_folder_job",
1211
)
12+
def on_orders_landed_sensor(ctx):
13+
return RunRequest(job="orders_folder_job")

‎benchmarks/duckshop/edge_cases/named_selectors/orchestration/sensors/on_tick_overdue_sensor.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from orchestration.sensors._orders_conditions import TICK_OVERDUE
44

5-
from sqlbuild.orchestration import sensor
5+
from sqlbuild.orchestration import RunRequest, sensor
66

7-
on_tick_overdue = sensor(
8-
"on_tick_overdue_sensor",
7+
8+
@sensor(
99
description="Repair orders after an overdue tick",
1010
when=TICK_OVERDUE,
11-
run="orders_repair_job",
1211
)
12+
def on_tick_overdue_sensor(ctx):
13+
return RunRequest(job="orders_repair_job")

‎benchmarks/duckshop/edge_cases/orchestration/attached_checks.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"cancelled": "import signal\nfrom sqlbuild.checks import check\nfrom sqlbuild.refs import model\n@check(depends_on=model('orders'), description='Heartbeat cancellation interrupts the driver without SIGTERM.')\ndef orders_valid(ctx):\n signal.signal(signal.SIGTERM, signal.SIG_IGN)\n ctx.query('WITH RECURSIVE pending(i) AS ((SELECT i FROM range(10000000000) AS seed(i) LIMIT 1) UNION ALL SELECT i FROM pending) SELECT sum(i) FROM pending')\n return ctx.pass_()\n",
66
"on_failure_job": "name = \"annual_orders_job\"\ndescription = \"Build orders.\"\nselect = \"orders\"\nschedule = { cron = \"0 0 * * *\", timezone = \"UTC\", starts_at = \"2000-01-01T00:00:00Z\" }\n",
77
"on_failure_destination": "name = \"refresh_inventory_job\"\ndescription = \"Refresh inventory.\"\nselect = \"inventory\"\n",
8-
"on_failure_sensor": "from sqlbuild.orchestration import NodeEventKind, node_event, sensor\n\nfailed_orders = sensor(\n 'failed_orders_sensor',\n description='React to an actual orders check failure.',\n when=node_event(select='check:orders_valid', kinds=[NodeEventKind.FAILED]),\n run='refresh_inventory_job',\n minimum_interval_seconds=1,\n)\n",
8+
"on_failure_sensor": "from sqlbuild.orchestration import NodeEventKind, RunRequest, node_event, sensor\n\n\n@sensor(\n description='React to an actual orders check failure.',\n when=node_event(select='check:orders_valid', kinds=[NodeEventKind.FAILED]),\n minimum_interval_seconds=1,\n)\ndef failed_orders_sensor(ctx):\n return RunRequest(job='refresh_inventory_job')\n",
9+
"on_check_event_sensor": "from sqlbuild.orchestration import CheckEvent, CheckEventKind, RunRequest, SensorContext, check_event, sensor\n\n\n@sensor(\n description='React to any failed check on orders.',\n when=check_event(select='orders', kinds=[CheckEventKind.FAILED]),\n minimum_interval_seconds=1,\n)\ndef failed_orders_sensor(ctx: SensorContext[CheckEvent]):\n assert ctx.event.check == 'check:orders_valid' and ctx.event.status == CheckEventKind.FAILED\n return RunRequest(job='refresh_inventory_job')\n",
910
"inventory": "MODEL (description 'Inventory after check failure.', materialized table);\nSELECT 59 AS amount;\n"
1011
}

0 commit comments

Comments
 (0)