Skip to content

Commit d159d0a

Browse files
authored
docs: reorganise the docs around what a user is doing and rewrite pages that bury their point (#1435)
* docs: make Refactoring the style exemplar and add opening and one-rule guidance * docs: regroup the sidebar by task and lead naming and column-migration pages with the normal path * docs: split testing, SQL macro and Recall reference pages and add project setup * docs: lead model migrations and sqb rename with the normal path * docs: remove history notes, engine names and adapter internals from user pages * docs: trim implementation detail from format, test, freshness, observability and scope pages * docs: remove duplicated sections and retitle compile, variables and observability pages * docs: label ambiguous sidebar entries, trim janitor and header-string detail, and regenerate the docs skill * docs: correct promotion, incremental failure, Snowflake metadata and rename-detection wording * docs: say Snowflake source probes may need a running warehouse * docs: draft contracts, reusable schemas, compile and configuration pages for check_declared_columns * docs: address follow-up review of contracts, schemas, configuration and build limits * docs: narrow schema-change and immediate-promotion wording on contracts and schemas
1 parent 3b7cbe3 commit d159d0a

154 files changed

Lines changed: 4232 additions & 4268 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.

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/CONTENTS.md‎

Lines changed: 91 additions & 75 deletions
Large diffs are not rendered by default.

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/audit.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Positional `SELECTOR` arguments work like `--select`, and both forms can be comb
2929
| `--concurrency` | Maximum number of audits to run concurrently (default: `1`) |
3030
| `--json` | Print structured audit results |
3131
| `--json-output` | Write structured audit results to a file |
32-
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/project-configuration.md#command-group-warehouses) and the connection warehouse |
32+
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses) and the connection warehouse |
3333

3434
## Concurrency
3535

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/build.md‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Online: https://sqlbuild.com/docs/cli/build/
1717
- Output
1818
- Deferred builds
1919
- Failure behavior
20+
- Limits
2021
- Fingerprints
2122
- Runtime artifacts
2223

