Spaces:
Sleeping
Sleeping
Adzacam commited on
Commit ·
1ce6a14
1
Parent(s): cc5c869
Fix: Pooler Supabase IPv4 (puerto 6543) + credenciales fuera del repo
Browse files- .env +12 -2
- .gitignore +5 -0
- database.py +18 -4
.env
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
DATABASE_URL=postgresql://postgres:Daza20Gira26TecnologiasEmergentesII@db.rxfsdhgxcmtoyinjekok.supabase.co:5432/postgres
|
|
|
|
| 1 |
+
# =============================================================================
|
| 2 |
+
# VARIABLES DE ENTORNO — SOLO PARA DESARROLLO LOCAL
|
| 3 |
+
# =============================================================================
|
| 4 |
+
# En producción (Hugging Face), configura DATABASE_URL en:
|
| 5 |
+
# Space Settings → Variables and secrets
|
| 6 |
+
#
|
| 7 |
+
# Usar el Transaction Pooler de Supabase (puerto 6543, IPv4, compatible con HF):
|
| 8 |
+
# postgresql://postgres.[PROJECT-REF]:[PASSWORD]@aws-0-[REGION].pooler.supabase.com:6543/postgres
|
| 9 |
+
#
|
| 10 |
+
# NUNCA subas credenciales reales a este archivo.
|
| 11 |
+
# =============================================================================
|
| 12 |
|
| 13 |
+
DATABASE_URL=postgresql://postgres.rxfsdhgxcmtoyinjekok:Daza20Gira26TecnologiasEmergentesII@aws-1-us-east-1.pooler.supabase.com:6543/postgres
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
.DS_Store
|
database.py
CHANGED
|
@@ -10,13 +10,27 @@ load_dotenv()
|
|
| 10 |
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 11 |
|
| 12 |
if not DATABASE_URL:
|
| 13 |
-
DATABASE_URL
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
engine = create_engine(
|
| 17 |
DATABASE_URL,
|
| 18 |
pool_pre_ping=True,
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
| 10 |
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 11 |
|
| 12 |
if not DATABASE_URL:
|
| 13 |
+
# En producción (Hugging Face), DATABASE_URL DEBE estar en los Secrets del Space.
|
| 14 |
+
# Nunca hardcodear credenciales aquí — este archivo está en el repositorio público.
|
| 15 |
+
raise RuntimeError(
|
| 16 |
+
"DATABASE_URL no configurada. "
|
| 17 |
+
"Añádela en Hugging Face Space → Settings → Variables and secrets."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Supabase Transaction Pooler (pgBouncer, puerto 6543):
|
| 21 |
+
# - pool_pre_ping: detecta conexiones muertas antes de usarlas
|
| 22 |
+
# - pool_size / max_overflow: límites conservadores para entorno serverless
|
| 23 |
+
# - connect_args: deshabilita prepared statements (requerido por pgBouncer Transaction mode)
|
| 24 |
engine = create_engine(
|
| 25 |
DATABASE_URL,
|
| 26 |
pool_pre_ping=True,
|
| 27 |
+
pool_size=5,
|
| 28 |
+
max_overflow=10,
|
| 29 |
+
pool_recycle=300, # recicla más rápido en pooler
|
| 30 |
+
connect_args={
|
| 31 |
+
"connect_timeout": 10,
|
| 32 |
+
"options": "-c statement_timeout=30000" # 30s max por query
|
| 33 |
+
},
|
| 34 |
)
|
| 35 |
|
| 36 |
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|