Skip to content

Commit 45e539a

Browse files
committed
run on production schedule
1 parent efd85b5 commit 45e539a

1 file changed

Lines changed: 66 additions & 42 deletions

File tree

docs/examples/sqlmesh_cli_crash_course.md

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You’ll use these commands 80% of the time because this is how you apply code c
1717
5. Run data diff against prod
1818
6. Apply the changes to prod
1919

20-
### Preview, Apply, and Audit Changes in dev
20+
### Preview, Apply, and Audit Changes in `dev`
2121

2222
All these steps are bundled into a single command below:
2323

@@ -601,8 +601,8 @@ Pro tip: run this after running `sqlmesh table_diff` to get a full picture of th
601601
```
602602

603603
```bash
604-
-- construct arbitrary query
605-
tcloud sqlmesh fetchdf "select * from <schema__environment>.<model_name> limit 5" -- double underscore is important. Not needed for prod.
604+
# construct arbitrary query
605+
tcloud sqlmesh fetchdf "select * from <schema__environment>.<model_name> limit 5" # double underscore is important. Not needed for prod.
606606
```
607607

608608
??? "Example Output"
@@ -714,7 +714,6 @@ This is great to verify the SQL is looking as expected before applying the chang
714714
tcloud sqlmesh render <model_name> --dialect <dialect>
715715
```
716716

717-
```bash
718717
??? "Example Output"
719718

720719
It outputs the full SQL code in the default or target dialect.
@@ -857,14 +856,15 @@ Each time you perform a SQLMesh command, it creates a log file in the `logs` dir
857856

858857
```bash
859858
# install this open source tool that enhances the default `cat` command
859+
# https://github.com/sharkdp/bat
860860
brew install bat
861861
```
862862

863863
```bash
864864
bat --theme='ansi' $(ls -t logs/ | head -n 1 | sed 's/^/logs\//')
865865
```
866866

867-
- In simple terms this command works like this: "Show me the contents of the newest log file in the logs directory, with nice formatting and syntax highlighting.”
867+
- In simple terms this command works like this: "Show me the contents of the newest log file in the `logs/` directory, with nice formatting and syntax highlighting.”
868868
- press `q` to quit out of big files in the terminal
869869

870870
??? "Example Output"
@@ -899,7 +899,15 @@ bat --theme='ansi' $(ls -t logs/ | head -n 1 | sed 's/^/logs\//')
899899
│ L: SELECT CURRENT_CATALOG() (base.py:2128)
900900
```
901901

902-
## **Run Commands**
902+
## **Run on Production Schedule**
903+
904+
If you're using open source SQLMesh, you can run this in your orchestrator (ex: Dagster, GitHub Actions, etc.) every 5 minutes or at your lowest model cron schedule (ex: every 1 hour). Don't worry! It will only run executions that need to be run.
905+
906+
If you're using Tobiko Cloud, this configures automatically without additional configuration.
907+
908+
### Run Models
909+
910+
This command is intended be run on a schedule. It will skip the physical and virtual layer updates and simply execute the model batches.
903911

904912
=== "SQLMesh"
905913

@@ -913,21 +921,49 @@ bat --theme='ansi' $(ls -t logs/ | head -n 1 | sed 's/^/logs\//')
913921
tcloud sqlmesh run
914922
```
915923

916-
asdf
924+
??? "Example Output"
917925

918-
=== "SQLMesh"
926+
This is what it looks like if models are ready to run.
927+
928+
```bash
929+
[1/1] sqlmesh_example.incremental_model [insert 2025-04-17 - 2025-04-17]
930+
0.01s
931+
[1/1] sqlmesh_example.incremental_unique_model [insert/update rows]
932+
0.01s
933+
[1/1] sqlmesh_example_v3.incremental_partition_model [insert partitions]
934+
0.01s
935+
Executing model batches ━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━ 40.0% • 2/5 • 0:00:00
936+
sqlmesh_example_v3.incremental_partition_model .
937+
[WARNING] sqlmesh_example.full_model: 'assert_positive_order_ids' audit error: 2 rows failed. Learn
938+
more in logs: /Users/sung/Desktop/git_repos/sqlmesh-cli-revamp/logs/sqlmesh_2025_04_18_12_48_35.log
939+
[1/1] sqlmesh_example.full_model [full refresh, audits ❌1]
940+
0.01s
941+
Executing model batches ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━ 80.0% • 4/5 • 0:00:00
942+
sqlmesh_example.view_model .
943+
[WARNING] sqlmesh_example.view_model: 'assert_positive_order_ids' audit error: 2 rows failed. Learn
944+
more in logs: /Users/sung/Desktop/git_repos/sqlmesh-cli-revamp/logs/sqlmesh_2025_04_18_12_48_35.log
945+
[1/1] sqlmesh_example.view_model [recreate view, audits ✔2 ❌1]
946+
0.01s
947+
Executing model batches ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 5/5 • 0:00:00
948+
949+
✔ Model batches executed
919950

920-
```bash
921-
sqlmesh run dev
951+
Run finished for environment 'prod'
922952
```
923953

924-
=== "Tobiko Cloud"
954+
This is what it looks like if no models are ready to run.
925955

926956
```bash
927-
tcloud sqlmesh run dev
957+
No models are ready to run. Please wait until a model `cron` interval has elapsed.
958+
959+
Next run will be ready at 2025-04-18 05:00PM PDT (2025-04-19 12:00AM UTC).
928960
```
929961

930-
asdf
962+
### Run Models with Incomplete Intervals (Warning)
963+
964+
!!! warning "Run Models with Incomplete Intervals"
965+
This only applies to incremental models that have `allow_partials` set to `true`.
966+
This is generally not recommended for production environments as you risk shipping incomplete data which will be perceived as broken data.
931967

932968
=== "SQLMesh"
933969

@@ -941,25 +977,31 @@ asdf
941977
tcloud sqlmesh run --ignore-cron
942978
```
943979

944-
asdf
980+
??? "Example Model Config"
945981

946-
- allow_partials
982+
```sql
983+
MODEL (
984+
name sqlmesh_example.incremental_model,
985+
kind INCREMENTAL_BY_TIME_RANGE (
986+
time_column event_date
987+
),
988+
start '2020-01-01',
989+
cron '@daily', -- daily at midnight UTC
990+
grain (id, event_date),
991+
allow_partials true
992+
);
993+
```
947994

948-
## **Working with Incremental Forward-Only Models**
995+
### **Forward-Only Development Workflow**
949996

950997
https://www.loom.com/share/209181d9532d44969313ac0ac23f501f
951998

952999
- codify this especially the commented out steps
9531000

9541001

955-
## **Validating Changes**
956-
957-
You'll these commands ad hoc to verify your changes are behaving as expected.
958-
1002+
### **Miscellaneous**
9591003

960-
961-
962-
## **Miscellaneous**
1004+
If you notice you have a lot of old development schemas/data, you can clean them up with the following command. This process runs automatically during the `sqlmesh run` command. This defaults to deleting old data past 7 days.
9631005

9641006
=== "SQLMesh"
9651007

@@ -971,22 +1013,4 @@ You'll these commands ad hoc to verify your changes are behaving as expected.
9711013

9721014
```bash
9731015
tcloud sqlmesh janitor
974-
```
975-
976-
Fun for the whole family:
977-
978-
```bash
979-
brew install bat
980-
```
981-
982-
```bash
983-
bat --theme='ansi' $(ls -t logs/ | head -n 1 | sed 's/^/logs\//')
984-
```
985-
986-
- view logs
987-
- a special treat for you ;)
988-
- https://github.com/sharkdp/bat
989-
- In simple terms: "Show me the contents of the newest log file in the logs directory, with nice formatting and syntax highlighting.”
990-
- `q` to quit out of big files in the terminal
991-
992-
- Manually clean up old development schemas outside the automated schedule
1016+
```

0 commit comments

Comments
 (0)