@@ -61,7 +62,7 @@ own option. `--version` works only directly after `sqb`, as in `sqb --version`:
6162
| `--defer-sources-to` | Read managed source data from another target |
6263
| `--fail-fast` | Stop on first failure and skip remaining nodes |
6364
| `--concurrency` | Number of worker connections (default: 1) |
64-
| `--test-timeout <duration>` | Time limit for each unit test the build runs, such as `30s`, or `disabled`; see [Time limits](../concepts/testing.md#time-limits) |
65+
| `--test-timeout <duration>` | Time limit for each unit test the build runs, such as `30s`, or `disabled`; see [Time limits](../concepts/testing-reference.md#time-limits) |
6566
| `--verbose`, `-v` | Show lifecycle SQL inline after each model |
6667
| `--start-cursor` | Override the start cursor, typed from the selected incremental models' cursor type; fails with `S303` if the selection mixes timestamp and integer cursors. With no cursor model selected, an integer value is read as an integer cursor and anything else as an ISO timestamp |
6768
| `--end-cursor` | Override the end cursor, typed the same way as `--start-cursor` |
@@ -77,7 +78,7 @@ own option. `--version` works only directly after `sqb`, as in `sqb --version`:
7778
| `SELECTOR ...` | Positional selectors, the same as `--select` |
7879
| `--select`, `-s` | Select specific models, or unit tests by name (`test:<name>`); selecting only unit tests runs them without building models |
7980
| `--exclude` | Exclude specific models |
80-
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/project-configuration.md#command-group-warehouses) and the connection warehouse |
81+
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses) and the connection warehouse |
8182

8283
## Fast iteration
8384

@@ -219,6 +220,58 @@ skipped as for any other failure. Its row shows `TIMEOUT`. In the summary line,
219220
failures were timeouts. A timeout is a failure for the exit code: the build exits non-zero and its
220221
JSON `status` is `failed`.
221222

223+
## Limits
224+
225+
A target's [`execution_limits`](../concepts/project-configuration.md#execution-limits) cap a whole
226+
build, and a model's [`max_duration`](../concepts/models/configuration.md#execution-time-limit) caps
227+
one model.
228+
229+
### Model limit
230+
231+
When the build would run more models than `max_models`, the build stops before any clone, load or
232+
model runs, and says that nothing in the warehouse changed. `sqb plan` has no limit, so use it to
233+
check a broad selection.
234+
235+
### Duration limit
236+
237+
`max_duration` covers planning and the build. At the deadline SQLBuild starts no more work and
238+
cancels the statements still running. Where the warehouse has a statement time limit, each
239+
statement also gets only the time that remains.
240+
241+
| Adapter | Warehouse statement limit | Cancellation at the deadline | Longest accepted duration |
242+
|---------|---------------------------|------------------------------|---------------------------|
243+
| Snowflake | `STATEMENT_TIMEOUT_IN_SECONDS` per statement | Driver cancel request for the running query | 7 days |
244+
| DuckDB, MotherDuck | None | Connection interrupt | About 24 days |
245+
| PostgreSQL | `SET LOCAL statement_timeout` inside transactions; statements outside a transaction rely on cancellation | Driver cancel (`cancel_safe`) | About 24 days |
246+
| BigQuery | Job timeout (`job_timeout_ms`) on each query job | `jobs.cancel`; reported as requested, not confirmed | About 24 days |
247+
| Databricks | `STATEMENT_TIMEOUT` session setting, capped at 48 hours | Cursor cancel; reported as requested, not confirmed | About 24 days |
248+
| SQL Server | None; the driver's query timeout is process-wide | Driver cancel | About 24 days |
249+
| SQLite | None | Connection interrupt | About 24 days |
250+
251+
A duration timeout can come after earlier models finished, so its error says that warehouse changes
252+
may already have been made. A custom adapter that can't cancel a running statement can't be used
253+
with `max_duration`.
254+
255+
### Per-item time limits
256+
257+
Unit test, scenario and model limits (`test_timeout`, `scenario_timeout` and a model's
258+
`max_duration`) count running time only, from the item's first warehouse statement. Rollback and
259+
cleanup always run and don't count. Where a warehouse reports queueing separately, queued
260+
time doesn't count:
261+
262+
| Adapter | How the item limit is enforced | Queued time |
263+
|---------|--------------------------------|-------------|
264+
| Snowflake | `STATEMENT_TIMEOUT_IN_SECONDS` per statement, with a client-side backstop after a grace margin of half the limit (at least 30 seconds) | Excluded by the warehouse limit; the backstop counts it |
265+
| DuckDB, MotherDuck | Connection interrupt at the limit | Not applicable |
266+
| PostgreSQL | `SET LOCAL statement_timeout` inside transactions; cancellation at the limit | Lock waits count |
267+
| BigQuery | `jobs.cancel` at the limit; no job timeout, because a job timeout counts from job creation | Excluded: the clock stops while a job is pending |
268+
| Databricks | `STATEMENT_TIMEOUT` session setting and cursor cancel | May count |
269+
| SQL Server | Driver cancel at the limit | Lock waits count |
270+
| SQLite | Connection interrupt at the limit | Waits for the write lock count |
271+
272+
When limits nest, such as a model's unit tests inside its own limit, the earliest deadline applies.
273+
After a timeout, SQLBuild checks the connection and replaces it if it is no longer usable.
274+
222275
## Fingerprints
223276

224277
After a successful build, SQLBuild writes version identities to `_sqlbuild_fingerprints` in the target schema. These are used on subsequent runs to detect changes and skip unchanged work. A build writes a row only for a resource whose identity differs from its latest row, so a build that changes no definitions writes none. In a project with model migration history, every build writes a row for each resource it builds. See [Planning and Change Detection](../concepts/planning.md) for details.

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/check.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Positional `SELECTOR` arguments work like `--select`, and both forms can be comb
2727
| `--json` | Print check results as JSON |
2828
| `--json-output` | Write check results JSON to a file path |
2929
| `--vars` | Override project variables |
30-
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/project-configuration.md#command-group-warehouses) and the connection warehouse |
30+
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses) and the connection warehouse |
3131

