@deinossrl/dgp-agent 1.5.7 → 1.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +129 -8
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1758,6 +1758,29 @@ async function executePgDump(command) {
|
|
|
1758
1758
|
params.schemas.forEach(schema => {
|
|
1759
1759
|
pgDumpArgs.push(`--schema=${schema}`);
|
|
1760
1760
|
});
|
|
1761
|
+
} else if (params.exclude_system_schemas === true && params.connection_type === 'supabase') {
|
|
1762
|
+
// Si el usuario marcó "excluir schemas del sistema" y NO especificó schemas manualmente
|
|
1763
|
+
const supabaseSystemSchemas = [
|
|
1764
|
+
'storage',
|
|
1765
|
+
'auth',
|
|
1766
|
+
'extensions',
|
|
1767
|
+
'realtime',
|
|
1768
|
+
'_realtime',
|
|
1769
|
+
'supabase_functions',
|
|
1770
|
+
'vault',
|
|
1771
|
+
'graphql',
|
|
1772
|
+
'graphql_public',
|
|
1773
|
+
'pgsodium',
|
|
1774
|
+
'pgsodium_masks',
|
|
1775
|
+
'supabase_migrations'
|
|
1776
|
+
];
|
|
1777
|
+
|
|
1778
|
+
logInfo('Excluyendo schemas del sistema de Supabase...');
|
|
1779
|
+
await addCommandLog('info', `Excluyendo ${supabaseSystemSchemas.length} schemas del sistema`);
|
|
1780
|
+
|
|
1781
|
+
supabaseSystemSchemas.forEach(schema => {
|
|
1782
|
+
pgDumpArgs.push(`--exclude-schema=${schema}`);
|
|
1783
|
+
});
|
|
1761
1784
|
}
|
|
1762
1785
|
|
|
1763
1786
|
// Tablas específicas
|
|
@@ -1787,19 +1810,47 @@ async function executePgDump(command) {
|
|
|
1787
1810
|
let stderrBuffer = '';
|
|
1788
1811
|
let stdoutBuffer = '';
|
|
1789
1812
|
let lastLogTime = Date.now();
|
|
1813
|
+
let objectCount = 0;
|
|
1814
|
+
let totalEstimated = 0;
|
|
1815
|
+
|
|
1816
|
+
// Estimar total de objetos si se especificaron schemas/tables
|
|
1817
|
+
if (params.tables && params.tables.length > 0) {
|
|
1818
|
+
totalEstimated = params.tables.length;
|
|
1819
|
+
} else if (params.schemas && params.schemas.length > 0) {
|
|
1820
|
+
// Aproximado: ~20 objetos por schema (tablas, índices, secuencias, etc.)
|
|
1821
|
+
totalEstimated = params.schemas.length * 20;
|
|
1822
|
+
}
|
|
1790
1823
|
|
|
1791
1824
|
// Capturar stderr (pg_dump envía progreso aquí con --verbose)
|
|
1792
1825
|
pgDumpProcess.stderr.on('data', (data) => {
|
|
1793
1826
|
const message = data.toString();
|
|
1794
1827
|
stderrBuffer += message;
|
|
1795
1828
|
|
|
1829
|
+
// Contar objetos procesados
|
|
1830
|
+
const lines = message.split('\n');
|
|
1831
|
+
for (const line of lines) {
|
|
1832
|
+
if (line.includes('processing') || line.includes('dumping data for table') || line.includes('creating') || line.includes('setting owner')) {
|
|
1833
|
+
objectCount++;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1796
1837
|
// Enviar log cada 2 segundos para no saturar
|
|
1797
1838
|
const now = Date.now();
|
|
1798
1839
|
if (now - lastLogTime > 2000) {
|
|
1799
|
-
const
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1840
|
+
const relevantLine = lines[lines.length - 1].trim();
|
|
1841
|
+
if (relevantLine && (relevantLine.includes('processing') || relevantLine.includes('dumping') || relevantLine.includes('table') || relevantLine.includes('creating'))) {
|
|
1842
|
+
let progressMsg = '';
|
|
1843
|
+
|
|
1844
|
+
// Si tenemos estimación, mostrar porcentaje
|
|
1845
|
+
if (totalEstimated > 0 && objectCount > 0) {
|
|
1846
|
+
const percentage = Math.min(Math.round((objectCount / totalEstimated) * 100), 100);
|
|
1847
|
+
progressMsg = `Progreso: ${percentage}% (${objectCount}/${totalEstimated}) - `;
|
|
1848
|
+
} else if (objectCount > 0) {
|
|
1849
|
+
progressMsg = `Objetos procesados: ${objectCount} - `;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
progressMsg += relevantLine.substring(0, 80);
|
|
1853
|
+
addCommandLog('info', progressMsg).catch(() => {});
|
|
1803
1854
|
lastLogTime = now;
|
|
1804
1855
|
}
|
|
1805
1856
|
}
|
|
@@ -1821,6 +1872,10 @@ async function executePgDump(command) {
|
|
|
1821
1872
|
const errorMsg = stderrBuffer || stdoutBuffer || 'Unknown error';
|
|
1822
1873
|
reject(new Error(`pg_dump failed with code ${code}: ${errorMsg}`));
|
|
1823
1874
|
} else {
|
|
1875
|
+
// Log final con total de objetos procesados
|
|
1876
|
+
if (objectCount > 0) {
|
|
1877
|
+
addCommandLog('success', `Backup completado: ${objectCount} objetos exportados`).catch(() => {});
|
|
1878
|
+
}
|
|
1824
1879
|
resolve();
|
|
1825
1880
|
}
|
|
1826
1881
|
});
|
|
@@ -2214,9 +2269,35 @@ async function executePgRestore(command) {
|
|
|
2214
2269
|
pgRestoreArgs.push('--no-owner');
|
|
2215
2270
|
pgRestoreArgs.push('--no-privileges');
|
|
2216
2271
|
|
|
2272
|
+
// Agregar --verbose para obtener información de progreso
|
|
2273
|
+
pgRestoreArgs.push('--verbose');
|
|
2274
|
+
|
|
2217
2275
|
// Archivo de entrada
|
|
2218
2276
|
pgRestoreArgs.push(localFilePath);
|
|
2219
2277
|
|
|
2278
|
+
// CALCULAR TOTAL DE OBJETOS para el porcentaje
|
|
2279
|
+
let totalObjects = 0;
|
|
2280
|
+
try {
|
|
2281
|
+
const listResult = spawnSync(pgRestorePath, ['--list', localFilePath], {
|
|
2282
|
+
env: process.env,
|
|
2283
|
+
encoding: 'utf-8',
|
|
2284
|
+
stdio: 'pipe',
|
|
2285
|
+
});
|
|
2286
|
+
|
|
2287
|
+
if (listResult.status === 0 && listResult.stdout) {
|
|
2288
|
+
// Contar líneas que representan objetos (excluir comentarios y líneas vacías)
|
|
2289
|
+
const lines = listResult.stdout.split('\n').filter(line => {
|
|
2290
|
+
const trimmed = line.trim();
|
|
2291
|
+
return trimmed && !trimmed.startsWith(';') && /^\d+;/.test(trimmed);
|
|
2292
|
+
});
|
|
2293
|
+
totalObjects = lines.length;
|
|
2294
|
+
logInfo(`Total de objetos a restaurar: ${totalObjects}`);
|
|
2295
|
+
await addCommandLog('info', `Objetos a procesar: ${totalObjects}`);
|
|
2296
|
+
}
|
|
2297
|
+
} catch (e) {
|
|
2298
|
+
logInfo('No se pudo contar objetos, continuando sin porcentaje...');
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2220
2301
|
// Ejecutar pg_restore con progreso en tiempo real
|
|
2221
2302
|
logCommand(`Ejecutando: pg_restore [conexión oculta]`);
|
|
2222
2303
|
await addCommandLog('command', 'Ejecutando pg_restore...');
|
|
@@ -2227,24 +2308,64 @@ async function executePgRestore(command) {
|
|
|
2227
2308
|
const result = await new Promise((resolve, reject) => {
|
|
2228
2309
|
const child = spawn(pgRestorePath, pgRestoreArgs, {
|
|
2229
2310
|
env: process.env,
|
|
2230
|
-
stdio: 'pipe',
|
|
2311
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
2231
2312
|
});
|
|
2232
2313
|
|
|
2233
2314
|
let stdout = '';
|
|
2234
2315
|
let stderr = '';
|
|
2316
|
+
let processedObjects = 0;
|
|
2317
|
+
let lastLogTime = Date.now();
|
|
2235
2318
|
|
|
2236
2319
|
child.stdout.on('data', (data) => {
|
|
2237
2320
|
stdout += data.toString();
|
|
2238
2321
|
});
|
|
2239
2322
|
|
|
2240
2323
|
child.stderr.on('data', (data) => {
|
|
2241
|
-
|
|
2324
|
+
const message = data.toString();
|
|
2325
|
+
stderr += message;
|
|
2326
|
+
|
|
2327
|
+
// Contar objetos procesados buscando patrones como "processing item" o nombres de tablas
|
|
2328
|
+
const lines = message.split('\n');
|
|
2329
|
+
for (const line of lines) {
|
|
2330
|
+
if (line.includes('processing') || line.includes('creating') || line.includes('restoring')) {
|
|
2331
|
+
processedObjects++;
|
|
2332
|
+
|
|
2333
|
+
// Enviar log cada 2 segundos para no saturar
|
|
2334
|
+
const now = Date.now();
|
|
2335
|
+
if (now - lastLogTime > 2000) {
|
|
2336
|
+
let progressMsg = '';
|
|
2337
|
+
|
|
2338
|
+
if (totalObjects > 0) {
|
|
2339
|
+
const percentage = Math.min(Math.round((processedObjects / totalObjects) * 100), 100);
|
|
2340
|
+
progressMsg = `Progreso: ${percentage}% (${processedObjects}/${totalObjects})`;
|
|
2341
|
+
} else {
|
|
2342
|
+
progressMsg = `Objetos procesados: ${processedObjects}`;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// Agregar detalle de lo que se está procesando
|
|
2346
|
+
const relevantLine = line.substring(0, 100).trim();
|
|
2347
|
+
if (relevantLine) {
|
|
2348
|
+
progressMsg += ` - ${relevantLine}`;
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
addCommandLog('info', progressMsg).catch(() => {});
|
|
2352
|
+
lastLogTime = now;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2242
2356
|
});
|
|
2243
2357
|
|
|
2244
|
-
// Mostrar progreso cada 10 segundos
|
|
2358
|
+
// Mostrar progreso por tiempo cada 10 segundos como respaldo
|
|
2245
2359
|
progressInterval = setInterval(() => {
|
|
2246
2360
|
const elapsed = Math.floor((Date.now() - startTime) / 1000);
|
|
2247
|
-
|
|
2361
|
+
if (Date.now() - lastLogTime > 10000) { // Solo si no se ha logueado recientemente
|
|
2362
|
+
let msg = `Restaurando... (${elapsed}s transcurridos)`;
|
|
2363
|
+
if (totalObjects > 0 && processedObjects > 0) {
|
|
2364
|
+
const percentage = Math.min(Math.round((processedObjects / totalObjects) * 100), 100);
|
|
2365
|
+
msg += ` - ${percentage}%`;
|
|
2366
|
+
}
|
|
2367
|
+
logInfo(msg);
|
|
2368
|
+
}
|
|
2248
2369
|
}, 10000);
|
|
2249
2370
|
|
|
2250
2371
|
child.on('error', (error) => {
|