Skip to content

Commit 657cf0d

Browse files
authored
Chore: Run audits for metadata snaphots after creating snapshots and their tables (#4517)
1 parent 73e2ef4 commit 657cf0d

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

sqlmesh/core/plan/evaluator.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def evaluate(
116116
after_promote_snapshots = all_names - before_promote_snapshots
117117
deployability_index_for_evaluation = DeployabilityIndex.all_deployable()
118118

119+
# Step 1: Run before_all environment statements before doing anything else
119120
execute_environment_statements(
120121
adapter=self.snapshot_evaluator.adapter,
121122
environment_statements=plan.environment_statements or [],
@@ -128,41 +129,61 @@ def evaluate(
128129
execution_time=plan.execution_time,
129130
)
130131

131-
self._run_audits_for_metadata_snapshots(plan, new_snapshots)
132-
132+
# Step 2:Store new snapshot records in the state and create physical tables for them
133133
push_completion_status = self._push(plan, snapshots, deployability_index_for_creation)
134134
if push_completion_status.is_nothing_to_do:
135135
self.console.log_success(
136136
"" if plan.restatements else "\nSKIP: No physical layer updates to perform"
137137
)
138+
139+
# Step 3: Update the intervals for the new forward-only snapshots
138140
update_intervals_for_new_snapshots(plan.new_snapshots, self.state_sync)
141+
142+
# Step 4: Run audits without evaluations for snapshots that capture audit metadata changes
143+
self._run_audits_for_metadata_snapshots(plan, new_snapshots)
144+
145+
# Step 5: Remove intervals for snapshots that need to be restated
139146
self._restate(plan, snapshots_by_name)
147+
148+
# Step 6: Backfill missing intervals for snapshots that can be backfilled before updating
149+
# the schema of production tables
140150
first_bf_completion_status = self._backfill(
141151
plan,
142152
snapshots_by_name,
143153
before_promote_snapshots,
144154
deployability_index_for_evaluation,
145155
circuit_breaker=circuit_breaker,
146156
)
157+
158+
# Step 7: Update the target environment record in the state and migrate table schemas for forward-only
159+
# snapshots if deploying to production
147160
promotion_result = self._promote(
148161
plan, snapshots, before_promote_snapshots, deployability_index_for_creation
149162
)
163+
164+
# Step 8: Backfill missing intervals for snapshots that can be backfilled only after updating
165+
# the schema of production tables
150166
second_bf_completion_status = self._backfill(
151167
plan,
152168
snapshots_by_name,
153169
after_promote_snapshots,
154170
deployability_index_for_evaluation,
155171
circuit_breaker=circuit_breaker,
156172
)
173+
157174
if (
158175
first_bf_completion_status.is_nothing_to_do
159176
and second_bf_completion_status.is_nothing_to_do
160177
):
161178
self.console.log_success("SKIP: No model batches to execute")
179+
180+
# Step 9: Update environment views to point at new physical tables and finalize the environment
181+
# record in the state
162182
self._update_views(
163183
plan, snapshots, promotion_result, deployability_index_for_evaluation
164184
)
165185

186+
# Step 10: Run after_all environment statements
166187
execute_environment_statements(
167188
adapter=self.snapshot_evaluator.adapter,
168189
environment_statements=plan.environment_statements or [],

0 commit comments

Comments
 (0)