Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -388,12 +388,37 @@ class PostgresManager:
|
|
| 388 |
"""
|
| 389 |
)
|
| 390 |
rows = cur.fetchall()
|
|
|
|
| 391 |
if rows:
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
if real_schema != schema_name:
|
| 394 |
print(
|
| 395 |
-
f"[WARN]
|
| 396 |
-
f"
|
| 397 |
)
|
| 398 |
schema_name = real_schema
|
| 399 |
|
|
|
|
| 388 |
"""
|
| 389 |
)
|
| 390 |
rows = cur.fetchall()
|
| 391 |
+
|
| 392 |
if rows:
|
| 393 |
+
# Todos los schemas que tienen tablas
|
| 394 |
+
schemas_with_tables = {s for (s, _) in rows}
|
| 395 |
+
|
| 396 |
+
# Si el schema de sesi贸n ya tiene tablas, lo usamos SIEMPRE
|
| 397 |
+
if schema_name in schemas_with_tables:
|
| 398 |
+
real_schema = schema_name
|
| 399 |
+
else:
|
| 400 |
+
# Si por alguna raz贸n no tiene tablas, preferimos:
|
| 401 |
+
# 1) un schema que empiece por 'sess_'
|
| 402 |
+
# 2) 'pagila'
|
| 403 |
+
# 3) 'public'
|
| 404 |
+
# 4) el primero de la lista
|
| 405 |
+
sess_candidates = [
|
| 406 |
+
s for (s, _) in rows if s.startswith("sess_")
|
| 407 |
+
]
|
| 408 |
+
|
| 409 |
+
if sess_candidates:
|
| 410 |
+
real_schema = sess_candidates[0]
|
| 411 |
+
elif "pagila" in schemas_with_tables:
|
| 412 |
+
real_schema = "pagila"
|
| 413 |
+
elif "public" in schemas_with_tables:
|
| 414 |
+
real_schema = "public"
|
| 415 |
+
else:
|
| 416 |
+
real_schema = rows[0][0]
|
| 417 |
+
|
| 418 |
if real_schema != schema_name:
|
| 419 |
print(
|
| 420 |
+
f"[WARN] Schema '{schema_name}' sin tablas; "
|
| 421 |
+
f"usando schema real '{real_schema}'."
|
| 422 |
)
|
| 423 |
schema_name = real_schema
|
| 424 |
|