@@ -16,13 +16,11 @@ class PostgresSchema:
16
16
NAME_MAX_LENGTH = 63
17
17
18
18
name : str
19
- using : str
20
19
21
20
default : "PostgresSchema"
22
21
23
- def __init__ (self , name : str , * , using : str = DEFAULT_DB_ALIAS ) -> None :
22
+ def __init__ (self , name : str ) -> None :
24
23
self .name = name
25
- self .using = using
26
24
27
25
@classmethod
28
26
def create (
@@ -51,7 +49,7 @@ def create(
51
49
with connections [using ].schema_editor () as schema_editor :
52
50
schema_editor .create_schema (name )
53
51
54
- return cls (name , using = using )
52
+ return cls (name )
55
53
56
54
@classmethod
57
55
def create_time_based (
@@ -116,7 +114,7 @@ def delete_and_create(
116
114
"""
117
115
118
116
with transaction .atomic (using = using ):
119
- cls (name , using = using ).delete (cascade = cascade )
117
+ cls (name ).delete (cascade = cascade , using = using )
120
118
return cls .create (name , using = using )
121
119
122
120
@classmethod
@@ -137,7 +135,9 @@ def exists(cls, name: str, *, using: str = DEFAULT_DB_ALIAS) -> bool:
137
135
with connection .cursor () as cursor :
138
136
return name in connection .introspection .get_schema_list (cursor )
139
137
140
- def delete (self , * , cascade : bool = False ) -> None :
138
+ def delete (
139
+ self , * , cascade : bool = False , using : str = DEFAULT_DB_ALIAS
140
+ ) -> None :
141
141
"""Deletes the schema and optionally deletes the contents of the schema
142
142
and anything that references it.
143
143
@@ -156,7 +156,7 @@ def delete(self, *, cascade: bool = False) -> None:
156
156
"Pretty sure you are about to make a mistake by trying to drop the 'public' schema. I have stopped you. Thank me later."
157
157
)
158
158
159
- with connections [self . using ].schema_editor () as schema_editor :
159
+ with connections [using ].schema_editor () as schema_editor :
160
160
schema_editor .delete_schema (self .name , cascade = cascade )
161
161
162
162
@classmethod
@@ -207,8 +207,8 @@ def postgres_temporary_schema(
207
207
yield schema
208
208
except Exception as e :
209
209
if delete_on_throw :
210
- schema .delete (cascade = cascade )
210
+ schema .delete (cascade = cascade , using = using )
211
211
212
212
raise e
213
213
214
- schema .delete (cascade = cascade )
214
+ schema .delete (cascade = cascade , using = using )
0 commit comments