3232
Selecting a non-check node is rejected; use [`sqb build`](build.md) to run tasks and assets.
3333

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/clone.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sqb --project-dir <path> clone --from <target> [--to <target>] [flags]
4444
| `--hard-copy` | Force physical table copies instead of zero-copy cloning |
4545
| `--select`, `-s` | Select specific models to clone |
4646
| `--exclude` | Exclude specific models from cloning |
47-
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/project-configuration.md#command-group-warehouses) and the connection warehouse |
47+
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `build` [warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses) and the connection warehouse |
4848

4949
## Examples
5050

@@ -95,4 +95,4 @@ allow_as_clone_destination = true
9595
The origin target must already contain the built relations being cloned. The destination
9696
connection's credentials must be able to read the origin namespace and create relations in the
9797
destination. Managed physical sources may bootstrap a destination that has not been built. See
98-
[Project Configuration](../concepts/project-configuration.md) for details.
98+
[Configuration reference](../concepts/project-configuration.md) for details.

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/compile.md‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Positional `SELECTOR` arguments work like `--select`, and both forms can be comb
7878
2. **Graph.** Resolves `__ref()`, `__source()` and `__seed()`, expands macros, and orders models
7979
by dependency.
8080
3. **SQL checks.** Parses and checks SQL, when SQL analysis is on. See
81-
[Semantic Compilation](../concepts/semantic-compilation.md).
81+
[What `sqb compile` checks](../concepts/semantic-compilation.md).
8282
4. **Column lineage.** Traces column-level dependencies across models.
8383
5. **Contracts.** Checks declared columns against the inferred query output.
8484
6. **Rules.** Runs the selected built-in Rules, then the selected custom Rules.
@@ -89,8 +89,7 @@ Positional `SELECTOR` arguments work like `--select`, and both forms can be comb
8989
Rules that need inferred types, such as `SQBRCONTRACT105`, are skipped when SQL analysis is off,
9090
and compile prints one note naming them.
9191

92-
`sqb compile` is authoritative for correctness, contracts, lineage and configured Rules. Rule
93-
findings block the artifacts. To check one Rule code or family without changing project
92+
Rule findings block the artifacts. To check one Rule code or family without changing project
9493
configuration, use [`sqb rules run`](rules.md).
9594

9695
### When Rules fail
@@ -170,19 +169,14 @@ error[K001]: declared column 'total_cents' was not found in statically inferred
170169
| `K001` | A declared column is missing from the query output |
171170
| `K002` | A column's inferred type doesn't match the declared type |
172171
| `K003` | A column's type can't be proven (with `type_enforcement` on) |
172+
| `K004` | A `nullable false` column can be null |
173+
| `K005` | A model with `contract enforced` outputs a column it doesn't list |
174+
| `K006` | A model with `contract enforced` lists no columns |
173175
| `K013` | A string literal fills an enum-typed column of an enforced contract but isn't a member of the enum (not checked on SQL Server) |
174176

175-
Which models are checked depends on `[settings] check_declared_columns`:
176-
177-
- `true` (default): a model with declared columns and no `contract` setting must output every
178-
declared column.
179-
- `false`: only models with `contract enforced` are shape-checked; declared columns elsewhere
180-
are metadata and audit targets.
181-
182-
Explicit type enforcement works with either value. Setting `false` is a project policy, not a
183-
way to silence an error: if a model is meant to have a contract, fix the query or the
184-
declaration. Errors on `contract enforced` models don't suggest changing the setting. See
185-
[Contracts](../concepts/models/contracts.md).
177+
Models without a `contract` setting are checked unless the project sets
178+
`[settings] check_declared_columns = false`; see [Contracts](../concepts/models/contracts.md). Don't
179+
turn the check off to silence one error: fix the query or the column list.
186180

187181
## Output
188182

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/contract.md‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
77
Online: https://sqlbuild.com/docs/cli/contract/
88

