Skip to content

Commit a463752

Browse files
authored
Merge pull request #15 from codeforkjeff/fix-detach
check if schema exists before calling DETACH DATABASE
2 parents f4f0f04 + c9f4171 commit a463752

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dbt/adapters/sqlite/impl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ def timestamp_add_sql(
244244
def drop_schema(self, relation: BaseRelation) -> None:
245245
super().drop_schema(relation)
246246

247+
# can't detach a databse in the middle of a transaction, so commit first.
248+
# I wonder if drop_schema() in SQLAdapter should do this, since create_schema() does.
249+
self.commit_if_has_connection()
250+
247251
# never detach main
248252
if relation.schema != 'main':
249-
self.connections.execute(f"DETACH DATABASE {relation.schema}")
253+
if self.check_schema_exists(relation.database, relation.schema):
254+
self.connections.execute(f"DETACH DATABASE {relation.schema}")

0 commit comments

Comments
 (0)