@@ -18,6 +18,9 @@ class CreatableTable(Protocol):
1818 @classmethod
1919 async def exists (cls ) -> CoroutineType [Any , Any , bool ] | bool : ...
2020
21+ @classmethod
22+ async def delete_table (cls ) -> CoroutineType [Any , Any , Any ] | Any : ...
23+
2124 @classmethod
2225 async def create_table (
2326 cls ,
@@ -31,8 +34,14 @@ def __check_creatable_table(cls: type[Any]):
3134 """Check if an object is of type `CreatableTable`"""
3235 if not issubclass (cls , Model ):
3336 raise TypeError (f"{ cls .__name__ } must be a subclass of Model" )
34- if not hasattr (cls , "exists" ) or not hasattr (cls , "create_table" ):
35- raise TypeError (f"{ cls .__name__ } must implement exists() and create_table()" )
37+ if (
38+ not hasattr (cls , "exists" )
39+ or not hasattr (cls , "delete_table" )
40+ or not hasattr (cls , "create_table" )
41+ ):
42+ raise TypeError (
43+ f"{ cls .__name__ } must implement exists(), delete_table() and create_table()"
44+ )
3645
3746
3847async def ensure_tables_exist (* tables : type [CreatableTable ]) -> None :
@@ -51,3 +60,17 @@ async def ensure_tables_exist(*tables: type[CreatableTable]) -> None:
5160 wait = True ,
5261 )
5362 __tables_cache .add (table_cls )
63+
64+
65+ async def delete_tables (* tables : type [CreatableTable ]) -> None :
66+ """
67+ Delete all given DynamoDB tables, if existent.
68+ """
69+ global __tables_cache
70+
71+ for table_cls in tables :
72+ __check_creatable_table (table_cls )
73+ if await table_cls .exists ():
74+ await table_cls .delete_table ()
75+ if table_cls in __tables_cache :
76+ __tables_cache .remove (table_cls )
0 commit comments