sqlmesh 0.200.1.dev22__py3-none-any.whl → 0.200.1.dev24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sqlmesh/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.200.1.dev22'
21
- __version_tuple__ = version_tuple = (0, 200, 1, 'dev22')
20
+ __version__ = version = '0.200.1.dev24'
21
+ __version_tuple__ = version_tuple = (0, 200, 1, 'dev24')
sqlmesh/core/console.py CHANGED
@@ -186,9 +186,19 @@ class DestroyConsole(abc.ABC):
186
186
  """Console for describing a destroy operation"""
187
187
 
188
188
  @abc.abstractmethod
189
- def start_destroy(self) -> bool:
189
+ def start_destroy(
190
+ self,
191
+ schemas_to_delete: t.Optional[t.Set[str]] = None,
192
+ views_to_delete: t.Optional[t.Set[str]] = None,
193
+ tables_to_delete: t.Optional[t.Set[str]] = None,
194
+ ) -> bool:
190
195
  """Start a destroy operation.
191
196
 
197
+ Args:
198
+ schemas_to_delete: Set of schemas that will be deleted
199
+ views_to_delete: Set of views that will be deleted
200
+ tables_to_delete: Set of tables that will be deleted
201
+
192
202
  Returns:
193
203
  Whether or not the destroy operation should proceed
194
204
  """
@@ -830,7 +840,12 @@ class NoopConsole(Console):
830
840
  ) -> None:
831
841
  pass
832
842
 
833
- def start_destroy(self) -> bool:
843
+ def start_destroy(
844
+ self,
845
+ schemas_to_delete: t.Optional[t.Set[str]] = None,
846
+ views_to_delete: t.Optional[t.Set[str]] = None,
847
+ tables_to_delete: t.Optional[t.Set[str]] = None,
848
+ ) -> bool:
834
849
  return True
835
850
 
836
851
  def stop_destroy(self, success: bool = True) -> None:
@@ -1282,16 +1297,40 @@ class TerminalConsole(Console):
1282
1297
  else:
1283
1298
  self.log_error("Cleanup failed!")
1284
1299
 
1285
- def start_destroy(self) -> bool:
1300
+ def start_destroy(
1301
+ self,
1302
+ schemas_to_delete: t.Optional[t.Set[str]] = None,
1303
+ views_to_delete: t.Optional[t.Set[str]] = None,
1304
+ tables_to_delete: t.Optional[t.Set[str]] = None,
1305
+ ) -> bool:
1286
1306
  self.log_warning(
1287
- (
1288
- "This will permanently delete all engine-managed objects, state tables and SQLMesh cache.\n"
1289
- "The operation is irreversible and may disrupt any currently running or scheduled plans.\n"
1290
- "Use this command only when you intend to fully reset the project."
1291
- )
1307
+ "This will permanently delete all engine-managed objects, state tables and SQLMesh cache.\n"
1308
+ "The operation may disrupt any currently running or scheduled plans.\n"
1292
1309
  )
1293
- if not self._confirm("Proceed?"):
1294
- self.log_error("Destroy aborted!")
1310
+
1311
+ if schemas_to_delete or views_to_delete or tables_to_delete:
1312
+ if schemas_to_delete:
1313
+ self.log_error("Schemas to be deleted:")
1314
+ for schema in sorted(schemas_to_delete):
1315
+ self.log_error(f" • {schema}")
1316
+
1317
+ if views_to_delete:
1318
+ self.log_error("\nEnvironment views to be deleted:")
1319
+ for view in sorted(views_to_delete):
1320
+ self.log_error(f" • {view}")
1321
+
1322
+ if tables_to_delete:
1323
+ self.log_error("\nSnapshot tables to be deleted:")
1324
+ for table in sorted(tables_to_delete):
1325
+ self.log_error(f" • {table}")
1326
+
1327
+ self.log_error(
1328
+ "\nThis action will DELETE ALL the above resources managed by SQLMesh AND\n"
1329
+ "potentially external resources created by other tools in these schemas.\n"
1330
+ )
1331
+
1332
+ if not self._confirm("Are you ABSOLUTELY SURE you want to proceed with deletion?"):
1333
+ self.log_error("Destroy operation cancelled.")
1295
1334
  return False
1296
1335
  return True
1297
1336
 
