dbsync
All checks were successful
Deploy Nyla Frontend to Production / deploy (push) Successful in 44s
All checks were successful
Deploy Nyla Frontend to Production / deploy (push) Successful in 44s
This commit is contained in:
parent
9047304934
commit
554d798ae2
1 changed files with 44 additions and 37 deletions
|
|
@ -841,10 +841,11 @@ const MigrationTab: React.FC = () => {
|
||||||
|
|
||||||
_addExportLog(t('Export gestartet: {count} Datenbanken', { count: totalDbs }));
|
_addExportLog(t('Export gestartet: {count} Datenbanken', { count: totalDbs }));
|
||||||
|
|
||||||
const exportData: Record<string, any> = {};
|
const rawChunks: string[] = [];
|
||||||
let totalTables = 0;
|
let totalTables = 0;
|
||||||
let totalRecords = 0;
|
let totalRecords = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
let exportedCount = 0;
|
||||||
|
|
||||||
for (let i = 0; i < dbList.length; i++) {
|
for (let i = 0; i < dbList.length; i++) {
|
||||||
const dbName = dbList[i];
|
const dbName = dbList[i];
|
||||||
|
|
@ -852,14 +853,17 @@ const MigrationTab: React.FC = () => {
|
||||||
try {
|
try {
|
||||||
const res = await api.get('/api/admin/database-health/migration/export-single', {
|
const res = await api.get('/api/admin/database-health/migration/export-single', {
|
||||||
params: { database: dbName },
|
params: { database: dbName },
|
||||||
|
responseType: 'text',
|
||||||
});
|
});
|
||||||
const dbPayload = res.data.data;
|
const parsed = JSON.parse(res.data);
|
||||||
exportData[dbName] = dbPayload;
|
const dbData = parsed.data;
|
||||||
totalTables += dbPayload.tableCount || 0;
|
totalTables += dbData?.tableCount || 0;
|
||||||
totalRecords += dbPayload.totalRecords || 0;
|
totalRecords += dbData?.totalRecords || 0;
|
||||||
|
rawChunks.push(`${JSON.stringify(dbName)}:${JSON.stringify(dbData)}`);
|
||||||
|
exportedCount++;
|
||||||
_addExportLog(
|
_addExportLog(
|
||||||
t('{db}: {tables} Tabellen, {records} Datensaetze', {
|
t('{db}: {tables} Tabellen, {records} Datensaetze', {
|
||||||
db: dbName, tables: dbPayload.tableCount || 0, records: dbPayload.totalRecords || 0,
|
db: dbName, tables: dbData?.tableCount || 0, records: dbData?.totalRecords || 0,
|
||||||
}),
|
}),
|
||||||
'success',
|
'success',
|
||||||
);
|
);
|
||||||
|
|
@ -873,7 +877,7 @@ const MigrationTab: React.FC = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(exportData).length === 0) {
|
if (exportedCount === 0) {
|
||||||
_addExportLog(t('Export abgebrochen: keine Daten exportiert'), 'error');
|
_addExportLog(t('Export abgebrochen: keine Daten exportiert'), 'error');
|
||||||
toast.showError(t('Export fehlgeschlagen'));
|
toast.showError(t('Export fehlgeschlagen'));
|
||||||
setExporting(false);
|
setExporting(false);
|
||||||
|
|
@ -883,45 +887,48 @@ const MigrationTab: React.FC = () => {
|
||||||
_addExportLog(t('Erstelle Exportdatei...'));
|
_addExportLog(t('Erstelle Exportdatei...'));
|
||||||
await new Promise(r => setTimeout(r, 0));
|
await new Promise(r => setTimeout(r, 0));
|
||||||
|
|
||||||
const fullPayload = {
|
try {
|
||||||
meta: {
|
const meta = JSON.stringify({
|
||||||
exportedAt: new Date().toISOString(),
|
exportedAt: new Date().toISOString(),
|
||||||
version: '1.0',
|
version: '1.0',
|
||||||
databaseCount: Object.keys(exportData).length,
|
databaseCount: exportedCount,
|
||||||
totalTables,
|
totalTables,
|
||||||
totalRecords,
|
totalRecords,
|
||||||
},
|
});
|
||||||
databases: exportData,
|
const jsonStr = `{"meta":${meta},"databases":{${rawChunks.join(',')}}}`;
|
||||||
};
|
|
||||||
|
|
||||||
const ts = new Date().toISOString().replace(/:/g, '-').slice(0, 19);
|
const ts = new Date().toISOString().replace(/:/g, '-').slice(0, 19);
|
||||||
const scope = isFullExport ? 'full' : 'partial';
|
const scope = isFullExport ? 'full' : 'partial';
|
||||||
const filename = `db_backup_${instanceLabel}_${scope}_${ts}.json`;
|
const filename = `db_backup_${instanceLabel}_${scope}_${ts}.json`;
|
||||||
|
|
||||||
const jsonStr = JSON.stringify(fullPayload);
|
const blob = new Blob([jsonStr], { type: 'application/json' });
|
||||||
const blob = new Blob([jsonStr], { type: 'application/json' });
|
const url = URL.createObjectURL(blob);
|
||||||
const url = URL.createObjectURL(blob);
|
const a = document.createElement('a');
|
||||||
const a = document.createElement('a');
|
a.href = url;
|
||||||
a.href = url;
|
a.download = filename;
|
||||||
a.download = filename;
|
document.body.appendChild(a);
|
||||||
document.body.appendChild(a);
|
a.click();
|
||||||
a.click();
|
document.body.removeChild(a);
|
||||||
document.body.removeChild(a);
|
URL.revokeObjectURL(url);
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
|
|
||||||
_addExportLog(
|
_addExportLog(
|
||||||
t('Export abgeschlossen: {dbs} Datenbanken, {tables} Tabellen, {records} Datensaetze', {
|
t('Export abgeschlossen: {dbs} Datenbanken, {tables} Tabellen, {records} Datensaetze', {
|
||||||
dbs: Object.keys(exportData).length, tables: totalTables, records: totalRecords,
|
dbs: exportedCount, tables: totalTables, records: totalRecords,
|
||||||
}),
|
}),
|
||||||
'success',
|
'success',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (errors > 0) {
|
if (errors > 0) {
|
||||||
toast.showWarning(t('Export mit {count} Fehlern abgeschlossen', { count: errors }));
|
toast.showWarning(t('Export mit {count} Fehlern abgeschlossen', { count: errors }));
|
||||||
} else {
|
} else {
|
||||||
toast.showSuccess(t('Export erfolgreich'));
|
toast.showSuccess(t('Export erfolgreich'));
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
_addExportLog(t('Fehler beim Erstellen der Exportdatei: {error}', { error: String(err) }), 'error');
|
||||||
|
toast.showError(t('Export fehlgeschlagen'));
|
||||||
|
} finally {
|
||||||
|
setExporting(false);
|
||||||
}
|
}
|
||||||
setExporting(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Restore: File upload ---
|
// --- Restore: File upload ---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue