Syntrex commited on
Commit
29665de
·
verified ·
1 Parent(s): e10a2c2

Update database/remote_db.py

Browse files
Files changed (1) hide show
  1. database/remote_db.py +11 -1
database/remote_db.py CHANGED
@@ -1,17 +1,27 @@
1
- from sqlalchemy import create_engine
 
2
  import os
3
 
 
 
4
 
5
  DATABASE_URL = os.getenv("DATABASE_URL")
6
 
7
  if not DATABASE_URL:
8
  raise RuntimeError("DATABASE_URL is not set")
9
 
 
 
 
 
 
 
10
  engine = create_engine(
11
  DATABASE_URL,
12
  pool_pre_ping=True,
13
  pool_recycle=300,
14
  )
15
 
 
16
  def get_connection():
17
  return engine.connect()
 
1
+ from __future__ import annotations
2
+
3
  import os
4
 
5
+ from sqlalchemy import create_engine
6
+
7
 
8
  DATABASE_URL = os.getenv("DATABASE_URL")
9
 
10
  if not DATABASE_URL:
11
  raise RuntimeError("DATABASE_URL is not set")
12
 
13
+ DATABASE_URL = DATABASE_URL.strip()
14
+
15
+ # Cockroach needs the cockroachdb dialect for SQLAlchemy
16
+ if DATABASE_URL.startswith("postgresql://"):
17
+ DATABASE_URL = "cockroachdb://" + DATABASE_URL[len("postgresql://"):]
18
+
19
  engine = create_engine(
20
  DATABASE_URL,
21
  pool_pre_ping=True,
22
  pool_recycle=300,
23
  )
24
 
25
+
26
  def get_connection():
27
  return engine.connect()