Skip to content

Commit 99e921a

Browse files
committed
Rename to always_recreate_environment, PR feedback 3
1 parent 3329ee1 commit 99e921a

8 files changed

Lines changed: 15 additions & 17 deletions

File tree

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
@@ -1530,7 +1530,6 @@ def show_environment_difference_summary(
15301530
Args:
15311531
context_diff: The context diff to use to print the summary
15321532
no_diff: Hide the actual environment statement differences.
1533-
environment: The initial target environment
15341533
"""
15351534
if context_diff.is_new_environment:
15361535
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
@@ -1487,7 +1487,7 @@ def plan_builder(
14871487
or (backfill_models is not None and not backfill_models),
14881488
ensure_finalized_snapshots=self.config.plan.use_finalized_state,
14891489
diff_rendered=diff_rendered,
1490-
always_init_from_prod=self.config.plan.always_init_from_prod,
1490+
always_recreate_environment=self.config.plan.always_recreate_environment,
14911491
)
14921492
modified_model_names = {
14931493
*context_diff.modified_snapshots,
@@ -2630,7 +2630,7 @@ def _context_diff(
26302630
force_no_diff: bool = False,
26312631
ensure_finalized_snapshots: bool = False,
26322632
diff_rendered: bool = False,
2633-
always_init_from_prod: bool = False,
2633+
always_recreate_environment: bool = False,
26342634
) -> ContextDiff:
26352635
environment = Environment.sanitize_name(environment)
26362636
if force_no_diff:
@@ -2648,7 +2648,7 @@ def _context_diff(
26482648
environment_statements=self._environment_statements,
26492649
gateway_managed_virtual_layer=self.config.gateway_managed_virtual_layer,
26502650
infer_python_dependencies=self.config.infer_python_dependencies,
2651-
always_init_from_prod=always_init_from_prod,
2651+
always_recreate_environment=always_recreate_environment,
26522652
)
26532653

26542654
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
@@ -160,7 +160,7 @@ def __init__(
160160
self.override_end = end is not None
161161
self.environment_naming_info = EnvironmentNamingInfo.from_environment_catalog_mapping(
162162
environment_catalog_mapping or {},
163-
name=environment,
163+
name=self._context_diff.environment,
164164
suffix_target=environment_suffix_target,
165165
normalize_name=self._context_diff.normalize_environment_name,
166166
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
@@ -6256,7 +6256,7 @@ def test_render_path_instead_of_model(tmp_path: Path):
62566256

62576257

62586258
@use_terminal_console
6259-
def test_plan_always_init_from_prod(tmp_path: Path):
6259+
def test_plan_always_recreate_environment(tmp_path: Path):
62606260
def plan_with_output(ctx: Context, environment: str):
62616261
with patch.object(logger, "info") as mock_logger:
62626262
with capture_output() as output:
@@ -6276,7 +6276,7 @@ def plan_with_output(ctx: Context, environment: str):
62766276
tmp_path, models_dir / "a.sql", "MODEL (name test.a, kind FULL); SELECT 1 AS col"
62776277
)
62786278

6279-
config = Config(plan=PlanConfig(always_init_from_prod=True))
6279+
config = Config(plan=PlanConfig(always_recreate_environment=True))
62806280
ctx = Context(paths=[tmp_path], config=config)
62816281

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

0 commit comments

Comments
 (0)