sqlmesh/core/context.py CHANGED
@@ -858,10 +858,52 @@ class GenericContext(BaseContext, t.Generic[C]):
858
858
  def destroy(self) -> bool:
859
859
  success = False
860
860
 
861
- if self.console.start_destroy():
861
+ # Collect resources to be deleted
862
+ environments = self.state_reader.get_environments()
863
+ schemas_to_delete = set()
864
+ tables_to_delete = set()
865
+ views_to_delete = set()
866
+ all_snapshot_infos = set()
867
+
868
+ # For each environment find schemas and tables
869
+ for environment in environments:
870
+ all_snapshot_infos.update(environment.snapshots)
871
+ snapshots = self.state_reader.get_snapshots(environment.snapshots).values()
872
+ for snapshot in snapshots:
873
+ if snapshot.is_model and not snapshot.is_symbolic:
874
+ # Get the appropriate adapter
875
+ if environment.gateway_managed and snapshot.model_gateway:
876
+ adapter = self.engine_adapters.get(
877
+ snapshot.model_gateway, self.engine_adapter
878
+ )
879
+ else:
880
+ adapter = self.engine_adapter
881
+
882
+ if environment.suffix_target.is_schema or environment.suffix_target.is_catalog:
883
+ schema = snapshot.qualified_view_name.schema_for_environment(
884
+ environment.naming_info, dialect=adapter.dialect
885
+ )
886
+ catalog = snapshot.qualified_view_name.catalog_for_environment(
887
+ environment.naming_info, dialect=adapter.dialect
888
+ )
889
+ if catalog:
890
+ schemas_to_delete.add(f"{catalog}.{schema}")
891
+ else:
892
+ schemas_to_delete.add(schema)
893
+
894
+ if environment.suffix_target.is_table:
895
+ view_name = snapshot.qualified_view_name.for_environment(
896
+ environment.naming_info, dialect=adapter.dialect
897
+ )
898
+ views_to_delete.add(view_name)
899
+
900
+ # Add snapshot tables
901
+ table_name = snapshot.table_name()
902
+ tables_to_delete.add(table_name)
903
+
904
+ if self.console.start_destroy(schemas_to_delete, views_to_delete, tables_to_delete):
862
905
  try:
863
- self._destroy()
864
- success = True
906
+ success = self._destroy()
865
907
  finally:
866
908
  self.console.stop_destroy(success=success)
867
909
 
@@ -2723,7 +2765,7 @@ class GenericContext(BaseContext, t.Generic[C]):
2723
2765
  always_recreate_environment=always_recreate_environment,
2724
2766
  )
2725
2767
 
2726
- def _destroy(self) -> None:
2768
+ def _destroy(self) -> bool:
2727
2769
  # Invalidate all environments, including prod
2728
2770
  for environment in self.state_reader.get_environments():
2729
2771
  self.state_sync.invalidate_environment(name=environment.name, protect_prod=False)
@@ -2739,6 +2781,8 @@ class GenericContext(BaseContext, t.Generic[C]):
2739
2781
  # Finally clear caches
2740
2782
  self.clear_caches()
2741
2783
 
2784
+ return True
2785
+
2742
2786
  def _run_janitor(self, ignore_ttl: bool = False) -> None:
2743
2787
  current_ts = now_timestamp()
2744
2788
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlmesh
3
- Version: 0.200.1.dev22
3
+ Version: 0.200.1.dev24
4
4
  Summary: Next-generation data transformation framework
5
5
  Author-email: "TobikoData Inc." <engineering@tobikodata.com>
6
6
  License: Apache License
@@ -1,5 +1,5 @@
1
1
  sqlmesh/__init__.py,sha256=QjwaamJIdW7voXoS880yAx7tHm-Im4_mqGA-XJgafos,7631
2
- sqlmesh/_version.py,sha256=U0jhi_308MRKOqqM98agigj69adW1C-9rEu3C36oJ9w,530
2
+ sqlmesh/_version.py,sha256=J1RW6X9kYWBIMKW-TLehP90TCzPYDgP4m2Dd5zJjOiw,530
3
3
  sqlmesh/magics.py,sha256=bEzYqXHcM0P3CjyUZ1O9arlmXAdLAhoglKbQ29fD9AE,41842
4
4
  sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -11,9 +11,9 @@ sqlmesh/cli/options.py,sha256=-4ZclMIeIg8tghLowtmQNmpEFlm0QtOVEh40NqRdFHA,2499