9-
Existing-schema comparison is explicitly online and read-only with respect to the warehouse.
9+
`sqb contract` compares a model's or source's declared columns with the table that already exists in
10+
the warehouse, or writes declarations from it. It reads the warehouse and never changes it. The
11+
target named by `--from` supplies the database and schema to read, using the project's connection.
1012

1113
## diff
1214

@@ -22,8 +24,22 @@ Reports declaration differences. Exit code `0` means agreement and `1` means dif
2224
sqb contract generate --from <target> [flags]
2325
```
2426

25-
Prints proposed declaration updates. Add `--write` to change repository files and `--overwrite` to
26-
replace conflicts rather than preserving authored declarations.
27+
Prints proposed declaration updates without changing files.
28+
29+
```bash
30+
# Fill in missing types and add warehouse columns missing from code
31+
sqb contract generate --from prod --select tag:commerce --write
32+
33+
# Also replace conflicting types and names, and remove columns the warehouse doesn't have
34+
sqb contract generate --from prod --select tag:commerce --write --overwrite
35+
```
36+
37+
Without `--overwrite`, generation keeps everything you wrote: existing types where they conflict,
38+
columns only in code, comments, descriptions, audits, nullability, enums, tags, freshness and loader
39+
settings. It never adds `contract enforced`; that stays your decision.
40+
41+
A shared `SCHEMA()` isn't changed from one model's columns; the conflict is reported instead. Writes
42+
are atomic, and SQLBuild recompiles the project afterwards and restores the old files if it fails.
2743

2844
## Flags
2945

@@ -37,7 +53,7 @@ replace conflicts rather than preserving authored declarations.
3753
| `--vars` | both | Override project variables |
3854
| `--write` | generate | Apply generated repository changes |
3955
| `--overwrite` | generate | Replace conflicting declarations; requires `--write` |
40-
| `--warehouse <name>` | both | Snowflake warehouse for this invocation; overrides the target's `query` [warehouse group](../concepts/project-configuration.md#command-group-warehouses) and the connection warehouse |
56+
| `--warehouse <name>` | both | Snowflake warehouse for this invocation; overrides the target's `query` [warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses) and the connection warehouse |
4157

42-
See [Contracts](../concepts/models/contracts.md#adopting-an-existing-schema) for ownership and safety
43-
guarantees.
58+
Sources can be selected like models, for example `--select source:raw_orders`. See
59+
[Contracts](../concepts/models/contracts.md) for what a contract checks.

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/dbt.md‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
77
Online: https://sqlbuild.com/docs/cli/dbt/
88

9+
## Contents
10+
11+
- sqb dbt plan
12+
- sqb dbt run
13+
- sqb dbt build
14+
- Flags
15+
- sqb dbt debug
16+
- Selectors
17+
- Configuration
18+
919
Orchestrate dbt and SQLBuild together. Each subcommand runs dbt first, then SQLBuild, with selection logic across both project graphs. dbt remains responsible for dbt-owned models; SQLBuild validates and executes SQLBuild-owned models downstream. See [Using SQLBuild with dbt](../concepts/dbt-compatibility/overview.md) for scope and selection behavior.
1020

1121
## sqb dbt plan
@@ -48,6 +58,40 @@ confirmation asks for the typed confirmation on an interactive terminal and refu
4858
build the affected models with `sqb build` and its allow flag instead, or relax the policy. A
4959
refusal at this point leaves completed dbt work in place and builds no SQLBuild models.
5060

61+
## Flags
62+
63+
`sqb dbt plan/run/build` declare the common flags directly. Anything declared goes **before** a `--` separator; any other raw dbt flag goes **after** it and is forwarded verbatim. A flag placed on the wrong side errors rather than silently reaching dbt.
64+
65+
```bash
66+
sqb dbt build --select path:models/marts --full-refresh
67+
```
68+
69+
Declared flags are routed to the right place automatically:
70+
71+
| Flag | Routed to | Notes |
72+
| ---- | --------- | ----- |
73+
| `--select` / `--exclude` | dbt | dbt resolves selection (see [Selection](../concepts/dbt-compatibility/selection.md)). |
74+
| `--vars` | dbt **and** SQLBuild | The same vars feed dbt's compile and SQLBuild's own variable resolution, so both sides see identical values. |
75+
| `--full-refresh` | dbt **and** SQLBuild | Requests a full rebuild on both sides. dbt and native SQLBuild models independently apply their model-level `full_refresh` setting, including `false` opt-outs. |
76+
| `--threads` | dbt (`--threads`) and SQLBuild (`--concurrency`) | |
77+
| `--target` / `--project-dir` / `--profiles-dir` / `--profile` / `--target-path` | dbt | Standard dbt locators. |
78+
79+
### `--vars`
80+
81+
`--vars` accepts the same JSON object dbt accepts, and SQLBuild passes it to **both** the underlying `dbt` invocation and its own variable resolution. That means a value referenced as `@@my_var` in SQLBuild model SQL (see [Variables and placeholders](../concepts/interpolation.md)) and as `{{ var('my_var') }}` in a dbt model both resolve to the value you passed. CLI vars take precedence over project and local config vars. You do not need to declare vars twice.
82+
83+
```bash
84+
sqb dbt build --select path:models/marts --vars '{"my_var": 1}'
85+
```
86+
87+
### Forwarding other dbt flags
88+
89+
For any native dbt flag SQLBuild does not declare, put it after `--` and it is passed straight to the `dbt` invocation untouched:
90+
91+
```bash
92+
sqb dbt build -- --log-level debug
93+
```
94+
5195
## sqb dbt debug
5296

5397
Run dbt diagnostics followed by SQLBuild diagnostics.
@@ -93,9 +137,9 @@ profiles_dir = "../profiles"
93137
target_path = "../dbt_project/target"
94138
```
95139

