AshenH commited on
Commit
9d6bac9
·
verified ·
1 Parent(s): 5ac59a8

Update tools/sql_tool.py

Browse files
Files changed (1) hide show
  1. tools/sql_tool.py +15 -1
tools/sql_tool.py CHANGED
@@ -31,13 +31,27 @@ class SQLTool:
31
  self.client = bigquery.Client(credentials=creds, project=cfg.gcp_project)
32
 
33
  elif self.backend == "motherduck":
34
- import duckdb
 
 
 
 
 
 
 
35
 
36
  token = self.cfg.motherduck_token or os.getenv("MOTHERDUCK_TOKEN")
37
  db_name = self.cfg.motherduck_db or "default"
38
  if not token:
39
  raise RuntimeError("Missing MOTHERDUCK_TOKEN")
40
 
 
 
 
 
 
 
 
41
  # Plain DuckDB connection
42
  self.client = duckdb.connect()
43
 
 
31
  self.client = bigquery.Client(credentials=creds, project=cfg.gcp_project)
32
 
33
  elif self.backend == "motherduck":
34
+ import duckdb, shutil, glob
35
+ import os
36
+
37
+ if not duckdb.__version__.startswith("1.3.2"):
38
+ raise RuntimeError(
39
+ "MotherDuck currently supports DuckDB 1.3.2. "
40
+ "Pin duckdb==1.3.2 in requirements.txt and redeploy."
41
+ )
42
 
43
  token = self.cfg.motherduck_token or os.getenv("MOTHERDUCK_TOKEN")
44
  db_name = self.cfg.motherduck_db or "default"
45
  if not token:
46
  raise RuntimeError("Missing MOTHERDUCK_TOKEN")
47
 
48
+ try:
49
+ ext_root = os.path.expanduser("~/.duckdb/extensions")
50
+ for p in glob.glob(os.path.join(ext_root, "*")):
51
+ if "1.3.2" not in p: # keep current version caches, remove others
52
+ shutil.rmtree(p, ignore_errors=True)
53
+ except Exception:
54
+
55
  # Plain DuckDB connection
56
  self.client = duckdb.connect()
57