@sqlanvil/cli 1.32.9 → 1.33.0
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.
- package/README.md +522 -81
- package/bundle.js +965 -774
- package/package.json +1 -1
- package/worker_bundle.js +16 -12
- package/._LICENSE +0 -0
- package/._NOTICE +0 -0
- package/._README.md +0 -0
- package/._bundle.js +0 -0
- package/._package.json +0 -0
- package/._worker_bundle.js +0 -0
package/README.md
CHANGED
|
@@ -1,134 +1,575 @@
|
|
|
1
|
-
# SQLAnvil
|
|
1
|
+
# SQLAnvil CLI Reference
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- Mirror of sqlanvil-com src/content/docs/docs/reference/cli.md (published at
|
|
4
|
+
https://sqlanvil.com/docs/reference/cli/). The body below this comment is identical in both
|
|
5
|
+
files (only the header differs) — change one, change the other. -->
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
This page documents every command and flag of the `sqlanvil` CLI. The CLI's own help is the
|
|
8
|
+
authority for the version you have installed: `sqlanvil help` lists the commands and
|
|
9
|
+
`sqlanvil help <command>` lists that command's flags.
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
## Installation
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g @sqlanvil/cli
|
|
15
|
+
sqlanvil --version # sqlanvil 1.33.0 (Dataform core 3.0.71)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Node.js 20.19+ or 22.12+. `--version` reports the sqlanvil release and the Dataform core
|
|
19
|
+
release it is synced with.
|
|
20
|
+
|
|
21
|
+
## Invocation
|
|
10
22
|
|
|
11
|
-
|
|
23
|
+
```bash
|
|
24
|
+
sqlanvil <command> [positional arguments] [flags]
|
|
25
|
+
```
|
|
12
26
|
|
|
13
|
-
|
|
27
|
+
- **`project-dir`** is the first positional argument of most commands and defaults to the current
|
|
28
|
+
directory. Commands that read the project (`compile`, `run`, `test`, `validate`, `format`,
|
|
29
|
+
`install`, `init-creds`, `migrate-fix`) fail unless the directory contains a
|
|
30
|
+
`workflow_settings.yaml`. The one exception is `run --graph`, where the compiled graph is the
|
|
31
|
+
project.
|
|
32
|
+
- **Help**: `sqlanvil help run` and `sqlanvil run --help` are the same thing. Running `sqlanvil`
|
|
33
|
+
with no command prints the command list.
|
|
34
|
+
|
|
35
|
+
## Global behavior
|
|
36
|
+
|
|
37
|
+
- **Unknown flags are errors.** The CLI is strict: a misspelled flag fails with
|
|
38
|
+
`Unknown arguments: …` rather than being silently ignored, and a misspelled command gets a
|
|
39
|
+
"did you mean" suggestion.
|
|
40
|
+
- **List flags** (`--actions`, `--tags`) take space- or comma-separated values:
|
|
41
|
+
`--actions a b` and `--actions a,b` are equivalent.
|
|
42
|
+
- **Durations** (`--timeout`, `--execution-timeout`) accept values such as `30s`, `10m`, `2h`.
|
|
43
|
+
- **Boolean flags** can be negated with a `--no-` prefix: `--no-artifacts`,
|
|
44
|
+
`--no-test-connection`.
|
|
45
|
+
- **Exit codes**: `0` on success, `1` on any failure — compilation errors, a failed or timed-out
|
|
46
|
+
action, a failed unit test, a `validate` FAILURE or BLOCKED result, or `format --check` finding
|
|
47
|
+
unformatted files. This makes every command usable as a CI gate.
|
|
48
|
+
- **Ctrl-C** during `run` cancels in-flight actions; during `validate` it drops the temporary shadow
|
|
49
|
+
schemas before exiting.
|
|
50
|
+
- **Artifacts**: `compile` writes a queryable catalog, and `run` adds a run-history entry, as Parquet
|
|
51
|
+
under `target/` in the project directory. They are best-effort (a write failure never fails the
|
|
52
|
+
command) and read by `query`, `inspect` and `docs`. Add `target/` to your `.gitignore`. See
|
|
53
|
+
[Artifacts & Catalog](https://sqlanvil.com/docs/guides/artifacts/).
|
|
54
|
+
|
|
55
|
+
## Commands
|
|
56
|
+
|
|
57
|
+
| Command | Purpose | Needs a warehouse |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| [`init`](#init) | Create a new project | no |
|
|
60
|
+
| [`install`](#install) | Install the project's NPM dependencies | no |
|
|
61
|
+
| [`init-creds`](#init-creds) | Create a BigQuery credentials file interactively | yes (to test) |
|
|
62
|
+
| [`compile`](#compile) | Compile the project and print the graph | no |
|
|
63
|
+
| [`test`](#test) | Run the project's unit tests | yes |
|
|
64
|
+
| [`validate`](#validate) | Check every model's SQL against the warehouse planner without executing | yes |
|
|
65
|
+
| [`run`](#run) | Run the project | yes |
|
|
66
|
+
| [`query`](#query) | Run SQL over the project's artifacts | no |
|
|
67
|
+
| [`inspect`](#inspect) | Summarize the artifacts and the latest run | no |
|
|
68
|
+
| [`docs`](#docs) | Generate an HTML catalog of the project | no |
|
|
69
|
+
| [`format`](#format) | Format `.sqlx` and `.js` files | no |
|
|
70
|
+
| [`introspect`](#introspect) | Generate a declaration from a source table's schema | yes (the source) |
|
|
71
|
+
| [`migrate-dataform`](#migrate-dataform) | Convert a Dataform project to sqlanvil | no |
|
|
72
|
+
| [`migrate-fix`](#migrate-fix) | Finish a converted project's dialect rewrites | no |
|
|
73
|
+
| `help [command]` | Show help | no |
|
|
74
|
+
|
|
75
|
+
### `init`
|
|
14
76
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- **BigQuery** — full upstream support: partitioning, clustering, labels, materialized views, `MERGE`-based incremental upserts
|
|
77
|
+
```bash
|
|
78
|
+
sqlanvil init [project-dir] [default-database] [default-location]
|
|
79
|
+
```
|
|
19
80
|
|
|
20
|
-
|
|
81
|
+
Creates a new project: `workflow_settings.yaml`, `package.json`, a `.gitignore` that excludes
|
|
82
|
+
`.df-credentials*.json` and `node_modules/`, and a sample project. For Postgres, Supabase and
|
|
83
|
+
MySQL/MariaDB it also writes a starter `.df-credentials.json` for you to fill in.
|
|
21
84
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- **SQLX + YAML + JS** — three authoring modes: SQL with config blocks, `actions.yaml` bulk definitions, or the JavaScript API
|
|
85
|
+
| Flag | Default | Description |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| `--warehouse` | `supabase` | Target warehouse: `bigquery`, `postgres`, `supabase` or `mysql`. |
|
|
88
|
+
| `--interactive` | `false` | Guided setup: start a fresh project (warehouse, sample, credentials) or convert an existing Dataform project. Ignores the other arguments except `project-dir`, which seeds the directory prompt. |
|
|
89
|
+
| `--bare` | `false` | Skip the sample files; create empty (gitkept) directories only. |
|
|
90
|
+
| `--iceberg` | `false` | BigQuery only. Prompts for a workflow-level BigQuery Iceberg table configuration. |
|
|
29
91
|
|
|
30
|
-
|
|
92
|
+
`default-database` (the Google Cloud project ID) and `default-location` (for example `US` or
|
|
93
|
+
`europe-west2`) are **required for BigQuery** and ignored for the other warehouses.
|
|
31
94
|
|
|
32
|
-
|
|
95
|
+
### `install`
|
|
33
96
|
|
|
34
97
|
```bash
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
sqlanvil
|
|
40
|
-
|
|
98
|
+
sqlanvil install [project-dir]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Installs the NPM dependencies declared in the project's `package.json` (for example
|
|
102
|
+
[packages](https://sqlanvil.com/docs/guides/packages/)). No flags. If compilation fails with
|
|
103
|
+
`Could not find NPM dependencies`, run this first.
|
|
104
|
+
|
|
105
|
+
### `init-creds`
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
sqlanvil init-creds [project-dir]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**BigQuery only.** Asks for the dataset location and whether to use Application Default
|
|
112
|
+
Credentials or a service-account JSON key, then writes `.df-credentials.json`. For Postgres,
|
|
113
|
+
Supabase and MySQL, edit the template `init` wrote instead (see
|
|
114
|
+
[Credentials file](#credentials-file)).
|
|
115
|
+
|
|
116
|
+
| Flag | Default | Description |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `--test-connection` | `true` | Run `SELECT 1` with the new credentials before writing them. `--no-test-connection` skips it. |
|
|
119
|
+
|
|
120
|
+
### `compile`
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
sqlanvil compile [project-dir]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Compiles the project and prints a summary of the resulting graph. It never connects to a
|
|
127
|
+
warehouse. Exits `1` if the project has compilation errors.
|
|
128
|
+
|
|
129
|
+
| Flag | Default | Description |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| `--json` | `false` | Print the full compiled graph as JSON. This is the file `run --graph` accepts. |
|
|
132
|
+
| `--dot` | `false` | Print the dependency graph in Graphviz dot format. Mutually exclusive with `--json`. |
|
|
133
|
+
| `--watch` | `false` | Recompile whenever a file in the project changes (ignores `node_modules`). |
|
|
134
|
+
| `--actions`, `--tags`, `--include-deps`, `--include-dependents` | | Filter the **printed** graph. The whole project is still compiled, so `ref()`s resolve. See [Selecting actions](#selecting-actions). |
|
|
135
|
+
| `--quiet` | `false` | Less verbose output. Mutually exclusive with `--verbose`. |
|
|
136
|
+
| `--verbose` | `false` | More verbose output. |
|
|
137
|
+
| `--timeout` | none | Maximum time compilation may take, e.g. `30s`. |
|
|
138
|
+
| `--no-artifacts` | | Don't write the catalog under `target/`. |
|
|
139
|
+
|
|
140
|
+
Also accepts every [project-config flag](#project-config-flags).
|
|
141
|
+
|
|
142
|
+
### `test`
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
sqlanvil test [project-dir]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Compiles the project and runs its [unit tests](https://sqlanvil.com/docs/reference/test/) (actions
|
|
149
|
+
of `type: "test"`) against the warehouse. Exits `1` if any test fails, or if the project has no
|
|
150
|
+
unit tests.
|
|
151
|
+
|
|
152
|
+
| Flag | Default | Description |
|
|
153
|
+
|---|---|---|
|
|
154
|
+
| `--credentials` | `.df-credentials.json` | Credentials file. See [Other shared flags](#other-shared-flags). |
|
|
155
|
+
| `--json` | `false` | Print the test results as JSON. |
|
|
156
|
+
| `--timeout` | none | Maximum compilation time. |
|
|
157
|
+
|
|
158
|
+
Also accepts every [project-config flag](#project-config-flags).
|
|
159
|
+
|
|
160
|
+
### `validate`
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
sqlanvil validate [project-dir]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Checks every model's SQL against the warehouse's own planner without running it. On Postgres,
|
|
167
|
+
Supabase and MySQL that means `EXPLAIN`; on BigQuery it means a dry run. `validate` compiles into a
|
|
168
|
+
temporary, timestamped shadow schema and walks the graph in dependency order. After each model
|
|
169
|
+
passes, it creates an empty stub of that model so downstream `ref()`s resolve. The shadow schemas
|
|
170
|
+
are dropped at the end, and orphans left by interrupted runs are swept on the next run.
|
|
171
|
+
|
|
172
|
+
Each action reports one of:
|
|
173
|
+
|
|
174
|
+
- `PASS`: the planner accepted the SQL.
|
|
175
|
+
- `FAIL`: the planner rejected it. The error and its line and column are printed.
|
|
176
|
+
- `BLOCK`: the action depends on something that failed.
|
|
177
|
+
- `SKIP`: not validated (operations, imports).
|
|
178
|
+
|
|
179
|
+
Exits `1` on any `FAIL` or `BLOCK`. See the [Validate guide](https://sqlanvil.com/docs/guides/validate/).
|
|
180
|
+
|
|
181
|
+
| Flag | Default | Description |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `--actions`, `--tags`, `--include-deps`, `--include-dependents` | | Validate only the selected actions. See [Selecting actions](#selecting-actions). |
|
|
184
|
+
| `--credentials` | `.df-credentials.json` | Credentials file. |
|
|
185
|
+
| `--json` | `false` | Print the per-action results as JSON. |
|
|
186
|
+
| `--keep-shadow` | `false` | Leave the shadow schemas in place for debugging. |
|
|
187
|
+
| `--timeout` | none | Maximum compilation time. |
|
|
188
|
+
|
|
189
|
+
Also accepts every [project-config flag](#project-config-flags).
|
|
190
|
+
|
|
191
|
+
### `run`
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
sqlanvil run [project-dir]
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Compiles the project and executes it against the warehouse named by `warehouse:` in
|
|
198
|
+
`workflow_settings.yaml`. Exits `0` only if every action succeeded.
|
|
199
|
+
|
|
200
|
+
| Flag | Default | Description |
|
|
201
|
+
|---|---|---|
|
|
202
|
+
| `--actions`, `--tags`, `--include-deps`, `--include-dependents` | | Run only part of the graph. See [Selecting actions](#selecting-actions). |
|
|
203
|
+
| `--full-refresh` | `false` | Rebuild incremental tables from scratch. |
|
|
204
|
+
| `--dry-run` | | Check the run without applying changes. On **BigQuery** this is BigQuery's server-side dry run. On **Postgres, Supabase and MySQL** it runs [`validate`](#validate), because those warehouses have no native dry run. |
|
|
205
|
+
| `--run-tests` | | Run the project's unit tests first, and abort the run if any fail. |
|
|
206
|
+
| `--action-retry-limit` | `0` | Retry failed idempotent actions up to this many times. |
|
|
207
|
+
| `--graph` | | Run a stored compiled graph (the output of `compile --json`) instead of compiling. What runs is exactly what was compiled. See [Compile once, run later](#compile-once-run-later). |
|
|
208
|
+
| `--credentials` | `.df-credentials.json` | Credentials file. |
|
|
209
|
+
| `--json` | `false` | Only valid with `--dry-run`. It prints the execution plan (BigQuery) or the validation results (other warehouses) as JSON. Without `--dry-run` the CLI prints a notice and exits without running anything. |
|
|
210
|
+
| `--timeout` | none | Maximum **compilation** time. |
|
|
211
|
+
| `--execution-timeout` | none | Wall-clock deadline for the **whole run** (compilation plus every action), e.g. `15m`. When it expires, in-flight actions are cancelled, pending ones are skipped and the run fails. |
|
|
212
|
+
| `--job-labels` | | BigQuery only. Labels added to every BigQuery job, e.g. `team=data,pipeline=nightly`. |
|
|
213
|
+
| `--job-prefix` | | BigQuery only. Prefix for BigQuery job IDs: `--job-prefix nightly` gives `sqlanvil-nightly-<uuid>`. |
|
|
214
|
+
| `--no-artifacts` | | Don't write the catalog or run history under `target/`. |
|
|
215
|
+
|
|
216
|
+
Also accepts every [project-config flag](#project-config-flags).
|
|
217
|
+
|
|
218
|
+
Restrictions on `--graph`:
|
|
219
|
+
|
|
220
|
+
- It can't be combined with `--environment`, because environment overrides are applied at compile
|
|
221
|
+
time. Compile with `--environment`, then pass `--credentials` to the run.
|
|
222
|
+
- It can't be combined with `--dry-run` on Postgres, Supabase or MySQL, because validation
|
|
223
|
+
recompiles from source. Run `validate` on the project instead.
|
|
224
|
+
- If the graph was compiled by a different minor version of sqlanvil, `run` warns but still runs.
|
|
225
|
+
|
|
226
|
+
### `query`
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
sqlanvil query "<sql>" [project-dir]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Runs SQL over the project's artifacts with the bundled DuckDB. No warehouse is involved. The
|
|
233
|
+
available views are `actions`, `dependencies` and `columns` (written by `compile`) and `runs`
|
|
234
|
+
(written by `run`). Run `compile` first.
|
|
235
|
+
|
|
236
|
+
| Flag | Default | Description |
|
|
237
|
+
|---|---|---|
|
|
238
|
+
| `--json` | `false` | Print the rows as JSON instead of a table. |
|
|
239
|
+
|
|
240
|
+
### `inspect`
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
sqlanvil inspect [project-dir]
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Summarizes the artifacts: action counts by type, plus the latest run's status, success and
|
|
247
|
+
failure counts, wall time, and up to 20 failures with their error messages.
|
|
248
|
+
|
|
249
|
+
| Flag | Default | Description |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `--json` | `false` | Print the summary as JSON. |
|
|
252
|
+
|
|
253
|
+
### `docs`
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
sqlanvil docs [project-dir]
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Writes a self-contained HTML catalog of the project to `target/docs/index.html`, covering models,
|
|
260
|
+
types, tags, columns, dependencies and last-run status. It is built from the artifacts, so run
|
|
261
|
+
`compile` (or `run`) first. No flags.
|
|
262
|
+
|
|
263
|
+
### `format`
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
sqlanvil format [project-dir]
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Formats the project's files in place. By default that is every `.sqlx` and `.js` file under
|
|
270
|
+
`definitions/` and `includes/`.
|
|
271
|
+
|
|
272
|
+
| Flag | Default | Description |
|
|
273
|
+
|---|---|---|
|
|
274
|
+
| `--actions` | `{definitions,includes}/**/*.{js,sqlx}` | For `format`, these are **file globs** relative to the project directory, not action names. |
|
|
275
|
+
| `--check` | `false` | Change nothing. Exit `1` if any file would be reformatted. |
|
|
276
|
+
| `--ignore-js-files` | `false` | Skip `.js` files (with the default globs, only `.sqlx` is formatted). |
|
|
277
|
+
|
|
278
|
+
### `introspect`
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
sqlanvil introspect <connection> <tableRef> [project-dir]
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Reads a source table's schema through one of the named `connections:` in `workflow_settings.yaml`
|
|
285
|
+
and generates a declaration `.sqlx` with its `columnTypes`. Source types are mapped to the
|
|
286
|
+
warehouse's types. `tableRef` is `schema.table`, or just `table`. The source's credentials come
|
|
287
|
+
from the `connections` section of `.df-credentials.json`. See
|
|
288
|
+
[Foreign Data Wrappers](https://sqlanvil.com/docs/guides/foreign-wrappers/).
|
|
289
|
+
|
|
290
|
+
| Flag | Default | Description |
|
|
291
|
+
|---|---|---|
|
|
292
|
+
| `--output` | stdout | Write the declaration to this file instead of printing it. |
|
|
293
|
+
|
|
294
|
+
### `migrate-dataform`
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
sqlanvil migrate-dataform <source-dir> <out-dir>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Converts a Dataform project to sqlanvil. The source directory is never modified. The converted
|
|
301
|
+
project, plus `migration-report.md` and `migration-report.json`, are written to `out-dir`, which
|
|
302
|
+
must be empty. See [Migrate from Dataform](https://sqlanvil.com/docs/guides/migrate-dataform/).
|
|
303
|
+
|
|
304
|
+
| Flag | Default | Description |
|
|
305
|
+
|---|---|---|
|
|
306
|
+
| `--target-warehouse` | `supabase` | Where the converted project runs. `supabase` or `postgres` **moves** the warehouse: BigQuery sources become named connections and the SQL gets safe dialect rewrites plus inline `SQLANVIL-MIGRATE` markers. `bigquery` is a **tooling swap**: the project keeps running on BigQuery with its SQL and `bigquery: {}` blocks untouched. |
|
|
307
|
+
|
|
308
|
+
### `migrate-fix`
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
sqlanvil migrate-fix [project-dir]
|
|
41
312
|
```
|
|
42
313
|
|
|
43
|
-
|
|
44
|
-
|
|
314
|
+
The third phase of a migration (convert, introspect, fix). Run it after the converted project's
|
|
315
|
+
declarations have been introspected (`sh scripts/introspect_all.sh`, generated by
|
|
316
|
+
`migrate-dataform`). It expands
|
|
317
|
+
`SELECT * EXCEPT (...)` into explicit column lists and rewrites `GROUP BY ALL` as positional
|
|
318
|
+
ordinals; both need the source columns that introspection provides. It is safe to re-run. It
|
|
319
|
+
reports anything it couldn't resolve, rather than guessing, and exits `1` if anything is
|
|
320
|
+
unresolved.
|
|
321
|
+
|
|
322
|
+
| Flag | Default | Description |
|
|
323
|
+
|---|---|---|
|
|
324
|
+
| `--dry-run` | `false` | Report what would change without writing. |
|
|
325
|
+
|
|
326
|
+
## Selecting actions
|
|
327
|
+
|
|
328
|
+
`run`, `validate` and `compile` share four selection flags:
|
|
329
|
+
|
|
330
|
+
| Flag | Description |
|
|
331
|
+
|---|---|
|
|
332
|
+
| `--actions` | Action names or patterns. A bare name (`orders`) matches by unqualified name and errors if it's ambiguous; a qualified name (`analytics.orders`) matches exactly. `*` wildcards are allowed: `stg_*` matches unqualified names, and `analytics.*` matches qualified ones. |
|
|
333
|
+
| `--tags` | Select every action carrying any of these tags. Combines with `--actions` as a union. |
|
|
334
|
+
| `--include-deps` | Also select everything the selected actions depend on, transitively. Requires `--actions` or `--tags`. |
|
|
335
|
+
| `--include-dependents` | Also select everything downstream of the selected actions, transitively. Requires `--actions` or `--tags`. |
|
|
336
|
+
|
|
337
|
+
Without `--include-deps`, only the selected actions run, so their upstream tables must already
|
|
338
|
+
exist.
|
|
45
339
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
340
|
+
## Project-config flags
|
|
341
|
+
|
|
342
|
+
`compile`, `run`, `test` and `validate` accept these flags. Each one overrides a setting in
|
|
343
|
+
`workflow_settings.yaml` for a single invocation. When a flag is unset, the file's value applies.
|
|
344
|
+
|
|
345
|
+
| Flag | Overrides | Description |
|
|
346
|
+
|---|---|---|
|
|
347
|
+
| `--environment` | | Load a named environment from `environments:` in `workflow_settings.yaml`. That environment's `schemaSuffix`, `vars`, `defaultDatabase`, `defaultLocation` and `credentials` file apply. See [Named Environments](https://sqlanvil.com/docs/guides/environments/). |
|
|
348
|
+
| `--default-database` | `defaultProject` | Default database. On BigQuery, the Google Cloud project ID. |
|
|
349
|
+
| `--default-schema` | `defaultDataset` | Default schema (a dataset on BigQuery). |
|
|
350
|
+
| `--default-location` | `defaultLocation` | BigQuery only. Default location, e.g. `US`. |
|
|
351
|
+
| `--assertion-schema` | `defaultAssertionDataset` | Schema that assertions are written to. |
|
|
352
|
+
| `--database-suffix` | `projectSuffix` | Suffix appended to database names. |
|
|
353
|
+
| `--schema-suffix` | `datasetSuffix` | Suffix appended to schema names, e.g. `dev` gives `analytics_dev`. Letters, digits and underscores only. |
|
|
354
|
+
| `--table-prefix` | `namePrefix` | Prefix added to every table name. |
|
|
355
|
+
| `--vars` | `vars` | Variables in the form `--vars=key1=value1,key2=value2`, read as `sqlanvil.projectConfig.vars.key1`. Values can't contain `,` or `=`. |
|
|
356
|
+
| `--disable-assertions` | | Skip every assertion, built-in (`uniqueKey`, `nonNull`, `rowConditions`) and `type: "assertion"`. |
|
|
357
|
+
| `--default-reservation` | `defaultReservation` | BigQuery only. Reservation to run queries in. |
|
|
358
|
+
|
|
359
|
+
Precedence is **flags > `--environment` > `workflow_settings.yaml`**. `vars` merge key by key, so a
|
|
360
|
+
`--vars` key overrides that key and keeps the others.
|
|
361
|
+
|
|
362
|
+
## Other shared flags
|
|
363
|
+
|
|
364
|
+
| Flag | Commands | Description |
|
|
365
|
+
|---|---|---|
|
|
366
|
+
| `--credentials` | `run`, `test`, `validate` | Path to the credentials file, relative to the project directory. Defaults to `.df-credentials.json`. An explicit `--credentials` beats the environment's `credentials:`, which beats the default. |
|
|
367
|
+
| `--json` | `compile`, `run`, `test`, `validate`, `query`, `inspect` | Machine-readable output. |
|
|
368
|
+
| `--timeout` | `compile`, `run`, `test`, `validate` | Maximum compilation time. Use `--execution-timeout` on `run` to bound the whole run. |
|
|
369
|
+
| `--no-artifacts` | `compile`, `run` | Don't write Parquet artifacts under `target/`. |
|
|
370
|
+
|
|
371
|
+
## Credentials file
|
|
372
|
+
|
|
373
|
+
Warehouse connections, including secrets, live in `.df-credentials.json` in the project directory.
|
|
374
|
+
It is gitignored by `init` and must never be committed. Non-secret settings stay in
|
|
375
|
+
`workflow_settings.yaml`. The file's shape depends on `warehouse:`.
|
|
376
|
+
|
|
377
|
+
**Postgres / Supabase**: for Supabase, use the session pooler host, because the direct
|
|
378
|
+
`db.<ref>.supabase.co` host is IPv6-only.
|
|
379
|
+
|
|
380
|
+
```json
|
|
381
|
+
{
|
|
382
|
+
"host": "aws-1-us-east-1.pooler.supabase.com",
|
|
383
|
+
"port": 5432,
|
|
384
|
+
"database": "postgres",
|
|
385
|
+
"user": "postgres.your-project-ref",
|
|
386
|
+
"password": "…",
|
|
387
|
+
"sslMode": "require",
|
|
388
|
+
"defaultSchema": "public"
|
|
389
|
+
}
|
|
51
390
|
```
|
|
52
391
|
|
|
53
|
-
|
|
392
|
+
`sslMode` is one of `disable`, `allow`, `prefer`, `require`, `verify-ca`, `verify-full`.
|
|
393
|
+
|
|
394
|
+
**MySQL / MariaDB**:
|
|
54
395
|
|
|
55
396
|
```json
|
|
56
397
|
{
|
|
57
398
|
"host": "localhost",
|
|
58
|
-
"port":
|
|
59
|
-
"database": "
|
|
60
|
-
"user": "
|
|
61
|
-
"password": "
|
|
399
|
+
"port": 3306,
|
|
400
|
+
"database": "sqlanvil",
|
|
401
|
+
"user": "root",
|
|
402
|
+
"password": "…",
|
|
62
403
|
"sslMode": "disable"
|
|
63
404
|
}
|
|
64
405
|
```
|
|
65
406
|
|
|
66
|
-
|
|
407
|
+
`sslMode` is `disable` or `require`.
|
|
67
408
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
409
|
+
**BigQuery** (written by `init-creds`):
|
|
410
|
+
|
|
411
|
+
```json
|
|
412
|
+
{
|
|
413
|
+
"projectId": "my-gcp-project",
|
|
414
|
+
"location": "US",
|
|
415
|
+
"credentials": "{\"type\": \"service_account\", …}"
|
|
72
416
|
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
`credentials` is the service-account key JSON as a string. Omit it to use Application Default
|
|
420
|
+
Credentials (`gcloud auth application-default login`). `accessToken` takes a short-lived OAuth2
|
|
421
|
+
token instead, and wins over `credentials`.
|
|
422
|
+
|
|
423
|
+
Two optional sections can sit alongside the warehouse fields:
|
|
424
|
+
|
|
425
|
+
- **`connections`** holds credentials for named source connections, keyed by connection name. They
|
|
426
|
+
are used by `introspect` and by `run` for cross-warehouse sources. See
|
|
427
|
+
[Foreign Data Wrappers](https://sqlanvil.com/docs/guides/foreign-wrappers/).
|
|
428
|
+
- **`storage`** holds object-store credentials (`s3`, `gcs`) for file exports and imports on
|
|
429
|
+
Postgres/Supabase. See [File Exports](https://sqlanvil.com/docs/guides/exports/).
|
|
430
|
+
|
|
431
|
+
To keep one file per environment, name them `.df-credentials.<env>.json` (also gitignored) and
|
|
432
|
+
point each environment's `credentials:` at its file.
|
|
433
|
+
|
|
434
|
+
## Examples
|
|
435
|
+
|
|
436
|
+
### First-time project setup
|
|
437
|
+
|
|
438
|
+
```bash
|
|
439
|
+
# Supabase (the default warehouse) — then fill in .df-credentials.json
|
|
440
|
+
sqlanvil init my_project
|
|
441
|
+
cd my_project && sqlanvil install
|
|
442
|
+
|
|
443
|
+
# Postgres or MySQL/MariaDB
|
|
444
|
+
sqlanvil init my_project --warehouse postgres
|
|
445
|
+
|
|
446
|
+
# BigQuery — project ID and location are required
|
|
447
|
+
sqlanvil init my_project my-gcp-project US --warehouse bigquery
|
|
448
|
+
sqlanvil init-creds my_project
|
|
449
|
+
|
|
450
|
+
# Not sure? Answer a few questions instead
|
|
451
|
+
sqlanvil init --interactive
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Compiling and inspecting a project without touching the warehouse
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
# Human-readable summary
|
|
458
|
+
sqlanvil compile
|
|
459
|
+
|
|
460
|
+
# Full compiled graph as JSON, e.g. to pipe into jq
|
|
461
|
+
sqlanvil compile --json | jq '.tables[].target'
|
|
462
|
+
|
|
463
|
+
# Visualize the dependency graph
|
|
464
|
+
sqlanvil compile --dot | dot -Tsvg > graph.svg
|
|
465
|
+
|
|
466
|
+
# Show only part of the graph (the whole project still compiles)
|
|
467
|
+
sqlanvil compile --actions orders --include-deps
|
|
468
|
+
|
|
469
|
+
# Ask questions of the compiled catalog
|
|
470
|
+
sqlanvil query "select type, count(*) from actions group by 1"
|
|
471
|
+
sqlanvil docs && open target/docs/index.html
|
|
472
|
+
```
|
|
73
473
|
|
|
74
|
-
|
|
474
|
+
### Validating before running
|
|
475
|
+
|
|
476
|
+
```bash
|
|
477
|
+
# Check every model against the planner; nothing is executed
|
|
478
|
+
sqlanvil validate
|
|
479
|
+
|
|
480
|
+
# Just one model and everything it reads from
|
|
481
|
+
sqlanvil validate --actions orders --include-deps
|
|
482
|
+
|
|
483
|
+
# `run --dry-run` does the same on Postgres/Supabase/MySQL (a BigQuery dry run on BigQuery)
|
|
484
|
+
sqlanvil run --dry-run
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Running unit tests before deploying changes
|
|
488
|
+
|
|
489
|
+
```bash
|
|
490
|
+
sqlanvil test
|
|
491
|
+
|
|
492
|
+
# ...or fail a run early if tests don't pass
|
|
493
|
+
sqlanvil run --run-tests
|
|
75
494
|
```
|
|
76
495
|
|
|
77
|
-
|
|
496
|
+
### Running only part of a pipeline
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
# Run a specific table (by bare name or full schema.name) and everything downstream of it
|
|
500
|
+
sqlanvil run --actions orders --include-dependents
|
|
78
501
|
|
|
79
|
-
|
|
502
|
+
# Run everything tagged "daily", including their dependencies
|
|
503
|
+
sqlanvil run --tags daily --include-deps
|
|
80
504
|
|
|
81
|
-
|
|
505
|
+
# Rebuild the "events" incremental table from scratch
|
|
506
|
+
sqlanvil run --actions events --full-refresh
|
|
507
|
+
```
|
|
82
508
|
|
|
83
|
-
|
|
84
|
-
- Warehouses: [PostgreSQL](https://sqlanvil.com/docs/guides/postgres/) · [Supabase](https://sqlanvil.com/docs/guides/supabase/) · [MySQL/MariaDB](https://sqlanvil.com/docs/guides/mysql/) · [BigQuery](https://sqlanvil.com/docs/guides/bigquery/)
|
|
85
|
-
- [Cross-warehouse sources](https://sqlanvil.com/docs/guides/foreign-wrappers/) · [File Imports](https://sqlanvil.com/docs/guides/imports/) · [File Exports](https://sqlanvil.com/docs/guides/exports/) · [Python Script Actions](https://sqlanvil.com/docs/guides/python-actions/)
|
|
86
|
-
- [Validate](https://sqlanvil.com/docs/guides/validate/) · [Named Environments](https://sqlanvil.com/docs/guides/environments/) · [Artifacts & Catalog](https://sqlanvil.com/docs/guides/artifacts/)
|
|
87
|
-
- [Configs Reference](https://sqlanvil.com/docs/reference/configs/) · [What's New](https://sqlanvil.com/docs/whats-new/)
|
|
509
|
+
### Bounding how long a run is allowed to take
|
|
88
510
|
|
|
89
|
-
|
|
90
|
-
the
|
|
91
|
-
|
|
511
|
+
```bash
|
|
512
|
+
# Compilation must finish within 30s; the whole run (compile + execute) within 15 minutes
|
|
513
|
+
sqlanvil run --timeout 30s --execution-timeout 15m
|
|
514
|
+
```
|
|
92
515
|
|
|
93
|
-
|
|
516
|
+
### Targeting a different environment for one invocation
|
|
94
517
|
|
|
95
|
-
|
|
518
|
+
```bash
|
|
519
|
+
# Uses environments.dev from workflow_settings.yaml: its schema suffix, vars and credentials file
|
|
520
|
+
sqlanvil run --environment dev
|
|
96
521
|
|
|
522
|
+
# Or override individual settings directly
|
|
523
|
+
sqlanvil run --schema-suffix pr_123 --vars=region=eu
|
|
97
524
|
```
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
525
|
+
|
|
526
|
+
### Compile once, run later
|
|
527
|
+
|
|
528
|
+
Compile a pinned graph, review or store it, then run exactly that graph:
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
sqlanvil compile --environment prod --json > graph.json
|
|
532
|
+
sqlanvil run --graph graph.json --credentials .df-credentials.prod.json
|
|
105
533
|
```
|
|
106
534
|
|
|
107
|
-
|
|
535
|
+
### Iterating on SQLX during development
|
|
108
536
|
|
|
109
|
-
|
|
537
|
+
```bash
|
|
538
|
+
sqlanvil compile --watch
|
|
539
|
+
```
|
|
110
540
|
|
|
111
|
-
|
|
112
|
-
macOS and Linux:
|
|
541
|
+
### Checking formatting without modifying files
|
|
113
542
|
|
|
114
543
|
```bash
|
|
115
|
-
#
|
|
116
|
-
|
|
544
|
+
sqlanvil format --check # exits 1 if anything would change — use as a CI step
|
|
545
|
+
```
|
|
117
546
|
|
|
118
|
-
|
|
119
|
-
bazel test //core/... //cli/...
|
|
547
|
+
### Inspecting the last run
|
|
120
548
|
|
|
121
|
-
|
|
122
|
-
|
|
549
|
+
```bash
|
|
550
|
+
sqlanvil inspect
|
|
551
|
+
sqlanvil query "select readable_name, status from runs where run_id = (select max(run_id) from runs)"
|
|
123
552
|
```
|
|
124
553
|
|
|
125
|
-
|
|
126
|
-
|
|
554
|
+
### Tracking and labeling BigQuery jobs from a run
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
# Job IDs become sqlanvil-nightly-<uuid>; every job carries both labels
|
|
558
|
+
sqlanvil run --job-prefix nightly --job-labels team=data,pipeline=nightly
|
|
559
|
+
```
|
|
127
560
|
|
|
128
|
-
|
|
561
|
+
### Declaring a cross-warehouse source
|
|
129
562
|
|
|
130
|
-
|
|
563
|
+
```bash
|
|
564
|
+
# Write a declaration for bigquery_public's samples.shakespeare
|
|
565
|
+
sqlanvil introspect bigquery_public samples.shakespeare --output definitions/sources/shakespeare.sqlx
|
|
566
|
+
```
|
|
131
567
|
|
|
132
|
-
|
|
568
|
+
### Migrating a Dataform project
|
|
133
569
|
|
|
134
|
-
|
|
570
|
+
```bash
|
|
571
|
+
sqlanvil migrate-dataform ./dataform_project ./sqlanvil_project # 1. convert
|
|
572
|
+
(cd sqlanvil_project && sh scripts/introspect_all.sh) # 2. introspect sources
|
|
573
|
+
sqlanvil migrate-fix ./sqlanvil_project # 3. finish the dialect work
|
|
574
|
+
sqlanvil compile ./sqlanvil_project
|
|
575
|
+
```
|