Skip to content

Commit ff56fe5

Browse files
authored
Docs: reorder notebook quickstart (#1170)
* Reorder notebook quickstart
1 parent f8d5041 commit ff56fe5

8 files changed

Lines changed: 31 additions & 40 deletions

docs/quickstart/notebook.md

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Inform SQLMesh of the project location by setting a context with the `%context`
2727

2828
You can specify multiple directories in one call to `%context` if your SQLMesh project has [multiple repositories](../guides/multi_repo.md).
2929

30-
## 2. Plan and apply environments
31-
### 2.1 Create a prod environment
30+
## 2. Create a prod environment
3231

3332
SQLMesh's key actions are creating and applying *plans* to *environments*. At this point, the only environment is the empty `prod` environment.
3433

@@ -57,28 +56,10 @@ The first output block shows the completion percentage and run time for each mod
5756

5857
You've now created a new production environment with all of history backfilled.
5958

60-
### 2.2 Create a dev environment
61-
Now that you've created a production environment, it's time to create a development environment so that you can modify models without affecting production.
59+
## 3. Update a model
6260

63-
Run `%plan dev` to create a development environment called `dev`. The following output will be displayed:
64-
65-
![Notebook output after dev plan creation](./notebook/nb-quickstart_plan-dev.png)
66-
67-
The output does not list any added or modified models because `dev` is being created from the existing `prod` environment without modification.
68-
69-
The `New environment` line shows that when you apply the plan creating the `dev` environment, it will only involve a Virtual Update. This is because SQLMesh is able to safely reuse the tables you've already backfilled in the `prod` environment.
70-
71-
Click the green button to perform the Virtual Update:
72-
73-
![Notebook output after dev plan application](./notebook/nb-quickstart_apply-plan-dev.png)
74-
75-
The output confirms that the `dev` environment has been updated successfully.
76-
77-
## 3. Make your first update
61+
Now that we have have populated the `prod` environment, let's modify one of the SQL models.
7862

79-
Now that we have have populated both `prod` and `dev` environments, let's modify one of the SQL models, validate it in `dev`, and push it to `prod`.
80-
81-
### 3.1 Edit the configuration
8263
We can modify the incremental SQL model using the `%model` *line* notebook magic (note the single `%`) and the model name:
8364

8465
![%model line magic for sqlmesh_example.incremental_model](./notebook/nb-quickstart_model-line.png)
@@ -91,59 +72,69 @@ We modify the incremental SQL model by adding a new column to the query. When we
9172

9273
![%%model cell magic for updated sqlmesh_example.incremental_model](./notebook/nb-quickstart_model-cell-updated.png)
9374

94-
## 4. Plan and apply updates
95-
We can preview the impact of the change using the `%plan dev` command:
75+
## 4. Work with a development environment
76+
77+
### 4.1 Create a dev environment
78+
Now that you've modified a model, it's time to create a development environment so that you can validate the model change without affecting production.
9679

97-
![Notebook output after model modification and %plan dev](./notebook/nb-quickstart_plan-dev-modified.png)
80+
Run `%plan dev` to create a development environment called `dev`. The following output will be displayed:
81+
82+
![Notebook output after dev plan creation](./notebook/nb-quickstart_plan-dev.png)
9883

9984
The first block of output notes that `%plan` successfully executed the project's test `tests/test_full_model.yaml` with duckdb.
10085

101-
The second block "Summary of differences against `dev`" summarizes the differences between the modified project components and the existing `dev` environment, detecting that we directly modified `incremental_model` and that `full_model` was indirectly modified because it selects from the incremental model.
86+
The `New environment` line describes what environments the plan will affect when applied - a new `dev` environment will be created from the existing `prod` environment.
10287

103-
The third block shows the modifications we made to the rendered query.
88+
The `Summary of differences` section summarizes the differences between the modified model and the new `dev` environment (right now just a copy of `prod`), detecting that we directly modified `incremental_model` and that `full_model` was indirectly modified because it selects from the incremental model. It shows a diff between the existing and updated model.
10489

105-
The next block shows that we directly modified the incremental model. SQLMesh understood that the change was additive (added a column not used by `full_model`) and automatically classified it as a non-breaking change.
90+
SQLMesh automatically classified the change as `Non-breaking` because understood that the change was additive (added a column not used by `full_model`) and did not invalidate any data already in `prod`.
10691

107-
The final block describes the models requiring backfill, including the incremental model from our start date `2020-01-01`. We can modify the backfill start and end dates for the incremental model with the date picker widget, if desired.
92+
The `Models needing backfill` section shows that only the directly modified `incremental_model` needs backfill and provides a date picker to specify the start and end dates for the backfill.
10893

109-
Click the green `Apply - Backfill Tables` button to apply the plan and execute the backfill:
94+
Click the green button to perform the backfill:
11095

111-
![Notebook output after model modification and applying the updated plan](./notebook/nb-quickstart_apply-plan-dev-modified.png)
96+
![Notebook output after dev plan application](./notebook/nb-quickstart_apply-plan-dev.png)
97+
98+
The output shows that SQLMesh created a new model version in `dev`. The last line of the output shows that SQLMesh applied the change to `sqlmesh_example__dev.incremental_model`. In the model schema, the suffix "`__dev`" indicates that it is in the `dev` environment.
11299

113-
SQLMesh applies the change to `sqlmesh_example.incremental_model` and backfills the model. SQLMesh did not need to backfill `sqlmesh_example.full_model` since the change was `non-breaking`.
100+
SQLMesh did not need to backfill anything for the `full_model` since the change was `Non-breaking`.
114101

115-
### 4.1 Validate updates in dev
102+
### 4.2 Validate updates in dev
116103
You can now view this change by querying data from `incremental_model` with the `%%fetchdf` *cell* magic (note the two `%` symbols) and the SQL query `select * from sqlmesh_example__dev.incremental_model`.
117104

118-
Note that the environment name `__dev` is appended to the schema namespace `sqlmesh_example` in the query: `select * from sqlmesh_example__dev.incremental_model`.
105+
Note that the environment name `__dev` is appended to the schema namespace `sqlmesh_example` in the query:
119106

120107
![Notebook output after executing %%fetchdf on `dev` incremental_model](./notebook/nb-quickstart_fetchdf-dev.png)
121108

122109
You can see that `new_column` was added to the dataset.
123110

124-
The production table was not modified; you can validate this by querying the production table using `%%fetchdf` and the query `select * from sqlmesh_example.incremental_model`. Note that nothing has been appended to the schema namespace `sqlmesh_example` because `prod` is the default environment.
111+
The production table was not modified; you can validate this by querying the production table using `%%fetchdf` and the query `select * from sqlmesh_example.incremental_model`.
112+
113+
Note that nothing has been appended to the schema namespace `sqlmesh_example` because `prod` is the default environment:
125114

126115
![Notebook output after executing %%fetchdf on prod incremental_model before model update applied](./notebook/nb-quickstart_fetchdf-prod.png)
127116

128117
The production table does not have `new_column` because the changes to `dev` have not yet been applied to `prod`.
129118

130-
### 4.2 Apply updates to prod
131-
Now that we've tested the changes in dev, it's time to move them to prod. Run `%plan` to plan and apply your changes to the prod environment.
119+
## 5. Update the prod environment
120+
Now that we've tested the changes in dev, it's time to move them to production. Run `%plan` to plan and apply your changes to the `prod` environment:
121+
122+
![Notebook output after executing %plan on prod](./notebook/nb-quickstart_apply-plan-prod-modified.png)
132123

133124
Click the green `Apply - Virtual Update` button to apply the plan and execute the backfill:
134125

135-
![Notebook output after executing %plan on prod and applying changes](./notebook/nb-quickstart_apply-plan-prod-modified.png)
126+
![Notebook output after executing applying virtual update on prod](./notebook/nb-quickstart_apply-plan-prod-modified-update.png)
136127

137128
Note that a backfill was not necessary and only a Virtual Update occurred.
138129

139-
### 4.3. Validate updates in prod
130+
### 5.2 Validate updates in prod
140131
Double-check that the data updated in `prod` by running `%%fetchdf` with the SQL query `select * from sqlmesh_example.incremental_model`:
141132

142133
![Notebook output after executing %%fetchdf on prod incremental_model after model update applied](./notebook/nb-quickstart_fetchdf-prod-modified.png)
143134

144135
`new_column` is now present in the `prod` incremental model.
145136

146-
## 5. Next steps
137+
## 6. Next steps
147138

148139
Congratulations, you've now conquered the basics of using SQLMesh!
149140

-9.13 KB
Binary file not shown.
17.3 KB
Loading
9.85 KB
Loading
30.3 KB
Loading
10.2 KB
Loading
-39.9 KB
Binary file not shown.
78.7 KB
Loading

0 commit comments

Comments
 (0)