11
11
  sqlmesh/cli/project_init.py,sha256=5JmDmUK0WJs39hM-p76uzHYdo1Hnx6fKuJg_pR3Hn5A,16419
12
12
  sqlmesh/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  sqlmesh/core/_typing.py,sha256=e1f7xO2aZCy38M_3VoDy-XI3shyd99-IFctgIFSgXWM,497
14
- sqlmesh/core/console.py,sha256=GQAWuxK8KZl6UclgPM51upiZXag9u8h1-HKotzjvblA,163884
14
+ sqlmesh/core/console.py,sha256=lb6Zq6BhimfQkcSd19t35owSmaGCqw0WHMhGK-WZ-y4,165491
15
15
  sqlmesh/core/constants.py,sha256=gUABXWYgH_XOSbaZAJsR5o1dmA61JDCvBDyxqqXX3LM,2630
16
- sqlmesh/core/context.py,sha256=vH-wZOjyqyDDvYCdxeXOIEgBFo4jQXBGmIuSCCFmmN0,125223
16
+ sqlmesh/core/context.py,sha256=0EH5FEoPEoxgr3_yu2pasH_Itei7daInEL1uEJgpgwM,127360
17
17
  sqlmesh/core/context_diff.py,sha256=_Ur55fGLJ58Icsp44I4pVhdi7_JHiHq45mWIco9oFzk,21792
18
18
  sqlmesh/core/dialect.py,sha256=1ykYwb9WZn_nCaX08PcQ0BJh2Pihv9SPvoMNjpMeCfs,50158
19
19
  sqlmesh/core/environment.py,sha256=odus40R-YzdQdS_IiUq_tFouUXIhnpwmNwo8dE8Aw1k,13041
@@ -284,7 +284,7 @@ sqlmesh/utils/pydantic.py,sha256=o_NsXbIpDqNpUA1Uc5xF0ZzoXQYYB0DfHwdRxBwXPNk,120
284
284
  sqlmesh/utils/rich.py,sha256=BpB47G0-JcU41LkGkeGKroexj4NOV5fox4-GOIXPgIc,3545
285
285
  sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
286
286
  sqlmesh/utils/yaml.py,sha256=hvo5lmybYLcIx4p6CQwufS8X4MbwS60lEBnCmYJCXmU,2336
287
- sqlmesh-0.200.1.dev22.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
287
+ sqlmesh-0.200.1.dev24.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
288
288
  web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
289
289
  web/client/dist/index.html,sha256=DAv6ABGogw4xRLb0T_92WP_S7XWyqVhwBgGKWtuQwU4,5472
290
290
  web/client/dist/assets/Audits-BuHAmFO8.js,sha256=zbYUF6WdUGMbnMm01GMNPb7xAJwj-o5wMdL56vPo2qE,1041
@@ -402,8 +402,8 @@ web/server/api/endpoints/models.py,sha256=kwj0s7uve3iZSMfmjkoPVMFMeY1sD0peTeyrWf
402
402
  web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
403
403
  web/server/api/endpoints/plan.py,sha256=bbbY50W_2MsZSTxOHWMKz0tbIm75nsRSlPy8GI2fg9Q,9306
404
404
  web/server/api/endpoints/table_diff.py,sha256=SCy3-pr5x6bEEiOaZGCDbiHQhpgxwmnz3Acqa2Ie6jI,2090
405
- sqlmesh-0.200.1.dev22.dist-info/METADATA,sha256=Sew2eEXfajZ7R0CE1lLvlr1AQ68Za_m9Iw5HfXy9yw8,26679
406
- sqlmesh-0.200.1.dev22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
407
- sqlmesh-0.200.1.dev22.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
408
- sqlmesh-0.200.1.dev22.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
409
- sqlmesh-0.200.1.dev22.dist-info/RECORD,,
405
+ sqlmesh-0.200.1.dev24.dist-info/METADATA,sha256=IEDKwaTQP6pK-HIFHy5tfwOlyTMiuOYJTQ8NLV5KAXQ,26679
406
+ sqlmesh-0.200.1.dev24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
407
+ sqlmesh-0.200.1.dev24.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
408
+ sqlmesh-0.200.1.dev24.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
409
+ sqlmesh-0.200.1.dev24.dist-info/RECORD,,