Skip to content

Commit 70f6c02

Browse files
committed
PR feedback
1 parent 82ead86 commit 70f6c02

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

sqlmesh/cli/project_init.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ def _gen_config(
121121
# https://sqlmesh.readthedocs.io/en/stable/guides/configuration/#virtual-data-environment-modes
122122
virtual_environment_mode: {VirtualEnvironmentMode.DEV_ONLY.lower()}
123123
124+
# --- Plan Defaults ---
125+
# https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#plan
126+
plan:
127+
# For Virtual Data Environments, this ensures that any changes are always considered against prod,
128+
# rather than the previous state of that environment
129+
always_recreate_environment: True
130+
124131
# --- Model Defaults ---
125132
# https://sqlmesh.readthedocs.io/en/stable/reference/model_configuration/#model-defaults
126133
model_defaults:

sqlmesh/core/context.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,6 @@ def plan(
12961296
explain: t.Optional[bool] = None,
12971297
ignore_cron: t.Optional[bool] = None,
12981298
min_intervals: t.Optional[int] = None,
1299-
always_recreate_environment: t.Optional[bool] = None,
13001299
) -> Plan:
13011300
"""Interactively creates a plan.
13021301
@@ -1346,7 +1345,6 @@ def plan(
13461345
explain: Whether to explain the plan instead of applying it.
13471346
min_intervals: Adjust the plan start date on a per-model basis in order to ensure at least this many intervals are covered
13481347
on every model when checking for missing intervals
1349-
always_recreate_environment: Whether to always recreate the target environment from the `create_from` environment.
13501348
13511349
Returns:
13521350
The populated Plan object.
@@ -1378,7 +1376,6 @@ def plan(
13781376
explain=explain,
13791377
ignore_cron=ignore_cron,
13801378
min_intervals=min_intervals,
1381-
always_recreate_environment=always_recreate_environment,
13821379
)
13831380

13841381
plan = plan_builder.build()
@@ -1431,7 +1428,6 @@ def plan_builder(
14311428
explain: t.Optional[bool] = None,
14321429
ignore_cron: t.Optional[bool] = None,
14331430
min_intervals: t.Optional[int] = None,
1434-
always_recreate_environment: t.Optional[bool] = None,
14351431
) -> PlanBuilder:
14361432
"""Creates a plan builder.
14371433
@@ -1470,7 +1466,6 @@ def plan_builder(
14701466
diff_rendered: Whether the diff should compare raw vs rendered models
14711467
min_intervals: Adjust the plan start date on a per-model basis in order to ensure at least this many intervals are covered
14721468
on every model when checking for missing intervals
1473-
always_recreate_environment: Whether to always recreate the target environment from the `create_from` environment.
14741469
Returns:
14751470
The plan builder.
14761471
"""
@@ -1501,7 +1496,6 @@ def plan_builder(
15011496
"diff_rendered": diff_rendered,
15021497
"skip_linter": skip_linter,
15031498
"min_intervals": min_intervals,
1504-
"always_recreate_environment": always_recreate_environment,
15051499
}
15061500
user_provided_flags: t.Dict[str, UserProvidedFlags] = {
15071501
k: v for k, v in kwargs.items() if v is not None
@@ -1593,8 +1587,7 @@ def plan_builder(
15931587
or (backfill_models is not None and not backfill_models),
15941588
ensure_finalized_snapshots=self.config.plan.use_finalized_state,
15951589
diff_rendered=diff_rendered,
1596-
always_recreate_environment=always_recreate_environment
1597-
or self.config.plan.always_recreate_environment,
1590+
always_recreate_environment=self.config.plan.always_recreate_environment,
15981591
)
15991592
modified_model_names = {
16001593
*context_diff.modified_snapshots,

sqlmesh_dbt/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def dbt(
9393
help="If specified, dbt will drop incremental models and fully-recalculate the incremental table from the model definition.",
9494
)
9595
@click.option(
96+
"--env",
9697
"--environment",
9798
help="Run against a specific Virtual Data Environment (VDE) instead of the main environment",
9899
)

sqlmesh_dbt/operations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ def _plan_options(
109109
dict(
110110
# don't create views for all of prod in the dev environment
111111
include_unmodified=False,
112-
# always plan from scratch against prod rather than planning against the previous state of an existing dev environment
113-
# this results in the full scope of changes vs prod always being shown on the local branch
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
114114
create_from=c.PROD,
115-
always_recreate_environment=True,
116115
# Always enable dev previews for incremental / forward-only models.
117116
# Due to how DBT does incrementals (INCREMENTAL_UNMANAGED on the SQLMesh engine), this will result in the full model being refreshed
118117
# with the entire dataset, which can potentially be very large. If this is undesirable, users have two options:

tests/dbt/cli/test_operations.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time_machine
88
from sqlmesh.core.console import NoopConsole
99
from sqlmesh.core.plan import PlanBuilder
10+
from sqlmesh.core.config.common import VirtualEnvironmentMode
1011

1112
pytestmark = pytest.mark.slow
1213

@@ -93,6 +94,18 @@ def test_create_can_specify_profile_and_target(jaffle_shop_duckdb: Path):
9394
assert dbt_project.context.target_name == "dev"
9495

9596

97+
def test_default_options(jaffle_shop_duckdb: Path):
98+
operations = create()
99+
100+
config = operations.context.config
101+
dbt_project = operations.project
102+
103+
assert config.plan.always_recreate_environment is True
104+
assert config.virtual_environment_mode == VirtualEnvironmentMode.DEV_ONLY
105+
assert config.model_defaults.start is not None
106+
assert config.model_defaults.dialect == dbt_project.context.target.dialect
107+
108+
96109
def test_create_can_set_project_variables(jaffle_shop_duckdb: Path):
97110
(jaffle_shop_duckdb / "models" / "test_model.sql").write_text("""
98111
select '{{ var('foo') }}' as a

0 commit comments

Comments
 (0)