@@ -952,6 +952,8 @@ def test_table_name(snapshot: Snapshot, make_snapshot: t.Callable):
952952 assert snapshot .table_name (is_deployable = True ) == "sqlmesh__default.name__3078928823"
953953 assert snapshot .table_name (is_deployable = False ) == "sqlmesh__default.name__3078928823__temp"
954954
955+ assert not snapshot .temp_version
956+
955957 # Mimic an indirect non-breaking change.
956958 previous_data_version = snapshot .data_version
957959 assert previous_data_version .physical_schema == "sqlmesh__default"
@@ -963,6 +965,7 @@ def test_table_name(snapshot: Snapshot, make_snapshot: t.Callable):
963965 assert snapshot .table_name (is_deployable = True ) == "sqlmesh__default.name__3078928823"
964966 # Indirect non-breaking snapshots reuse the dev table as well.
965967 assert snapshot .table_name (is_deployable = False ) == "sqlmesh__default.name__3078928823__temp"
968+ assert snapshot .temp_version
966969
967970 # Mimic a direct forward-only change.
968971 snapshot .fingerprint = SnapshotFingerprint (
@@ -993,6 +996,37 @@ def test_table_name(snapshot: Snapshot, make_snapshot: t.Callable):
993996 )
994997
995998
999+ def test_table_name_view (make_snapshot : t .Callable ):
1000+ # Mimic a direct breaking change.
1001+ snapshot = make_snapshot (SqlModel (name = "name" , query = parse_one ("select 1" ), kind = "VIEW" ))
1002+ snapshot .categorize_as (SnapshotChangeCategory .BREAKING )
1003+ snapshot .previous_versions = ()
1004+ assert snapshot .table_name (is_deployable = True ) == f"sqlmesh__default.name__{ snapshot .version } "
1005+ assert (
1006+ snapshot .table_name (is_deployable = False )
1007+ == f"sqlmesh__default.name__{ snapshot .temp_version_get_or_generate ()} __temp"
1008+ )
1009+
1010+ assert not snapshot .temp_version
1011+
1012+ # Mimic an indirect non-breaking change.
1013+ new_snapshot = make_snapshot (SqlModel (name = "name" , query = parse_one ("select 2" ), kind = "VIEW" ))
1014+ previous_data_version = snapshot .data_version
1015+ new_snapshot .previous_versions = (previous_data_version ,)
1016+ new_snapshot .categorize_as (SnapshotChangeCategory .INDIRECT_NON_BREAKING )
1017+ assert (
1018+ new_snapshot .table_name (is_deployable = True ) == f"sqlmesh__default.name__{ snapshot .version } "
1019+ )
1020+ # Indirect non-breaking view snapshots should not reuse the dev table.
1021+ assert (
1022+ new_snapshot .table_name (is_deployable = False )
1023+ == f"sqlmesh__default.name__{ new_snapshot .temp_version_get_or_generate ()} __temp"
1024+ )
1025+ assert not new_snapshot .temp_version
1026+ assert new_snapshot .version == snapshot .version
1027+ assert new_snapshot .temp_version_get_or_generate () != snapshot .temp_version_get_or_generate ()
1028+
1029+
9961030def test_categorize_change_sql (make_snapshot ):
9971031 old_snapshot = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 1, ds" )))
9981032
0 commit comments