You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
901 B
Python
38 lines
901 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
from app.core.settings import settings
|
|
|
|
if settings.cloud_sql_connection_name:
|
|
# Cloud Run
|
|
DATABASE_URL = (
|
|
f"postgresql+psycopg2://{settings.db_user}:"
|
|
f"{settings.db_password}@/"
|
|
f"{settings.db_name}"
|
|
f"?host=/cloudsql/{settings.cloud_sql_connection_name}"
|
|
)
|
|
else:
|
|
# Ambiente local
|
|
DATABASE_URL = (
|
|
f"postgresql+psycopg2://{settings.db_user}:"
|
|
f"{settings.db_password}@"
|
|
f"{settings.db_host}:"
|
|
f"{settings.db_port}/"
|
|
f"{settings.db_name}"
|
|
)
|
|
|
|
engine = create_engine(
|
|
DATABASE_URL,
|
|
echo=True,
|
|
pool_pre_ping=True,
|
|
pool_recycle=3600,
|
|
connect_args={"connect_timeout": 10}
|
|
)
|
|
|
|
SessionLocal = sessionmaker(
|
|
autocommit=False,
|
|
autoflush=False,
|
|
bind=engine
|
|
)
|
|
|
|
Base = declarative_base()
|