stvnnnnnn commited on
Commit
856fa70
verified
1 Parent(s): 93661e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -388,12 +388,37 @@ class PostgresManager:
388
  """
389
  )
390
  rows = cur.fetchall()
 
391
  if rows:
392
- real_schema = rows[0][0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  if real_schema != schema_name:
394
  print(
395
- f"[WARN] Dump cre贸 tablas en schema '{real_schema}' "
396
- f"en vez de '{schema_name}'. Usando '{real_schema}'."
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