You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"When targeting the production environment either the backfill should not be skipped or the lack of data gaps should be enforced (--no-gaps flag)."
1521
+
# note: we deliberately don't mention the --no-gaps flag in case the plan came from the sqlmesh_dbt command
1522
+
# todo: perhaps we could have better error messages if we check sys.argv[0] for which cli is running?
1523
+
self.console.log_warning(
1524
+
"Skipping the backfill stage for production can lead to unexpected results, such as tables being empty or incremental data with non-contiguous time ranges being made available.\n"
1525
+
"If you are doing this deliberately to create an empty version of a table to test a change, please consider using Virtual Data Environments instead."
# prod plans should "catch up" before applying the changes so that after the command finishes prod is the latest it can be
96
+
# dev plans *with* selectors should do the same as the user is saying "specifically update these models to the latest"
97
+
# dev plans *without* selectors should just have the defaults of never exceeding prod as the user is saying "just create this env" without focusing on any specific models
98
+
options.update(
99
+
dict(
100
+
# always catch the data up to latest rather than only operating on what has been loaded before
101
+
run=True,
102
+
# don't taking cron schedules into account when deciding what models to run, do everything even if it just ran
103
+
ignore_cron=True,
104
+
)
105
+
)
106
+
107
+
ifis_dev:
108
+
options.update(
109
+
dict(
110
+
# don't create views for all of prod in the dev environment
111
+
include_unmodified=False,
112
+
# always plan from scratch against prod. note that this is coupled with the `always_recreate_environment=True` setting in the default config file.
113
+
# the result is that rather than planning against the previous state of an existing dev environment, the full scope of changes vs prod are always shown
114
+
create_from=c.PROD,
115
+
# Always enable dev previews for incremental / forward-only models.
116
+
# Due to how DBT does incrementals (INCREMENTAL_UNMANAGED on the SQLMesh engine), this will result in the full model being refreshed
117
+
# with the entire dataset, which can potentially be very large. If this is undesirable, users have two options:
118
+
# - work around this using jinja to conditionally add extra filters to the WHERE clause or a LIMIT to the model query
119
+
# - upgrade to SQLMesh's incremental models, where we have variables for the start/end date and inject leak guards to
120
+
# limit the amount of data backfilled
121
+
#
122
+
# Note: enable_preview=True is *different* behaviour to the `sqlmesh` CLI, which uses enable_preview=None.
123
+
# This means the `sqlmesh` CLI will only enable dev previews for dbt projects if the target adapter supports cloning,
124
+
# whereas we enable it unconditionally here
125
+
enable_preview=True,
126
+
)
127
+
)
128
+
129
+
ifempty:
130
+
# `dbt --empty` adds LIMIT 0 to the queries, resulting in empty tables. In addition, it happily clobbers existing tables regardless of if they are populated.
131
+
# This *partially* lines up with --skip-backfill in SQLMesh, which indicates to not populate tables if they happened to be created/updated as part of this plan.
132
+
# However, if a table already exists and has data in it, there is no change so SQLMesh will not recreate the table and thus it will not be cleared.
133
+
# So in order to fully replicate dbt's --empty, we also need --full-refresh semantics in order to replace existing tables
134
+
options["skip_backfill"] =True
135
+
full_refresh=True
136
+
137
+
iffull_refresh:
138
+
# TODO: handling this requires some updates in the engine to enable restatements+changes in the same plan without affecting prod
139
+
# if the plan targets dev
140
+
pass
141
+
142
+
returndict(
143
+
environment=environment,
144
+
select_models=select_models,
145
+
# dont output a diff of model changes
146
+
no_diff=True,
147
+
# don't throw up any prompts like "set the effective date" - use defaults
148
+
no_prompts=True,
149
+
# start doing work immediately (since no_diff is set, there isnt really anything for the user to say yes/no to)
150
+
auto_apply=True,
151
+
**options,
152
+
)
153
+
74
154
@property
75
155
defconsole(self) ->DbtCliConsole:
76
156
console=self.context.console
@@ -103,6 +183,12 @@ def create(
103
183
fromsqlmesh_dbt.consoleimportDbtCliConsole
104
184
fromsqlmesh.utils.errorsimportSQLMeshError
105
185
186
+
# clear any existing handlers set up by click/rich as defaults so that once SQLMesh logging config is applied,
187
+
# we dont get duplicate messages logged from things like console.log_warning()
"Error: When targeting the production environment either the backfill should not be skipped or the lack of data gaps should be enforced (--no-gaps flag)."
265
-
inresult.output
266
-
)
263
+
assert"Skipping the backfill stage for production can lead to unexpected"inresult.output
267
264
268
265
# plan executes virtual update without executing model batches
0 commit comments