@@ -16,13 +16,11 @@ class PostgresSchema:
1616 NAME_MAX_LENGTH = 63
1717
1818 name : str
19- using : str
2019
2120 default : "PostgresSchema"
2221
23- def __init__ (self , name : str , * , using : str = DEFAULT_DB_ALIAS ) -> None :
22+ def __init__ (self , name : str ) -> None :
2423 self .name = name
25- self .using = using
2624
2725 @classmethod
2826 def create (
@@ -51,7 +49,7 @@ def create(
5149 with connections [using ].schema_editor () as schema_editor :
5250 schema_editor .create_schema (name )
5351
54- return cls (name , using = using )
52+ return cls (name )
5553
5654 @classmethod
5755 def create_time_based (
@@ -116,7 +114,7 @@ def delete_and_create(
116114 """
117115
118116 with transaction .atomic (using = using ):
119- cls (name , using = using ).delete (cascade = cascade )
117+ cls (name ).delete (cascade = cascade , using = using )
120118 return cls .create (name , using = using )
121119
122120 @classmethod
@@ -137,7 +135,9 @@ def exists(cls, name: str, *, using: str = DEFAULT_DB_ALIAS) -> bool:
137135 with connection .cursor () as cursor :
138136 return name in connection .introspection .get_schema_list (cursor )
139137
140- def delete (self , * , cascade : bool = False ) -> None :
138+ def delete (
139+ self , * , cascade : bool = False , using : str = DEFAULT_DB_ALIAS
140+ ) -> None :
141141 """Deletes the schema and optionally deletes the contents of the schema
142142 and anything that references it.
143143
@@ -156,7 +156,7 @@ def delete(self, *, cascade: bool = False) -> None:
156156 "Pretty sure you are about to make a mistake by trying to drop the 'public' schema. I have stopped you. Thank me later."
157157 )
158158
159- with connections [self . using ].schema_editor () as schema_editor :
159+ with connections [using ].schema_editor () as schema_editor :
160160 schema_editor .delete_schema (self .name , cascade = cascade )
161161
162162 @classmethod
@@ -207,8 +207,8 @@ def postgres_temporary_schema(
207207 yield schema
208208 except Exception as e :
209209 if delete_on_throw :
210- schema .delete (cascade = cascade )
210+ schema .delete (cascade = cascade , using = using )
211211
212212 raise e
213213
214- schema .delete (cascade = cascade )
214+ schema .delete (cascade = cascade , using = using )
0 commit comments