Add tenant import progress polling
This commit is contained in:
@@ -45,6 +45,7 @@ type ImportResult = {
|
||||
|
||||
type ImportOptions = {
|
||||
targetTenantId?: number | null
|
||||
onProgress?: (progress: { done: number; total: number; message?: string }) => Promise<void> | void
|
||||
}
|
||||
|
||||
type BuildTenantFullExportOptions = {
|
||||
@@ -834,10 +835,28 @@ export const importTenantFullExport = async (
|
||||
...importOrder,
|
||||
...Object.keys(exportData.tables).filter((table) => !importOrder.includes(table)).sort(),
|
||||
].filter((table, index, all) => all.indexOf(table) === index)
|
||||
const specialTables = [
|
||||
columnsByTable.has("bankaccounts") ? "bankaccounts" : null,
|
||||
columnsByTable.has("bankstatements") ? "bankstatements" : null,
|
||||
columnsByTable.has("letterheads") ? "letterheads" : null,
|
||||
].filter(Boolean) as string[]
|
||||
const regularTableNames = tableNames.filter((table) => !specialTables.includes(table))
|
||||
const progressTotal = Math.max(1, specialTables.length + regularTableNames.length + 3)
|
||||
let progressDone = 0
|
||||
const reportProgress = async (message: string) => {
|
||||
await options.onProgress?.({
|
||||
done: Math.min(progressDone, progressTotal),
|
||||
total: progressTotal,
|
||||
message,
|
||||
})
|
||||
}
|
||||
|
||||
await client.query("begin")
|
||||
await client.query("set local session_replication_role = replica")
|
||||
await reportProgress("Dateien werden vorbereitet")
|
||||
const files = await restoreFiles(exportData)
|
||||
progressDone += 1
|
||||
await reportProgress("Dateien vorbereitet")
|
||||
|
||||
const importedTables: { table: string; rows: number }[] = []
|
||||
const bankaccountMetadata = columnsByTable.get("bankaccounts")
|
||||
@@ -845,6 +864,8 @@ export const importTenantFullExport = async (
|
||||
const result = await insertIdentityRowsWithRemap(client, "bankaccounts", exportData.tables.bankaccounts || [], bankaccountMetadata)
|
||||
remapTableColumn(exportData.tables.bankstatements, "account", result.idMap)
|
||||
importedTables.push({ table: "bankaccounts", rows: result.count })
|
||||
progressDone += 1
|
||||
await reportProgress("Bankkonten importiert")
|
||||
}
|
||||
|
||||
const bankstatementMetadata = columnsByTable.get("bankstatements")
|
||||
@@ -853,6 +874,8 @@ export const importTenantFullExport = async (
|
||||
remapTableColumn(exportData.tables.statementallocations, "bs_id", result.idMap)
|
||||
remapTableColumn(exportData.tables.historyitems, "bankstatement", result.idMap)
|
||||
importedTables.push({ table: "bankstatements", rows: result.count })
|
||||
progressDone += 1
|
||||
await reportProgress("Bankauszüge importiert")
|
||||
}
|
||||
|
||||
const letterheadMetadata = columnsByTable.get("letterheads")
|
||||
@@ -860,25 +883,31 @@ export const importTenantFullExport = async (
|
||||
const result = await insertIdentityRowsWithRemap(client, "letterheads", exportData.tables.letterheads || [], letterheadMetadata)
|
||||
remapTableColumn(exportData.tables.createddocuments, "letterhead", result.idMap)
|
||||
importedTables.push({ table: "letterheads", rows: result.count })
|
||||
progressDone += 1
|
||||
await reportProgress("Briefpapiere importiert")
|
||||
}
|
||||
|
||||
for (const table of tableNames) {
|
||||
if (["bankaccounts", "bankstatements", "letterheads"].includes(table)) continue
|
||||
|
||||
for (const table of regularTableNames) {
|
||||
const rows = exportData.tables[table] || []
|
||||
const metadata = columnsByTable.get(table)
|
||||
if (!metadata) continue
|
||||
|
||||
const count = await insertRows(client, table, rows, metadata)
|
||||
importedTables.push({ table, rows: count })
|
||||
progressDone += 1
|
||||
await reportProgress(`${table} importiert`)
|
||||
}
|
||||
|
||||
const cleanedCommunicationRooms = await cleanupImportedCommunicationRooms(client, exportData)
|
||||
if (cleanedCommunicationRooms) {
|
||||
importedTables.push({ table: "communication_rooms_matrix_reset", rows: cleanedCommunicationRooms })
|
||||
}
|
||||
progressDone += 1
|
||||
await reportProgress("Kommunikationsräume bereinigt")
|
||||
|
||||
await refreshSequences(client, columnsByTable)
|
||||
progressDone = progressTotal
|
||||
await reportProgress("Import abgeschlossen")
|
||||
await client.query("commit")
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user