@sqlanvil/cli 1.32.8 → 1.32.10

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 CHANGED
@@ -1,134 +1,575 @@
1
- # SQLAnvil
1
+ # SQLAnvil CLI Reference
2
2
 
3
- **SQL workflow tool for BigQuery, Postgres, Supabase, and MySQL/MariaDB.**
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
- SQLAnvil is an open-source fork of [Dataform OSS](https://github.com/dataform-co/dataform) (Apache 2.0), extended with first-class PostgreSQL, Supabase, and MySQL/MariaDB support. Define your data transformations in SQLX, have SQLAnvil compile them to idiomatic SQL for your warehouse, and run, validate, and document the whole DAG from one CLI.
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
- > **SQLAnvil is not affiliated with or endorsed by Google.** The Dataform name and related marks are trademarks of Google LLC. See [NOTICE](https://github.com/SQLAnvil/sqlanvil/blob/main/NOTICE) for attribution.
11
+ ## Installation
8
12
 
9
- ---
13
+ ```bash
14
+ npm install -g @sqlanvil/cli
15
+ sqlanvil --version # sqlanvil 1.32.10 (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
- ## Features
23
+ ```bash
24
+ sqlanvil <command> [positional arguments] [flags]
25
+ ```
12
26
 
13
- **Four first-class warehouses** — each adapter generates its warehouse's own idiomatic SQL, not translated BigQuery:
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
- - **PostgreSQL** — native partitioning (RANGE/LIST/HASH), `INSERT … ON CONFLICT` upserts, btree/hash/gin/gist/brin indexes (unique, partial, `INCLUDE`, opclasses), tablespaces, fillfactor, materialized views with in-place refresh policies
16
- - **Supabase** — everything Postgres, plus RLS policies, Realtime publications, pgvector indexes, and Supabase Wrappers (FDW) as declarative actions
17
- - **MySQL / MariaDB** — one adapter validated against both engines: CTAS tables, `ON DUPLICATE KEY UPDATE` incremental upserts, the full `mysql: {}` config block (engine/charset/collation/rowFormat, secondary indexes incl. `FULLTEXT`/`SPATIAL` and prefix lengths, native partitioning), materialized-view emulation
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
- **Beyond transformation** — the pieces most SQL workflow tools leave outside the pipeline:
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
- - **Cross-warehouse sources** — read BigQuery or MySQL/MariaDB from a Postgres/Supabase warehouse via named `connections:`: a live FDW bridge (Supabase Wrappers) or **runner-extract** (the CLI reads the source at run time and materializes a plain `ref()`-able table — keyless BigQuery supported). `sqlanvil introspect` scaffolds the declarations
23
- - **File imports & exports** — `type: "import"` loads Parquet/CSV/JSON from `s3://`/`gs://`/local into a `ref()`-able table (DuckDB bridge on Postgres/Supabase, native `LOAD DATA` on BigQuery); `type: "export"` writes query results back out to files
24
- - **Python script actions** — `python:` in `actions.yaml` runs file-staging and glue scripts as first-class DAG nodes: ordered by dependencies, covered by run history, no warehouse credentials injected (scripts stage files; `import` loads them). SQLAnvil validates the declared environment — interpreter version, `requirements.txt` vs installed packages, syntax — and never installs anything
25
- - **`sqlanvil validate`** — EXPLAIN/dry-run the *whole DAG* against the live warehouse without executing: an isolated shadow schema of empty stubs lets every downstream `ref()` resolve; results classify as PASS / FAIL / BLOCKED so one real error doesn't cascade
26
- - **Queryable artifacts** — every compile/run writes a Parquet catalog + run history under `target/`; `sqlanvil query` runs SQL over them, `sqlanvil inspect` summarizes, `sqlanvil docs` renders a self-contained HTML catalog
27
- - **Release-artifact runs** — `sqlanvil run --graph <file>` executes a stored `compile --json` output exactly as compiled; **named environments** (`--environment`) give per-env schema suffixes and vars
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
- ## Quick start
95
+ ### `install`
33
96
 
34
97
  ```bash
35
- npm install -g @sqlanvil/cli
36
- sqlanvil init my-project
37
- cd my-project
38
- # edit workflow_settings.yaml + .df-credentials.json (see below)
39
- sqlanvil compile
40
- sqlanvil run
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
- **`workflow_settings.yaml` (Postgres/Supabase):** the warehouse is a flat string; connection
44
- secrets never live here.
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
- ```yaml
47
- warehouse: postgres # bigquery | postgres | supabase | mysql
48
- defaultDataset: public # the Postgres schema
49
- defaultAssertionDataset: sqlanvil_assertions
50
- sqlanvilCoreVersion: 1.20.1
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
- **`.df-credentials.json`** (gitignored) holds the connection:
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": 5432,
59
- "database": "analytics",
60
- "user": "sqlanvil_writer",
61
- "password": "...",
399
+ "port": 3306,
400
+ "database": "sqlanvil",
401
+ "user": "root",
402
+ "password": "…",
62
403
  "sslMode": "disable"
63
404
  }
64
405
  ```
65
406
 
66
- **First action (`definitions/my_view.sqlx`):**
407
+ `sslMode` is `disable` or `require`.
67
408
 
68
- ```sql
69
- config {
70
- type: "view",
71
- description: "My first SQLAnvil view."
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
- SELECT 1 AS id, 'hello' AS greeting
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
- ## Documentation
502
+ # Run everything tagged "daily", including their dependencies
503
+ sqlanvil run --tags daily --include-deps
80
504
 
81
- Full documentation at **[sqlanvil.com/docs](https://sqlanvil.com/docs/)**.
505
+ # Rebuild the "events" incremental table from scratch
506
+ sqlanvil run --actions events --full-refresh
507
+ ```
82
508
 
83
- - [Getting Started](https://sqlanvil.com/docs/getting-started/)
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
- Writing sqlanvil projects with an AI agent? Point it at [`AGENTS.md`](https://github.com/SQLAnvil/sqlanvil/blob/main/AGENTS.md) — it corrects
90
- the Dataform/BigQuery priors that otherwise produce broken sqlanvil code. Contributor/design
91
- docs live in the separate [`sqlanvil/docs`](https://github.com/sqlanvil/docs) repo.
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
- ## Project layout
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
- core/ Compiler + action types (table/view/incremental/assertion/operation/declaration/import/export/script/…)
99
- cli/ CLI entrypoint and per-adapter glue (cli/api/dbadapters/ — bigquery, postgres, supabase, mysql)
100
- protos/ Protobuf definitions for core/configs/execution/db_adapter
101
- tests/ Integration specs against real warehouses (Postgres, Supabase, MySQL/MariaDB, BigQuery)
102
- tools/ Bazel rules + Docker fixtures for the integration databases
103
- examples/ Sample SQLAnvil projects (see examples/supabase_bigquery_mailing_list)
104
- scripts/ ./scripts/run is the CLI entrypoint wrapper
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
- ## Building from source
537
+ ```bash
538
+ sqlanvil compile --watch
539
+ ```
110
540
 
111
- SQLAnvil uses [Bazel](https://bazel.build) 7 with bzlmod (via Bazelisk). Native Bazel works on
112
- macOS and Linux:
541
+ ### Checking formatting without modifying files
113
542
 
114
543
  ```bash
115
- # Run the CLI
116
- ./scripts/run help
544
+ sqlanvil format --check # exits 1 if anything would change — use as a CI step
545
+ ```
117
546
 
118
- # Run tests
119
- bazel test //core/... //cli/...
547
+ ### Inspecting the last run
120
548
 
121
- # Integration tests against a local Docker Postgres
122
- ./tools/postgres/run-postgres-db.sh
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
- A Docker-based build container (`./scripts/docker-bazel`) remains available as an optional
126
- hermetic environment. See [contributing.md](https://github.com/SQLAnvil/sqlanvil/blob/main/contributing.md) for full instructions.
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
- ## License
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
- Apache License 2.0. See [LICENSE](https://github.com/SQLAnvil/sqlanvil/blob/main/LICENSE) and [NOTICE](https://github.com/SQLAnvil/sqlanvil/blob/main/NOTICE).
568
+ ### Migrating a Dataform project
133
569
 
134
- SQLAnvil is a derivative of Dataform OSS (originally developed by Dataform Co and contributed to by Google LLC). It has been fully renamed and extended with first-class PostgreSQL/Supabase/MySQL support. Licensed under Apache License 2.0.
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
+ ```
package/bundle.js CHANGED
@@ -51159,8 +51159,8 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
51159
51159
  .filter(validationQuery => !!validationQuery.query);
51160
51160
  }
51161
51161
 
51162
- const version = "1.32.8";
51163
- const dataformVersion = "3.0.70";
51162
+ const version = "1.32.10";
51163
+ const dataformVersion = "3.0.71";
51164
51164
 
51165
51165
  async function build(compiledGraph, runConfig, dbadapter) {
51166
51166
  const prunedGraph = prune(compiledGraph, runConfig);
@@ -55013,7 +55013,8 @@ ProjectConfigOptions.assertionSchema = option("assertion-schema", {
55013
55013
  describe: "Default assertion schema. If unset, the value from workflow_settings.yaml is used."
55014
55014
  });
55015
55015
  ProjectConfigOptions.databaseSuffix = option("database-suffix", {
55016
- describe: "Default assertion schema. If unset, the value from workflow_settings.yaml is used."
55016
+ describe: "A suffix to be appended to output database names. If unset, the value from " +
55017
+ "workflow_settings.yaml is used."
55017
55018
  });
55018
55019
  ProjectConfigOptions.vars = option("vars", {
55019
55020
  describe: "Override for variables to inject via '--vars=someKey=someValue,a=b', referenced by " +
@@ -60291,8 +60292,8 @@ async function runValidate(argv) {
60291
60292
  }
60292
60293
  const validateCommand = {
60293
60294
  format: `validate [${projectDirMustExistOption.name}]`,
60294
- description: "Validate the project's SQL against the warehouse planner (EXPLAIN/dry-run) without " +
60295
- "executing. Postgres/Supabase/MySQL only.",
60295
+ description: "Validate the project's SQL against the warehouse planner without executing: EXPLAIN on " +
60296
+ "Postgres/Supabase/MySQL, a dry run on BigQuery.",
60296
60297
  positionalOptions: [projectDirMustExistOption],
60297
60298
  options: [
60298
60299
  actionsOption,
@@ -60329,7 +60330,7 @@ const executionTimeoutOption = option("execution-timeout", {
60329
60330
  coerce: (rawTimeoutString) => rawTimeoutString ? parseDuration__default["default"](rawTimeoutString) : null
60330
60331
  });
60331
60332
  const jobPrefixOption = option("job-prefix", {
60332
- describe: "Adds an additional prefix in the form of `sqlanvil-${jobPrefix}-`.",
60333
+ describe: "BigQuery only. Adds a prefix to BigQuery job IDs, in the form `sqlanvil-${jobPrefix}-`.",
60333
60334
  type: "string",
60334
60335
  default: null
60335
60336
  });
@@ -60375,11 +60376,11 @@ const runCommand = {
60375
60376
  graphFileOption,
60376
60377
  includeDepsOption,
60377
60378
  includeDependentsOption,
60378
- credentialsOption,
60379
60379
  jsonOutputOption,
60380
60380
  timeoutOption,
60381
60381
  executionTimeoutOption,
60382
60382
  tagsOption,
60383
+ jobPrefixOption,
60383
60384
  bigqueryJobLabelsOption,
60384
60385
  artifactsOption,
60385
60386
  ...ProjectConfigOptions.allYargsOptions
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "glob": "13.0.6",
9
9
  "google-auth-library": "^9.15.1",
10
10
  "google-sql-syntax-ts": "^1.0.3",
11
- "js-beautify": "^1.10.2",
11
+ "js-beautify": "1.15.4",
12
12
  "js-yaml": "^4.3.2",
13
13
  "moo": "^0.5.0",
14
14
  "mysql2": "^3.11.0",
15
15
  "object-sizeof": "^1.6.1",
16
- "parse-duration": "^1.0.0",
16
+ "parse-duration": "2.1.6",
17
17
  "pg": "^8.11.3",
18
18
  "pg-query-stream": "^4.5.3",
19
19
  "promise-pool-executor": "^1.1.1",
@@ -30,7 +30,7 @@
30
30
  "resolutions": {
31
31
  "**/object-path": "^0.11.5",
32
32
  "**/http-proxy": "^1.18.1",
33
- "**/serialize-javascript": "^3.1.0",
33
+ "**/serialize-javascript": "^7.1.1",
34
34
  "**/ssri": "^7.1.1",
35
35
  "**/glob-parent": "^5.1.2",
36
36
  "**/node-forge": "^1.0.0",
@@ -42,14 +42,17 @@
42
42
  "**/json-schema": "^0.4.0",
43
43
  "**/nth-check": "^2.0.1",
44
44
  "**/node-fetch": "^2.6.7",
45
- "**/markdown-it": "^12.3.2",
45
+ "**/markdown-it": "14.3.1",
46
+ "**/mdurl": "2.0.0",
46
47
  "**/wrap-ansi": "7.0.0",
47
48
  "**/string-width": "4.1.0",
48
49
  "**/@eslint-community/eslint-utils": "4.9.1",
49
50
  "**/@ungap/structured-clone": "1.3.1",
50
51
  "**/brace-expansion": "5.0.9",
51
52
  "**/linkify-it": "^5.0.2",
52
- "**/braces": "^3.0.3"
53
+ "**/braces": "^3.0.3",
54
+ "**/@eslint/plugin-kit": "0.7.2",
55
+ "@google-cloud/storage/**/uuid": "14.0.2"
53
56
  },
54
57
  "homepage": "https://sqlanvil.com",
55
58
  "repository": {
@@ -76,7 +79,10 @@
76
79
  "bin": {
77
80
  "sqlanvil": "bundle.js"
78
81
  },
79
- "version": "1.32.8",
82
+ "engines": {
83
+ "node": "^20.19.0 || >=22.12.0"
84
+ },
85
+ "version": "1.32.10",
80
86
  "name": "@sqlanvil/cli",
81
87
  "description": "sqlanvil command line interface.",
82
88
  "main": "bundle.js"
package/._LICENSE DELETED
Binary file
package/._NOTICE DELETED
Binary file
package/._README.md DELETED
Binary file
package/._bundle.js DELETED
Binary file
package/._package.json DELETED
Binary file
Binary file