Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -125,7 +125,7 @@ class PostgresManager:
|
|
| 125 |
|
| 126 |
def _should_skip_statement(self, stmt: str) -> bool:
|
| 127 |
"""
|
| 128 |
-
Devuelve True si el statement NO debe ejecutarse (grants, owner, create db, etc.).
|
| 129 |
Filtro universal para dumps PostgreSQL (Neon, Pagila, etc.).
|
| 130 |
"""
|
| 131 |
if not stmt:
|
|
@@ -154,6 +154,9 @@ class PostgresManager:
|
|
| 154 |
"DROP EXTENSION",
|
| 155 |
"CREATE SCHEMA", # no queremos recrear schemas globales
|
| 156 |
"ALTER SCHEMA",
|
|
|
|
|
|
|
|
|
|
| 157 |
"REVOKE ",
|
| 158 |
"GRANT ",
|
| 159 |
"ALTER ROLE",
|
|
@@ -201,15 +204,18 @@ class PostgresManager:
|
|
| 201 |
- Reescribe public./pagila. -> schema_name.
|
| 202 |
- Respeta funciones con $$...$$ (no corta por ';' internos).
|
| 203 |
- Ignora statements peligrosos via _should_skip_statement().
|
|
|
|
| 204 |
"""
|
| 205 |
|
| 206 |
in_copy = False
|
| 207 |
copy_sql = ""
|
| 208 |
copy_lines: list[str] = []
|
| 209 |
|
| 210 |
-
buffer = ""
|
| 211 |
-
in_dollar = False
|
| 212 |
-
dollar_tag = ""
|
|
|
|
|
|
|
| 213 |
|
| 214 |
def flush_statement():
|
| 215 |
nonlocal buffer
|
|
@@ -234,8 +240,8 @@ class PostgresManager:
|
|
| 234 |
line = raw_line.rstrip("\n")
|
| 235 |
stripped = line.strip()
|
| 236 |
|
| 237 |
-
# Comentarios y líneas vacías (fuera de COPY)
|
| 238 |
-
if not in_copy:
|
| 239 |
if not stripped or stripped.startswith("--"):
|
| 240 |
continue
|
| 241 |
|
|
@@ -251,6 +257,20 @@ class PostgresManager:
|
|
| 251 |
copy_lines.append(line)
|
| 252 |
continue
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
# Detectar inicio de COPY
|
| 255 |
if (
|
| 256 |
stripped.upper().startswith("COPY ")
|
|
|
|
| 125 |
|
| 126 |
def _should_skip_statement(self, stmt: str) -> bool:
|
| 127 |
"""
|
| 128 |
+
Devuelve True si el statement NO debe ejecutarse (grants, owner, create db, domains, etc.).
|
| 129 |
Filtro universal para dumps PostgreSQL (Neon, Pagila, etc.).
|
| 130 |
"""
|
| 131 |
if not stmt:
|
|
|
|
| 154 |
"DROP EXTENSION",
|
| 155 |
"CREATE SCHEMA", # no queremos recrear schemas globales
|
| 156 |
"ALTER SCHEMA",
|
| 157 |
+
"CREATE DOMAIN", # 👈 ignoramos domains (no los necesitamos)
|
| 158 |
+
"ALTER DOMAIN",
|
| 159 |
+
"DROP DOMAIN",
|
| 160 |
"REVOKE ",
|
| 161 |
"GRANT ",
|
| 162 |
"ALTER ROLE",
|
|
|
|
| 204 |
- Reescribe public./pagila. -> schema_name.
|
| 205 |
- Respeta funciones con $$...$$ (no corta por ';' internos).
|
| 206 |
- Ignora statements peligrosos via _should_skip_statement().
|
| 207 |
+
- Ignora bloques CREATE DOMAIN ... multi-línea sin usar regex agresivos.
|
| 208 |
"""
|
| 209 |
|
| 210 |
in_copy = False
|
| 211 |
copy_sql = ""
|
| 212 |
copy_lines: list[str] = []
|
| 213 |
|
| 214 |
+
buffer = "" # statement acumulado
|
| 215 |
+
in_dollar = False # estamos dentro de $$...$$ ?
|
| 216 |
+
dollar_tag = "" # por ej. "$func$"
|
| 217 |
+
|
| 218 |
+
in_domain_block = False # 👈 estamos dentro de un bloque CREATE DOMAIN ?
|
| 219 |
|
| 220 |
def flush_statement():
|
| 221 |
nonlocal buffer
|
|
|
|
| 240 |
line = raw_line.rstrip("\n")
|
| 241 |
stripped = line.strip()
|
| 242 |
|
| 243 |
+
# Comentarios y líneas vacías (fuera de COPY / DOMAIN)
|
| 244 |
+
if not in_copy and not in_domain_block:
|
| 245 |
if not stripped or stripped.startswith("--"):
|
| 246 |
continue
|
| 247 |
|
|
|
|
| 257 |
copy_lines.append(line)
|
| 258 |
continue
|
| 259 |
|
| 260 |
+
# ====== BLOQUE CREATE DOMAIN (lo ignoramos entero hasta ';') ======
|
| 261 |
+
if in_domain_block:
|
| 262 |
+
# Terminamos el bloque cuando encontramos una línea con solo ';'
|
| 263 |
+
if stripped == ";":
|
| 264 |
+
in_domain_block = False
|
| 265 |
+
# No añadimos nada al buffer
|
| 266 |
+
continue
|
| 267 |
+
|
| 268 |
+
# Detectar inicio de bloque DOMAIN
|
| 269 |
+
if stripped.upper().startswith("CREATE DOMAIN"):
|
| 270 |
+
# Entramos en bloque DOMAIN y lo ignoramos hasta el ';'
|
| 271 |
+
in_domain_block = True
|
| 272 |
+
continue
|
| 273 |
+
|
| 274 |
# Detectar inicio de COPY
|
| 275 |
if (
|
| 276 |
stripped.upper().startswith("COPY ")
|