don't backfill old rows on AI column creation
This commit is contained in:
parent
2c5fe77740
commit
c1a86433c1
|
@ -163,7 +163,7 @@ export const TypeIconMap = {
|
|||
[FieldType.AI]: "MagicWand",
|
||||
[FieldType.JSON]: "Brackets",
|
||||
[FieldType.BIGINT]: "TagBold",
|
||||
[FieldType.AUTO]: "MagicWand",
|
||||
[FieldType.AUTO]: "Shapes",
|
||||
[FieldType.BB_REFERENCE]: {
|
||||
[BBReferenceFieldSubType.USER]: "UserGroup",
|
||||
[BBReferenceFieldSubType.USERS]: "UserGroup",
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
import { getRowParams } from "../../../db/utils"
|
||||
import {
|
||||
outputProcessing,
|
||||
processAIColumns,
|
||||
} from "../../../utilities/rowProcessor"
|
||||
import { context } from "@budibase/backend-core"
|
||||
import { Table, Row } from "@budibase/types"
|
||||
import isEqual from "lodash/isEqual"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
|
||||
export async function updateAllAIColumnsInTable(table: Table) {
|
||||
const db = context.getAppDB()
|
||||
// start by getting the raw rows (which will be written back to DB after update)
|
||||
let rows = (
|
||||
await db.allDocs<Row>(
|
||||
getRowParams(table._id, null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
).rows.map(row => row.doc!)
|
||||
// now enrich the rows, note the clone so that we have the base state of the
|
||||
// rows so that we don't write any of the enriched information back
|
||||
let enrichedRows = await outputProcessing(table, cloneDeep(rows), {
|
||||
squash: false,
|
||||
})
|
||||
const updatedRows = []
|
||||
for (let row of rows) {
|
||||
// find the enriched row, if found process the formulas
|
||||
const enrichedRow = enrichedRows.find(
|
||||
(enriched: Row) => enriched._id === row._id
|
||||
)
|
||||
if (enrichedRow) {
|
||||
let processed = await processAIColumns(table, cloneDeep(row), {
|
||||
contextRows: [enrichedRow],
|
||||
})
|
||||
// values have changed, need to add to bulk docs to update
|
||||
if (!isEqual(processed, row)) {
|
||||
updatedRows.push(processed)
|
||||
}
|
||||
}
|
||||
}
|
||||
await db.bulkDocs(updatedRows)
|
||||
}
|
|
@ -14,7 +14,6 @@ import {
|
|||
} from "@budibase/types"
|
||||
import sdk from "../../../sdk"
|
||||
import { isRelationshipColumn } from "../../../db/utils"
|
||||
import { updateAllAIColumnsInTable } from "../row/aiColumn"
|
||||
|
||||
function isStaticFormula(
|
||||
column: FieldSchema
|
||||
|
@ -199,21 +198,3 @@ export async function runStaticFormulaChecks(
|
|||
await checkIfFormulaUpdated(table, { oldTable })
|
||||
}
|
||||
}
|
||||
|
||||
export async function runAIColumnChecks(
|
||||
table: Table,
|
||||
{ oldTable }: { oldTable?: Table }
|
||||
) {
|
||||
// look to see if any AI column values have changed
|
||||
const shouldUpdate = Object.values(table.schema).find(
|
||||
column =>
|
||||
column.type === FieldType.AI &&
|
||||
(!oldTable ||
|
||||
!oldTable.schema[column.name] ||
|
||||
!isEqual(oldTable.schema[column.name], column))
|
||||
)
|
||||
// if an AI column has updated, then need to run the update
|
||||
if (shouldUpdate != null) {
|
||||
await updateAllAIColumnsInTable(table)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,6 @@ export async function save(
|
|||
}
|
||||
// has to run after, make sure it has _id
|
||||
await runStaticFormulaChecks(table, { oldTable, deletion: false })
|
||||
// await runAIColumnChecks(table, { oldTable, deletion: false })
|
||||
return { table }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue