Spaces:
Running
Running
psycopg3
Browse files- py_backend/alembic/env.py +1 -1
- py_backend/app/database.py +5 -4
- py_backend/requirements.txt +2 -2
py_backend/alembic/env.py
CHANGED
|
@@ -48,7 +48,7 @@ def run_migrations_offline() -> None:
|
|
| 48 |
|
| 49 |
def run_migrations_online() -> None:
|
| 50 |
url = _get_db_url()
|
| 51 |
-
engine = create_engine(url, poolclass=pool.NullPool
|
| 52 |
with engine.connect() as connection:
|
| 53 |
context.configure(
|
| 54 |
connection=connection,
|
|
|
|
| 48 |
|
| 49 |
def run_migrations_online() -> None:
|
| 50 |
url = _get_db_url()
|
| 51 |
+
engine = create_engine(url, poolclass=pool.NullPool)
|
| 52 |
with engine.connect() as connection:
|
| 53 |
context.configure(
|
| 54 |
connection=connection,
|
py_backend/app/database.py
CHANGED
|
@@ -11,24 +11,25 @@ raw_db_url = settings.DATABASE_URL
|
|
| 11 |
if raw_db_url.startswith("psql '") and raw_db_url.endswith("'"):
|
| 12 |
raw_db_url = raw_db_url[6:-1]
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
if "sslmode=" not in raw_db_url and "localhost" not in raw_db_url and "127.0.0.1" not in raw_db_url:
|
| 15 |
raw_db_url = f"{raw_db_url}{'&' if '?' in raw_db_url else '?'}sslmode=require"
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
engine = create_engine(
|
| 20 |
raw_db_url,
|
| 21 |
pool_pre_ping=True,
|
| 22 |
pool_recycle=300,
|
| 23 |
-
|
| 24 |
-
future=True,
|
| 25 |
)
|
| 26 |
|
| 27 |
SessionLocal = sessionmaker(
|
| 28 |
autocommit=False,
|
| 29 |
autoflush=False,
|
| 30 |
bind=engine,
|
| 31 |
-
future=True,
|
| 32 |
)
|
| 33 |
|
| 34 |
Base = declarative_base()
|
|
|
|
| 11 |
if raw_db_url.startswith("psql '") and raw_db_url.endswith("'"):
|
| 12 |
raw_db_url = raw_db_url[6:-1]
|
| 13 |
|
| 14 |
+
# Convert postgresql:// to postgresql+psycopg:// for psycopg v3
|
| 15 |
+
if raw_db_url.startswith("postgresql://") and not raw_db_url.startswith("postgresql+psycopg://"):
|
| 16 |
+
raw_db_url = raw_db_url.replace("postgresql://", "postgresql+psycopg://")
|
| 17 |
+
|
| 18 |
if "sslmode=" not in raw_db_url and "localhost" not in raw_db_url and "127.0.0.1" not in raw_db_url:
|
| 19 |
raw_db_url = f"{raw_db_url}{'&' if '?' in raw_db_url else '?'}sslmode=require"
|
| 20 |
|
| 21 |
+
print(f"database url: {raw_db_url}")
|
| 22 |
|
| 23 |
engine = create_engine(
|
| 24 |
raw_db_url,
|
| 25 |
pool_pre_ping=True,
|
| 26 |
pool_recycle=300,
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
SessionLocal = sessionmaker(
|
| 30 |
autocommit=False,
|
| 31 |
autoflush=False,
|
| 32 |
bind=engine,
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
Base = declarative_base()
|
py_backend/requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn[standard]
|
| 3 |
orjson
|
| 4 |
-
sqlalchemy
|
| 5 |
-
alembic
|
| 6 |
psycopg[binary,pool]
|
| 7 |
boto3
|
| 8 |
python-dotenv
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn[standard]
|
| 3 |
orjson
|
| 4 |
+
sqlalchemy>=2.0.0
|
| 5 |
+
alembic>=1.12.0
|
| 6 |
psycopg[binary,pool]
|
| 7 |
boto3
|
| 8 |
python-dotenv
|