don't backfill old rows on AI column creation

This commit is contained in:
Martin McKeaveney 2024-10-02 16:49:04 +01:00
parent 2c5fe77740
commit c1a86433c1
4 changed files with 1 additions and 64 deletions

View File

@ -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",

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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 }
}