Skip to content

Commit 5f42366

Browse files
authored
recreate is not needed for views in case of metadata changes + comments not supported
1 parent 91b7c7b commit 5f42366

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def migrate(
477477
allow_destructive_snapshots: t.Optional[t.Set[str]] = None,
478478
allow_additive_snapshots: t.Optional[t.Set[str]] = None,
479479
deployability_index: t.Optional[DeployabilityIndex] = None,
480+
directly_or_indirectly_modified_snapshots_ids: t.Set[SnapshotId] = None,
480481
) -> None:
481482
"""Alters a physical snapshot table to match its snapshot's schema for the given collection of snapshots.
482483
@@ -486,6 +487,7 @@ def migrate(
486487
allow_destructive_snapshots: Set of snapshots that are allowed to have destructive schema changes.
487488
allow_additive_snapshots: Set of snapshots that are allowed to have additive schema changes.
488489
deployability_index: Determines snapshots that are deployable in the context of this evaluation.
490+
directly_or_indirectly_modified_snapshots_ids: Set of SnapshotIds with direct or indirect changes.
489491
"""
490492
deployability_index = deployability_index or DeployabilityIndex.all_deployable()
491493
target_data_objects = self._get_physical_data_objects(target_snapshots, deployability_index)
@@ -510,6 +512,10 @@ def migrate(
510512
allow_additive_snapshots,
511513
self.get_adapter(s.model_gateway),
512514
deployability_index,
515+
only_metadata_changes=s.snapshot_id
516+
not in directly_or_indirectly_modified_snapshots_ids
517+
if directly_or_indirectly_modified_snapshots_ids is not None
518+
else False,
513519
),
514520
self.ddl_concurrent_tasks,
515521
)
@@ -1111,6 +1117,7 @@ def _migrate_snapshot(
11111117
allow_additive_snapshots: t.Set[str],
11121118
adapter: EngineAdapter,
11131119
deployability_index: DeployabilityIndex,
1120+
only_metadata_changes: bool,
11141121
) -> None:
11151122
if not snapshot.is_model or snapshot.is_symbolic:
11161123
return
@@ -1154,6 +1161,7 @@ def _migrate_snapshot(
11541161
allow_destructive_snapshots=allow_destructive_snapshots,
11551162
allow_additive_snapshots=allow_additive_snapshots,
11561163
run_pre_post_statements=True,
1164+
only_metadata_changes=only_metadata_changes,
11571165
)
11581166
else:
11591167
self._execute_create(
@@ -1190,6 +1198,7 @@ def _migrate_target_table(
11901198
allow_destructive_snapshots: t.Set[str],
11911199
allow_additive_snapshots: t.Set[str],
11921200
run_pre_post_statements: bool = False,
1201+
only_metadata_changes: bool = None,
11931202
) -> None:
11941203
adapter = self.get_adapter(snapshot.model.gateway)
11951204

@@ -1226,6 +1235,7 @@ def _migrate_target_table(
12261235
ignore_destructive=snapshot.model.on_destructive_change.is_ignore,
12271236
ignore_additive=snapshot.model.on_additive_change.is_ignore,
12281237
deployability_index=deployability_index,
1238+
only_metadata_changes=only_metadata_changes,
12291239
)
12301240
finally:
12311241
if snapshot.is_materialized:
@@ -2760,20 +2770,23 @@ def migrate(
27602770
**kwargs: t.Any,
27612771
) -> None:
27622772
logger.info("Migrating view '%s'", target_table_name)
2763-
model = snapshot.model
2764-
render_kwargs = dict(
2765-
execution_time=now(), snapshots=kwargs["snapshots"], engine_adapter=self.adapter
2766-
)
2773+
if not (
2774+
kwargs["only_metadata_changes"] and self.adapter.COMMENT_CREATION_VIEW.is_unsupported
2775+
):
2776+
model = snapshot.model
2777+
render_kwargs = dict(
2778+
execution_time=now(), snapshots=kwargs["snapshots"], engine_adapter=self.adapter
2779+
)
27672780

2768-
self.adapter.create_view(
2769-
target_table_name,
2770-
model.render_query_or_raise(**render_kwargs),
2771-
model.columns_to_types,
2772-
materialized=self._is_materialized_view(model),
2773-
view_properties=model.render_physical_properties(**render_kwargs),
2774-
table_description=model.description,
2775-
column_descriptions=model.column_descriptions,
2776-
)
2781+
self.adapter.create_view(
2782+
target_table_name,
2783+
model.render_query_or_raise(**render_kwargs),
2784+
model.columns_to_types,
2785+
materialized=self._is_materialized_view(model),
2786+
view_properties=model.render_physical_properties(**render_kwargs),
2787+
table_description=model.description,
2788+
column_descriptions=model.column_descriptions,
2789+
)
27772790

27782791
# Apply grants after view migration
27792792
deployability_index = kwargs.get("deployability_index")

0 commit comments

Comments
 (0)