KI-AGENT: Überspringe generierte Spalten beim Mandantenimport
This commit is contained in:
@@ -9,6 +9,7 @@ type TableRows = Record<string, Record<string, any>[]>
|
|||||||
type TableMetadata = {
|
type TableMetadata = {
|
||||||
columns: string[]
|
columns: string[]
|
||||||
jsonColumns: Set<string>
|
jsonColumns: Set<string>
|
||||||
|
generatedColumns: Set<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TenantFullExport = {
|
export type TenantFullExport = {
|
||||||
@@ -37,7 +38,7 @@ const quoteIdent = (value: string) => `"${value.replace(/"/g, '""')}"`
|
|||||||
|
|
||||||
const tableColumns = async (client: any) => {
|
const tableColumns = async (client: any) => {
|
||||||
const result = await client.query(`
|
const result = await client.query(`
|
||||||
select table_name, column_name, data_type
|
select table_name, column_name, data_type, is_generated
|
||||||
from information_schema.columns
|
from information_schema.columns
|
||||||
where table_schema = 'public'
|
where table_schema = 'public'
|
||||||
order by table_name, ordinal_position
|
order by table_name, ordinal_position
|
||||||
@@ -48,12 +49,16 @@ const tableColumns = async (client: any) => {
|
|||||||
const metadata = columnsByTable.get(row.table_name) || {
|
const metadata = columnsByTable.get(row.table_name) || {
|
||||||
columns: [],
|
columns: [],
|
||||||
jsonColumns: new Set<string>(),
|
jsonColumns: new Set<string>(),
|
||||||
|
generatedColumns: new Set<string>(),
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata.columns.push(row.column_name)
|
metadata.columns.push(row.column_name)
|
||||||
if (row.data_type === "json" || row.data_type === "jsonb") {
|
if (row.data_type === "json" || row.data_type === "jsonb") {
|
||||||
metadata.jsonColumns.add(row.column_name)
|
metadata.jsonColumns.add(row.column_name)
|
||||||
}
|
}
|
||||||
|
if (row.is_generated === "ALWAYS") {
|
||||||
|
metadata.generatedColumns.add(row.column_name)
|
||||||
|
}
|
||||||
|
|
||||||
columnsByTable.set(row.table_name, metadata)
|
columnsByTable.set(row.table_name, metadata)
|
||||||
}
|
}
|
||||||
@@ -220,7 +225,7 @@ const insertRows = async (client: any, table: string, rows: Record<string, any>[
|
|||||||
if (!rows.length) return 0
|
if (!rows.length) return 0
|
||||||
|
|
||||||
let inserted = 0
|
let inserted = 0
|
||||||
const availableColumns = new Set(metadata.columns)
|
const availableColumns = new Set(metadata.columns.filter((column) => !metadata.generatedColumns.has(column)))
|
||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const rowColumns = Object.keys(row).filter((column) => availableColumns.has(column))
|
const rowColumns = Object.keys(row).filter((column) => availableColumns.has(column))
|
||||||
|
|||||||
Reference in New Issue
Block a user