1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00

Fixing the issue, making sure if error occurs to re-evaluate.

This commit is contained in:
mike12345567 2024-07-22 15:17:34 +01:00
parent fddfc77ffa
commit 4f05f33b08
2 changed files with 14 additions and 2 deletions

View file

@ -49,6 +49,7 @@ import { dataFilters } from "@budibase/shared-core"
const builder = new sql.Sql(SqlClient.SQL_LITE)
const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`)
const MISSING_TABLE_REGX = new RegExp(`no such table: .+`)
const DUPLICATE_COLUMN_REGEX = new RegExp(`duplicate column name: .+`)
function buildInternalFieldList(
table: Table,
@ -237,9 +238,11 @@ function resyncDefinitionsRequired(status: number, message: string) {
// pre data_ prefix on column names, need to resync
return (
// there are tables missing - try a resync
(status === 400 && message.match(MISSING_TABLE_REGX)) ||
(status === 400 && message?.match(MISSING_TABLE_REGX)) ||
// there are columns missing - try a resync
(status === 400 && message.match(MISSING_COLUMN_REGEX)) ||
(status === 400 && message?.match(MISSING_COLUMN_REGEX)) ||
// duplicate column name in definitions - need to re-run definition sync
(status === 400 && message?.match(DUPLICATE_COLUMN_REGEX)) ||
// no design document found, needs a full sync
(status === 404 && message?.includes(SQLITE_DESIGN_DOC_ID))
)

View file

@ -94,6 +94,9 @@ export function mapToUserColumn(key: string) {
function mapTable(table: Table): SQLiteTables {
const tables: SQLiteTables = {}
const fields: Record<string, { field: string; type: SQLiteType }> = {}
// a list to make sure no duplicates - the fields are mapped by SQS with case sensitivity
// but need to make sure there are no duplicate columns
const usedColumns: string[] = []
for (let [key, column] of Object.entries(table.schema)) {
// relationships should be handled differently
if (column.type === FieldType.LINK) {
@ -106,6 +109,12 @@ function mapTable(table: Table): SQLiteTables {
if (!FieldTypeMap[column.type]) {
throw new Error(`Unable to map type "${column.type}" to SQLite type`)
}
const lcKey = key.toLowerCase()
// ignore duplicates
if (usedColumns.includes(lcKey)) {
continue
}
usedColumns.push(lcKey)
fields[mapToUserColumn(key)] = {
field: key,
type: FieldTypeMap[column.type],