Skip to content

Commit 79adfb7

Browse files
committed
Add interactive init to quickstart docs
1 parent 6e90e3e commit 79adfb7

File tree

3 files changed

+209
-66
lines changed

3 files changed

+209
-66
lines changed

docs/integrations/overview.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ SQLMesh supports integrations with the following tools:
99
* [Kestra](https://kestra.io/plugins/plugin-sqlmesh/tasks/cli/io.kestra.plugin.sqlmesh.cli.sqlmeshcli)
1010

1111
## Execution engines
12-
SQLMesh supports the following execution engines for running SQLMesh projects:
12+
SQLMesh supports the following execution engines for running SQLMesh projects (engine `type` in parentheses):
1313

14-
* [Athena](./engines/athena.md)
15-
* [Azure SQL](./engines/azuresql.md)
16-
* [BigQuery](./engines/bigquery.md)
17-
* [ClickHouse](./engines/clickhouse.md)
18-
* [Databricks](./engines/databricks.md)
19-
* [DuckDB](./engines/duckdb.md)
20-
* [MotherDuck](./engines/motherduck.md)
21-
* [MSSQL](./engines/mssql.md)
22-
* [MySQL](./engines/mysql.md)
23-
* [Postgres](./engines/postgres.md)
24-
* [GCP Postgres](./engines/gcp-postgres.md)
25-
* [Redshift](./engines/redshift.md)
26-
* [Snowflake](./engines/snowflake.md)
27-
* [Spark](./engines/spark.md)
28-
* [Trino](./engines/trino.md)
14+
* [Athena](./engines/athena.md) (athena)
15+
* [Azure SQL](./engines/azuresql.md) (azuresql)
16+
* [BigQuery](./engines/bigquery.md) (bigquery)
17+
* [ClickHouse](./engines/clickhouse.md) (clickhouse)
18+
* [Databricks](./engines/databricks.md) (databricks)
19+
* [DuckDB](./engines/duckdb.md) (duckdb)
20+
* [MotherDuck](./engines/motherduck.md) (motherduck)
21+
* [MSSQL](./engines/mssql.md) (mssql)
22+
* [MySQL](./engines/mysql.md) (mysql)
23+
* [Postgres](./engines/postgres.md) (postgres)
24+
* [GCP Postgres](./engines/gcp-postgres.md) (gcppostgres)
25+
* [Redshift](./engines/redshift.md) (redshift)
26+
* [Snowflake](./engines/snowflake.md) (snowflake)
27+
* [Spark](./engines/spark.md) (spark)
28+
* [Trino](./engines/trino.md) (trino)

docs/quickstart/cli.md

Lines changed: 187 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# CLI
22

3-
In this quickstart, you'll use the SQLMesh command line interface (CLI) to get up and running with SQLMesh's scaffold generator. This example project will run locally on your computer using [DuckDB](https://duckdb.org/) as an embedded SQL engine.
3+
In this quickstart, you'll use the SQLMesh command line interface (CLI) to get up and running with SQLMesh's scaffold generator.
4+
5+
It will create an example project that runs locally on your computer using [DuckDB](https://duckdb.org/) as an embedded SQL engine.
46

57
Before beginning, ensure that you meet all the [prerequisites](../prerequisites.md) for using SQLMesh.
68

@@ -39,36 +41,173 @@ mkdir sqlmesh-example
3941
cd sqlmesh-example
4042
```
4143

42-
If using a python virtual environment, ensure it's activated first by running the `source .env/bin/activate` command from the folder used during [installation](../installation.md).
44+
If using a Python virtual environment, ensure it's activated first by running the `source .env/bin/activate` command from the folder used during [installation](../installation.md).
45+
46+
### 1.1 Initialize the project
47+
48+
SQLMesh includes a scaffold generator to initialize a new SQLMesh project.
49+
50+
The scaffold generator will ask you some questions and create a SQLMesh configuration file based on your responses.
4351

44-
Create a SQLMesh scaffold with the following command, specifying a default SQL dialect for your models. The dialect should correspond to the dialect most of your models are written in; it can be overridden for specific models in the model's `MODEL` specification. All SQL dialects [supported by the SQLGlot library](https://github.com/tobymao/sqlglot/blob/main/sqlglot/dialects/dialect.py) are allowed.
52+
Depending on your answers, it will also create multiple files for the SQLmesh example project used in this quickstart.
4553

46-
In this example, we specify the `duckdb` dialect:
54+
Start the scaffold generator by executing the `sqlmesh init` command:
4755

4856
```bash
49-
sqlmesh init duckdb
57+
sqlmesh init
5058
```
5159

52-
The scaffold will include a SQLMesh configuration file for the example project.
60+
??? info "Skip the questions"
61+
62+
If you don't want to use the interactive scaffold generator, you can initialize your project with arguments to the [`sqlmesh init` command](../reference/cli.md#init).
63+
64+
The only required argument is `engine`, which specifies the SQL engine your project will use. Specify one of the engine `type`s in the [list of supported engines](../integrations/overview.md#execution-engines).
65+
66+
In this example, we specify the `duckdb` engine:
67+
68+
```bash
69+
sqlmesh init duckdb
70+
```
71+
72+
The scaffold will include a SQLMesh configuration file and example project directories and files. You're now ready to continue the quickstart [below](#2-create-a-prod-environment).
73+
74+
#### Project type
75+
76+
The first question asks about the type of project you want to create. Enter the number corresponding to the type of project you want to create and press `Enter`.
77+
78+
``` bash
79+
──────────────────────────────
80+
Welcome to SQLMesh!
81+
──────────────────────────────
82+
83+
What type of project do you want to set up?
84+
85+
[1] DEFAULT - Create SQLMesh example project models and files
86+
[2] dbt - You have an existing dbt project and want to run it with SQLMesh
87+
[3] EMPTY - Create a SQLMesh configuration file and project directories only
88+
89+
Enter a number: 1
90+
```
91+
92+
For this quickstart, choose the `DEFAULT` option `1` so the example project files are included in the project directories.
93+
94+
#### SQL engine
95+
96+
The second question asks which SQL engine your project will use. SQLMesh will include that engine's connection settings in the configuration file, which you will fill in later to connect your project to the engine.
97+
98+
For this quickstart, choose the `DuckDB` option `1` so we can run the example project with the built-in DuckDB engine that doesn't need additional configuration.
99+
100+
``` bash
101+
Choose your SQL engine:
102+
103+
[1] DuckDB
104+
[2] Snowflake
105+
[3] Databricks
106+
[4] BigQuery
107+
[5] MotherDuck
108+
[6] ClickHouse
109+
[7] Redshift
110+
[8] Spark
111+
[9] Trino
112+
[10] Azure SQL
113+
[11] MSSQL
114+
[12] Postgres
115+
[13] GCP Postgres
116+
[14] MySQL
117+
[15] Athena
118+
[16] RisingWave
119+
120+
Enter a number: 1
121+
```
122+
123+
#### CLI mode
124+
125+
SQLMesh's core commands have multiple options that alter their behavior. Some of those options streamline the SQLMesh `plan` workflow and CLI output.
126+
127+
If you prefer a streamlined workflow, choose the `FLOW` CLI mode to automatically include those options in your project configuration file. If you prefer to see all the output SQLMesh provides, choose `DEFAULT` mode.
128+
129+
``` bash
130+
Choose your SQLMesh CLI experience:
131+
132+
[1] DEFAULT - See and control every detail
133+
[2] FLOW - Automatically run changes and show summary output
134+
135+
Enter a number: 1
136+
```
137+
138+
#### Ready to go
139+
140+
Your project is now ready to go, and SQLMesh displays a message with some good next steps.
141+
142+
If you chose the DuckDB engine, you're ready to move forward and run the example project with DuckDB.
143+
144+
If you chose a different engine, add your engine's connection information to the `config.yaml` file before you run any additional SQLMesh commands.
145+
146+
``` bash
147+
Your SQLMesh project is ready!
148+
149+
Next steps:
150+
• Update your gateway connection settings (e.g., username/password) in the project configuration file:
151+
/Users/trey/tobiko/sqlmesh/sqlmesh-example-fresh/test/config.yaml
152+
• Run command in CLI: sqlmesh plan
153+
• (Optional) Explain a plan: sqlmesh plan --explain
154+
155+
Quickstart guide:
156+
https://sqlmesh.readthedocs.io/en/stable/quickstart/cli/
157+
158+
Need help?
159+
• Docs: https://sqlmesh.readthedocs.io
160+
• Slack: https://www.tobikodata.com/slack
161+
• GitHub: https://github.com/TobikoData/sqlmesh/issues
162+
```
53163

54164
??? info "Learn more about the project's configuration"
55165
SQLMesh project-level configuration parameters are specified in the `config.yaml` file in the project directory.
56166

57-
This example project uses the embedded DuckDB SQL engine, so its configuration specifies `duckdb` as the local gateway's connection and the `local` gateway as the default.
167+
This example project uses the embedded DuckDB SQL engine, so its configuration specifies `duckdb` as the gateway's connection type. All available configuration settings are included in the file, with optional settings set to their default value and commented out.
58168

59-
The command to run the scaffold generator **requires** a default SQL dialect for your models, which it places in the config `model_defaults` `dialect` key. In this example, we specified the `duckdb` SQL dialect as the default:
169+
SQLMesh requires a default model SQL dialect. SQLMesh automatically specifies the SQL dialect for your project's SQL engine, which it places in the config `model_defaults` `dialect` key. In this example, we specified the DuckDB engine, so `duckdb` is the default SQL dialect:
60170

61171
```yaml linenums="1"
172+
# --- Gateway Connection ---
62173
gateways:
63-
local:
174+
duckdb:
64175
connection:
65-
type: duckdb
66-
database: ./db.db
67-
68-
default_gateway: local
176+
# For more information on configuring the connection to your execution engine, visit:
177+
# https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#connection
178+
# https://sqlmesh.readthedocs.io/en/stable/integrations/engines/duckdb/#connection-options
179+
#
180+
type: duckdb # <-- DuckDB engine
181+
database: db.db
182+
# concurrent_tasks: 1
183+
# register_comments: True # <-- Optional setting `register_comments` has a default value of True
184+
# pre_ping: False
185+
# pretty_sql: False
186+
# catalogs: # <-- Optional setting `catalogs` has no default value
187+
# extensions:
188+
# connector_config:
189+
# secrets:
190+
# token:
191+
192+
default_gateway: duckdb
193+
194+
# --- Model Defaults ---
195+
# https://sqlmesh.readthedocs.io/en/stable/reference/model_configuration/#model-defaults
69196

70197
model_defaults:
71-
dialect: duckdb
198+
dialect: duckdb # <-- Models written in DuckDB SQL dialect by default
199+
start: 2025-06-12 # Start date for backfill history
200+
cron: '@daily' # Run models daily at 12am UTC (can override per model)
201+
202+
# --- Linting Rules ---
203+
# Enforce standards for your team
204+
# https://sqlmesh.readthedocs.io/en/stable/guides/linter/
205+
206+
linter:
207+
enabled: true
208+
rules:
209+
- ambiguousorinvalidcolumn
210+
- invalidselectstarexpansion
72211
```
73212

74213
Learn more about SQLMesh project configuration [here](../reference/configuration.md).
@@ -133,13 +272,19 @@ SQLMesh's key actions are creating and applying *plans* to *environments*. At th
133272

134273
SQLMesh's key actions are creating and applying *plans* to *environments*.
135274

136-
A [SQLMesh environment](../concepts/environments.md) is an isolated namespace containing models and the data they generated. The most important environment is `prod` ("production"), which consists of the databases behind the applications your business uses to operate each day. Environments other than `prod` provide a place where you can test and preview changes to model code before they go live and affect business operations.
275+
A [SQLMesh environment](../concepts/environments.md) is an isolated namespace containing models and the data they generated.
276+
277+
The most important environment is `prod` ("production"), which consists of the databases behind the applications your business uses to operate each day. Environments other than `prod` provide a place where you can test and preview changes to model code before they go live and affect business operations.
278+
279+
A [SQLMesh plan](../concepts/plans.md) contains a comparison of one environment to another and the set of changes needed to bring them into alignment.
137280

138-
A [SQLMesh plan](../concepts/plans.md) contains a comparison of one environment to another and the set of changes needed to bring them into alignment. For example, if a new SQL model was added, tested, and run in the `dev` environment, it would need to be added and run in the `prod` environment to bring them into alignment. SQLMesh identifies all such changes and classifies them as either breaking or non-breaking.
281+
For example, if a new SQL model was added, tested, and run in the `dev` environment, it would need to be added and run in the `prod` environment to bring them into alignment. SQLMesh identifies all such changes and classifies them as either breaking or non-breaking.
139282

140-
Breaking changes are those that invalidate data already existing in an environment. For example, if a `WHERE` clause was added to a model in the `dev` environment, existing data created by that model in the `prod` environment are now invalid because they may contain rows that would be filtered out by the new `WHERE` clause. Other changes, like adding a new column to a model in `dev`, are non-breaking because all the existing data in `prod` are still valid to use - only new data must be added to align the environments.
283+
Breaking changes are those that invalidate data already existing in an environment. For example, if a `WHERE` clause was added to a model in the `dev` environment, existing data created by that model in the `prod` environment are now invalid because they may contain rows that would be filtered out by the new `WHERE` clause.
141284

142-
After SQLMesh creates a plan, it summarizes the breaking and non-breaking changes so you can understand what will happen if you apply the plan. It will prompt you to "backfill" data to apply the plan - in this context, backfill is a generic term for updating or adding to a table's data (including an initial load or full refresh).
285+
Other changes, like adding a new column to a model in `dev`, are non-breaking because all the existing data in `prod` are still valid to use - only new data must be added to align the environments.
286+
287+
After SQLMesh creates a plan, it summarizes the breaking and non-breaking changes so you can understand what will happen if you apply the plan. It will prompt you to "backfill" data to apply the plan. (In this context, backfill is a generic term for updating or adding to a table's data, including an initial load or full refresh.)
143288

144289
The first SQLMesh plan must execute every model to populate the production environment. Running `sqlmesh plan` will generate the plan and the following output:
145290

@@ -257,12 +402,9 @@ Updating physical layer ━━━━━━━━━━━━━━━━━━
257402

258403
✔ Physical layer updated
259404

260-
[1/1] sqlmesh_example.seed_model [insert seed file]
261-
0.02s
262-
[1/1] sqlmesh_example.incremental_model [insert 2020-01-01 -
263-
2025-04-17] 0.03s
264-
[1/1] sqlmesh_example.full_model [full refresh, audits ✔1]
265-
0.05s
405+
[1/1] sqlmesh_example.seed_model [insert seed file] 0.02s
406+
[1/1] sqlmesh_example.incremental_model [insert 2020-01-01 -2025-04-17] 0.03s
407+
[1/1] sqlmesh_example.full_model [full refresh, audits ✔1] 0.05s
266408
Executing model batches ━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 3/3 • 0:00:00
267409

268410
✔ Model batches executed
@@ -327,7 +469,7 @@ Run `sqlmesh plan dev` to create a development environment called `dev`:
327469
$ sqlmesh plan dev
328470
======================================================================
329471
Successfully Ran 1 tests against duckdb
330-
----------------------------------------------------------------------
472+
----------------------------------------------------------------------
331473

332474
New environment `dev` will be created from `prod`
333475

@@ -341,25 +483,25 @@ Models:
341483
└── sqlmesh_example__dev.full_model
342484

343485
---
344-
345-
+++
346-
486+
487+
+++
488+
347489
@@ -14,6 +14,7 @@
348-
490+
349491
SELECT
350-
id,
351-
item_id,
492+
id,
493+
item_id,
352494
+ 'z' AS new_column,
353-
event_date
495+
event_date
354496
FROM sqlmesh_example.seed_model
355497
WHERE
356498

357-
Directly Modified: sqlmesh_example__dev.incremental_model
499+
Directly Modified: sqlmesh_example__dev.incremental_model
358500
(Non-breaking)
359501
└── Indirectly Modified Children:
360-
└── sqlmesh_example__dev.full_model (Indirect Non-breaking)
502+
└── sqlmesh_example__dev.full_model (Indirect Non-breaking)
361503
Models needing backfill:
362-
└── sqlmesh_example__dev.incremental_model: [2020-01-01 - 2025-04-17]
504+
└── sqlmesh_example__dev.incremental_model: [2020-01-01 - 2025-04-17]
363505
Apply - Backfill Tables [y/n]:
364506
```
365507

@@ -378,8 +520,7 @@ Updating physical layer ━━━━━━━━━━━━━━━━━━
378520

379521
✔ Physical layer updated
380522

381-
[1/1] sqlmesh_example__dev.incremental_model [insert 2020-01-01 -
382-
2025-04-17] 0.03s
523+
[1/1] sqlmesh_example__dev.incremental_model [insert 2020-01-01 - 2025-04-17] 0.03s
383524
Executing model batches ━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 1/1 • 0:00:00
384525

385526
✔ Model batches executed
@@ -447,7 +588,7 @@ Enter `y` and press `Enter` at the `Apply - Virtual Update [y/n]:` prompt to app
447588
$ sqlmesh plan
448589
======================================================================
449590
Successfully Ran 1 tests against duckdb
450-
----------------------------------------------------------------------
591+
----------------------------------------------------------------------
451592

452593
Differences from the `prod` environment:
453594

@@ -458,20 +599,20 @@ Models:
458599
└── sqlmesh_example.full_model
459600

460601
---
461-
462-
+++
463-
602+
603+
+++
604+
464605
@@ -14,6 +14,7 @@
465-
606+
466607
SELECT
467-
id,
468-
item_id,
608+
id,
609+
item_id,
469610
+ 'z' AS new_column,
470-
event_date
611+
event_date
471612
FROM sqlmesh_example.seed_model
472613
WHERE
473614

474-
Directly Modified: sqlmesh_example.incremental_model (Non-breaking)
615+
Directly Modified: sqlmesh_example.incremental_model (Non-breaking)
475616
└── Indirectly Modified Children:
476617
└── sqlmesh_example.full_model (Indirect Non-breaking)
477618
Apply - Virtual Update [y/n]: y

docs/reference/cli.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,17 @@ Options:
267267
## init
268268

269269
```
270-
Usage: sqlmesh init [OPTIONS] [SQL_DIALECT]
270+
Usage: sqlmesh init [OPTIONS] [ENGINE]
271271
272272
Create a new SQLMesh repository.
273273
274274
Options:
275-
-t, --template TEXT Project template. Supported values: dbt,
276-
dlt, default, empty.
275+
-t, --template TEXT Project template. Supported values: dbt, dlt, default,
276+
empty.
277277
--dlt-pipeline TEXT DLT pipeline for which to generate a SQLMesh project.
278-
For use with dlt template.
278+
Use alongside template: dlt
279+
--dlt-path TEXT The directory where the DLT pipeline resides. Use
280+
alongside template: dlt
279281
--help Show this message and exit.
280282
```
281283

0 commit comments

Comments
 (0)