96-
See [Project Configuration](../concepts/project-configuration.md#dbt) for all fields.
140+
See [Using SQLBuild with dbt](../concepts/dbt-compatibility/overview.md#configuration) for all fields.
97141

98142
SQLBuild-owned work in `sqb dbt plan`, `run` and `build` connects with the target's `build`
99-
[warehouse group](../concepts/project-configuration.md#command-group-warehouses). dbt itself
143+
[warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses). dbt itself
100144
keeps using the warehouse from its profile. These commands do not accept `--warehouse`, because
101145
their remaining arguments pass through to dbt.

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/debug.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- generated-by: sqlbuild skills -->
22

3-
# debug
3+
# sqb debug
44

55
> Validate project configuration and test the warehouse connection.
66
@@ -22,7 +22,7 @@ The command reports four groups of checks:
2222

2323
**Runtime** - SQLBuild version, Python version, Python path, OS info.
2424

25-
**Configuration** - Finds and validates `sqlbuild_project.toml`, loads `sqlbuild_local.toml` if present, resolves the adapter, active target, connection, database, and schema. For Snowflake it also shows the warehouse each [command group](../concepts/project-configuration.md#command-group-warehouses) connects with and where that value came from.
25+
**Configuration** - Finds and validates `sqlbuild_project.toml`, loads `sqlbuild_local.toml` if present, resolves the adapter, active target, connection, database, and schema. For Snowflake it also shows the warehouse each [command group](../concepts/adapters/snowflake.md#command-group-warehouses) connects with and where that value came from.
2626

2727
**Providers** - Lists the [providers](../concepts/python-nodes/providers.md) the project defines.
2828

@@ -34,7 +34,7 @@ The command reports four groups of checks:
3434
|------|-------------|
3535
| `--no-connection` | Skip the connection and query tests. Useful for validating config without warehouse access. |
3636
| `--json` | Output results as JSON instead of formatted text. |
37-
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `query` [warehouse group](../concepts/project-configuration.md#command-group-warehouses) and the connection warehouse |
37+
| `--warehouse <name>` | Snowflake warehouse for this invocation; overrides the target's `query` [warehouse group](../concepts/adapters/snowflake.md#command-group-warehouses) and the connection warehouse |
3838

3939
## Example
4040

0 commit comments

Comments
 (0)