Skip to content

Commit 6faf43f

Browse files
committed
Rename to always_recreate_environment, PR feedback 3
1 parent cfc115c commit 6faf43f

File tree

8 files changed

+15
-17
lines changed

8 files changed

+15
-17
lines changed

docs/guides/configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,15 @@ Example showing default values:
386386

387387
By default, SQLMesh compares the current state of project files to the target `<env>` environment when `sqlmesh plan <env>` is run. However, a common expectation is that local changes should always be compared to the production environment.
388388

389-
The `always_init_from_prod` boolean plan option can alter this behavior. When enabled, SQLMesh will always attempt to compare against the production environment; If that does not exist, SQLMesh will fall back to comparing against the target environment.
389+
The `always_recreate_environment` boolean plan option can alter this behavior. When enabled, SQLMesh will always attempt to compare against the production environment by recreating the target environment; If `prod` does not exist, SQLMesh will fall back to comparing against the target environment.
390390

391391
**NOTE:**: Upon succesfull plan application, changes are still promoted to the target `<env>` environment.
392392

393393
=== "YAML"
394394

395395
```yaml linenums="1"
396396
plan:
397-
always_init_from_prod: True
397+
always_recreate_environment: True
398398
```
399399

400400
=== "Python"
@@ -416,7 +416,7 @@ The `always_init_from_prod` boolean plan option can alter this behavior. When en
416416

417417
#### Change Categorization Example
418418

419-
Consider this scenario with `always_init_from_prod` enabled:
419+
Consider this scenario with `always_recreate_environment` enabled:
420420

