Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -349,6 +349,8 @@ class PostgresManager:
|
|
| 349 |
"""
|
| 350 |
Crea un schema aislado en Neon y restaura dentro de 茅l
|
| 351 |
un dump de Postgres (schema + datos, con COPY, funciones, etc.).
|
|
|
|
|
|
|
| 352 |
"""
|
| 353 |
connection_id = self._new_connection_id()
|
| 354 |
schema_name = f"sess_{uuid.uuid4().hex[:8]}"
|
|
@@ -371,6 +373,27 @@ class PostgresManager:
|
|
| 371 |
# 2) Ejecutar el dump sanitizado dentro del schema
|
| 372 |
self._execute_sanitized_pg_dump(cur, sql_text, schema_name)
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
except Exception as e:
|
| 375 |
# Limpiar schema si algo sali贸 mal
|
| 376 |
try:
|
|
@@ -390,7 +413,7 @@ class PostgresManager:
|
|
| 390 |
self.connections[connection_id] = {
|
| 391 |
"label": label,
|
| 392 |
"engine": "postgres",
|
| 393 |
-
"schema": schema_name,
|
| 394 |
}
|
| 395 |
return connection_id
|
| 396 |
|
|
|
|
| 349 |
"""
|
| 350 |
Crea un schema aislado en Neon y restaura dentro de 茅l
|
| 351 |
un dump de Postgres (schema + datos, con COPY, funciones, etc.).
|
| 352 |
+
Despu茅s de restaurar, detecta en qu茅 schema real quedaron las tablas
|
| 353 |
+
(pagila, public, sess_xxxx, etc.) y usa ese schema para la conexi贸n.
|
| 354 |
"""
|
| 355 |
connection_id = self._new_connection_id()
|
| 356 |
schema_name = f"sess_{uuid.uuid4().hex[:8]}"
|
|
|
|
| 373 |
# 2) Ejecutar el dump sanitizado dentro del schema
|
| 374 |
self._execute_sanitized_pg_dump(cur, sql_text, schema_name)
|
| 375 |
|
| 376 |
+
# 3) Detectar el schema REAL donde quedaron las tablas del dump
|
| 377 |
+
cur.execute(
|
| 378 |
+
"""
|
| 379 |
+
SELECT table_schema, COUNT(*) AS n
|
| 380 |
+
FROM information_schema.tables
|
| 381 |
+
WHERE table_type = 'BASE TABLE'
|
| 382 |
+
AND table_schema NOT IN ('pg_catalog','information_schema')
|
| 383 |
+
GROUP BY table_schema
|
| 384 |
+
ORDER BY n DESC;
|
| 385 |
+
"""
|
| 386 |
+
)
|
| 387 |
+
rows = cur.fetchall()
|
| 388 |
+
if rows:
|
| 389 |
+
real_schema = rows[0][0]
|
| 390 |
+
if real_schema != schema_name:
|
| 391 |
+
print(
|
| 392 |
+
f"[WARN] Dump cre贸 tablas en schema '{real_schema}' "
|
| 393 |
+
f"en vez de '{schema_name}'. Usando '{real_schema}'."
|
| 394 |
+
)
|
| 395 |
+
schema_name = real_schema
|
| 396 |
+
|
| 397 |
except Exception as e:
|
| 398 |
# Limpiar schema si algo sali贸 mal
|
| 399 |
try:
|
|
|
|
| 413 |
self.connections[connection_id] = {
|
| 414 |
"label": label,
|
| 415 |
"engine": "postgres",
|
| 416 |
+
"schema": schema_name, # 馃憟 ahora es el schema REAL con tablas
|
| 417 |
}
|
| 418 |
return connection_id
|
| 419 |
|