@@ -1134,6 +1134,57 @@ def test_create_clone_in_dev(mocker: MockerFixture, adapter_mock, make_snapshot)
11341134 )
11351135
11361136
1137+ def test_drop_clone_in_dev_when_migration_fails (mocker : MockerFixture , adapter_mock , make_snapshot ):
1138+ adapter_mock .SUPPORTS_CLONING = True
1139+ adapter_mock .get_alter_expressions .return_value = []
1140+ evaluator = SnapshotEvaluator (adapter_mock )
1141+
1142+ adapter_mock .alter_table .side_effect = Exception ("Migration failed" )
1143+
1144+ model = load_sql_based_model (
1145+ parse ( # type: ignore
1146+ """
1147+ MODEL (
1148+ name test_schema.test_model,
1149+ kind INCREMENTAL_BY_TIME_RANGE (
1150+ time_column ds
1151+ )
1152+ );
1153+
1154+ SELECT 1::INT as a, ds::DATE FROM a;
1155+ """
1156+ ),
1157+ )
1158+
1159+ snapshot = make_snapshot (model )
1160+ snapshot .categorize_as (SnapshotChangeCategory .FORWARD_ONLY )
1161+ snapshot .previous_versions = snapshot .all_versions
1162+
1163+ evaluator .create ([snapshot ], {})
1164+
1165+ adapter_mock .clone_table .assert_called_once_with (
1166+ f"sqlmesh__test_schema.test_schema__test_model__{ snapshot .version } __temp" ,
1167+ f"sqlmesh__test_schema.test_schema__test_model__{ snapshot .version } " ,
1168+ replace = True ,
1169+ )
1170+
1171+ adapter_mock .get_alter_expressions .assert_called_once_with (
1172+ f"sqlmesh__test_schema.test_schema__test_model__{ snapshot .version } __temp" ,
1173+ f"sqlmesh__test_schema.test_schema__test_model__{ snapshot .version } __temp__schema_migration_source" ,
1174+ )
1175+
1176+ adapter_mock .alter_table .assert_called_once_with ([])
1177+
1178+ adapter_mock .drop_table .assert_has_calls (
1179+ [
1180+ call (f"sqlmesh__test_schema.test_schema__test_model__{ snapshot .version } __temp" ),
1181+ call (
1182+ f"sqlmesh__test_schema.test_schema__test_model__{ snapshot .version } __temp__schema_migration_source"
1183+ ),
1184+ ]
1185+ )
1186+
1187+
11371188def test_create_clone_in_dev_self_referencing (mocker : MockerFixture , adapter_mock , make_snapshot ):
11381189 adapter_mock .SUPPORTS_CLONING = True
11391190 adapter_mock .get_alter_expressions .return_value = []
0 commit comments