421421
1. Initial state in `prod`:
422422
```sql

docs/reference/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Configuration for the `sqlmesh plan` command.
8080
| `enable_preview` | Indicates whether to enable [data preview](../concepts/plans.md#data-preview) for forward-only models when targeting a development environment (Default: True, except for dbt projects where the target engine does not support cloning) | Boolean | N |
8181
| `no_diff` | Don't show diffs for changed models (Default: False) | boolean | N |
8282
| `no_prompts` | Disables interactive prompts in CLI (Default: True) | boolean | N |
83-
| `always_init_from_prod` | Always recreates the target environment from the environment specified in `create_from` (by default `prod`) (Default: False) | boolean | N |
83+
| `always_recreate_environment` | Always recreates the target environment from the environment specified in `create_from` (by default `prod`) (Default: False) | boolean | N |
8484
## Run
8585

8686
Configuration for the `sqlmesh run` command. Please note that this is only applicable when configured with the [builtin](#builtin) scheduler.

sqlmesh/core/config/plan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PlanConfig(BaseConfig):
2020
auto_apply: Whether to automatically apply the new plan after creation.
2121
use_finalized_state: Whether to compare against the latest finalized environment state, or to use
2222
whatever state the target environment is currently in.
23-
always_init_from_prod: Whether to always recreate the target environment from the prod environment.
23+
always_recreate_environment: Whether to always recreate the target environment from the prod environment.
2424
"""
2525

2626
forward_only: bool = False
@@ -31,4 +31,4 @@ class PlanConfig(BaseConfig):
3131
no_prompts: bool = True
3232
auto_apply: bool = False
3333
use_finalized_state: bool = False
34-
always_init_from_prod: bool = False
34+
always_recreate_environment: bool = False

sqlmesh/core/console.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,6 @@ def show_environment_difference_summary(
15321532
Args:
15331533
context_diff: The context diff to use to print the summary
15341534
no_diff: Hide the actual environment statement differences.
1535-
environment: The initial target environment
15361535
"""
15371536
if context_diff.is_new_environment:
15381537
msg = (
@@ -2905,7 +2904,6 @@ def show_environment_difference_summary(
29052904
Args:
29062905
context_diff: The context diff to use to print the summary.
29072906
no_diff: Hide the actual environment statements differences.
2908-
environment: The initial target environment
29092907
"""
29102908
if context_diff.is_new_environment:
29112909
msg = (

sqlmesh/core/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ def plan_builder(
14841484
or (backfill_models is not None and not backfill_models),
14851485
ensure_finalized_snapshots=self.config.plan.use_finalized_state,
14861486
diff_rendered=diff_rendered,
1487-
always_init_from_prod=self.config.plan.always_init_from_prod,
1487+
always_recreate_environment=self.config.plan.always_recreate_environment,
14881488
)
14891489
modified_model_names = {
14901490
*context_diff.modified_snapshots,
@@ -2609,7 +2609,7 @@ def _context_diff(
26092609
force_no_diff: bool = False,
26102610
ensure_finalized_snapshots: bool = False,
26112611
diff_rendered: bool = False,
2612-
always_init_from_prod: bool = False,
2612+
always_recreate_environment: bool = False,
26132613
) -> ContextDiff:
26142614
environment = Environment.sanitize_name(environment)
26152615
if force_no_diff:
@@ -2627,7 +2627,7 @@ def _context_diff(
26272627
environment_statements=self._environment_statements,
26282628
gateway_managed_virtual_layer=self.config.gateway_managed_virtual_layer,
26292629
infer_python_dependencies=self.config.infer_python_dependencies,
2630-
always_init_from_prod=always_init_from_prod,
2630+
always_recreate_environment=always_recreate_environment,
26312631
)
26322632

26332633
def _destroy(self) -> None:

sqlmesh/core/context_diff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def create(
104104
environment_statements: t.Optional[t.List[EnvironmentStatements]] = [],
105105
gateway_managed_virtual_layer: bool = False,
106106
infer_python_dependencies: bool = True,
107-
always_init_from_prod: bool = False,
107+
always_recreate_environment: bool = False,
108108
) -> ContextDiff:
109109
"""Create a ContextDiff object.
110110
@@ -133,7 +133,7 @@ def create(
133133
existing_env = state_reader.get_environment(environment)
134134
create_from_env_exists = False
135135

136-
if existing_env is None or existing_env.expired or always_init_from_prod:
136+
if existing_env is None or existing_env.expired or always_recreate_environment:
137137
env = state_reader.get_environment(create_from.lower())
138138

139139
if not env and create_from != c.PROD:
@@ -223,7 +223,7 @@ def create(
223223

224224
previous_environment_statements = state_reader.get_environment_statements(environment)
225225

226-
if existing_env and always_init_from_prod:
226+
if existing_env and always_recreate_environment:
227227
previous_plan_id: t.Optional[str] = existing_env.plan_id
228228
else:
229229
previous_plan_id = env.plan_id if env and not is_new_environment else None

sqlmesh/core/plan/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(
157157
self.override_end = end is not None
158158
self.environment_naming_info = EnvironmentNamingInfo.from_environment_catalog_mapping(
159159
environment_catalog_mapping or {},
160-
name=environment,
160+
name=self._context_diff.environment,
161161
suffix_target=environment_suffix_target,
162162
normalize_name=self._context_diff.normalize_environment_name,
163163
gateway_managed=self._context_diff.gateway_managed_virtual_layer,

tests/core/test_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6212,7 +6212,7 @@ def test_render_path_instead_of_model(tmp_path: Path):
62126212

62136213

62146214
@use_terminal_console
6215-
def test_plan_always_init_from_prod(tmp_path: Path):
6215+
def test_plan_always_recreate_environment(tmp_path: Path):
62166216
def plan_with_output(ctx: Context, environment: str):
62176217
with patch.object(logger, "info") as mock_logger:
62186218
with capture_output() as output:
@@ -6232,7 +6232,7 @@ def plan_with_output(ctx: Context, environment: str):
62326232
tmp_path, models_dir / "a.sql", "MODEL (name test.a, kind FULL); SELECT 1 AS col"
62336233
)
62346234

6235-
config = Config(plan=PlanConfig(always_init_from_prod=True))
6235+
config = Config(plan=PlanConfig(always_recreate_environment=True))
62366236
ctx = Context(paths=[tmp_path], config=config)
62376237

62386238
# Case 1: Neither prod nor dev exists, so dev is initialized

0 commit comments

Comments
 (0)