Include global resources in tenant exports
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 39s
Build and Push Docker Images / build-frontend (push) Successful in 25s
Build and Push Docker Images / build-website (push) Successful in 24s
Build and Push Docker Images / build-central-services-api (push) Successful in 24s
Build and Push Docker Images / build-central-services-admin (push) Successful in 25s
Build and Push Docker Images / build-docs (push) Successful in 24s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 39s
Build and Push Docker Images / build-frontend (push) Successful in 25s
Build and Push Docker Images / build-website (push) Successful in 24s
Build and Push Docker Images / build-central-services-api (push) Successful in 24s
Build and Push Docker Images / build-central-services-admin (push) Successful in 25s
Build and Push Docker Images / build-docs (push) Successful in 24s
This commit is contained in:
36
backend/src/utils/tenantExportGlobalResources.ts
Normal file
36
backend/src/utils/tenantExportGlobalResources.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
type TableRows = Record<string, Record<string, any>[]>
|
||||
|
||||
type LoadRows = (
|
||||
table: string,
|
||||
whereSql: string,
|
||||
params?: any[]
|
||||
) => Promise<Record<string, any>[]>
|
||||
|
||||
type AddRows = (
|
||||
tables: TableRows,
|
||||
table: string,
|
||||
rows: Record<string, any>[]
|
||||
) => void
|
||||
|
||||
export const TENANT_EXPORT_GLOBAL_TABLES = ["units", "citys", "countrys"] as const
|
||||
|
||||
export const addTenantExportGlobalResources = async (
|
||||
tables: TableRows,
|
||||
availableTables: ReadonlySet<string>,
|
||||
tenant: Record<string, any>,
|
||||
loadRows: LoadRows,
|
||||
addRows: AddRows
|
||||
) => {
|
||||
for (const table of TENANT_EXPORT_GLOBAL_TABLES) {
|
||||
if (!availableTables.has(table)) continue
|
||||
addRows(tables, table, await loadRows(table, "true"))
|
||||
}
|
||||
|
||||
if (availableTables.has("accounts")) {
|
||||
addRows(
|
||||
tables,
|
||||
"accounts",
|
||||
await loadRows("accounts", `"accountChart" = $1`, [tenant.accountChart || "skr03"])
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { pool } from "../../db"
|
||||
import { s3 } from "./s3"
|
||||
import { secrets } from "./secrets"
|
||||
import { decrypt, encrypt } from "./crypt"
|
||||
import { addTenantExportGlobalResources } from "./tenantExportGlobalResources"
|
||||
import { restoreImportedTenantNumberRanges } from "./tenantImportNumberRanges"
|
||||
|
||||
type TableRows = Record<string, Record<string, any>[]>
|
||||
@@ -300,6 +301,13 @@ export const buildTenantFullExport = async (
|
||||
if (!tenantRows.length) throw new Error("Tenant nicht gefunden")
|
||||
|
||||
addRows(tables, "tenants", tenantRows)
|
||||
await addTenantExportGlobalResources(
|
||||
tables,
|
||||
new Set(columnsByTable.keys()),
|
||||
tenantRows[0],
|
||||
(table, whereSql, params) => loadRows(client, table, whereSql, params),
|
||||
addRows
|
||||
)
|
||||
|
||||
for (const [table, metadata] of columnsByTable.entries()) {
|
||||
if (table === "tenants") continue
|
||||
|
||||
Reference in New Issue
Block a user