Skip to content

Commit

Permalink
Allowing incorrectly setup column schemas to still function as part o…
Browse files Browse the repository at this point in the history
…f search - requires further investigation as to how this happens, but search should still work.
  • Loading branch information
mike12345567 committed Aug 7, 2024
1 parent d03915d commit 9733ba5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/server/src/api/controllers/row/utils/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export function basicProcessing({
}): Row {
const thisRow: Row = {}
// filter the row down to what is actually the row (not joined)
for (let field of Object.values(table.schema)) {
const fieldName = field.name
for (let fieldName of Object.keys(table.schema)) {
let value = extractFieldValue({
row,
tableName: table.name,
Expand Down
29 changes: 29 additions & 0 deletions packages/server/src/api/routes/tests/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,35 @@ describe.each([
})
})

describe("Invalid column definitions", () => {
beforeAll(async () => {
// need to create an invalid table - means ignoring typescript
table = await createTable({
// @ts-ignore
invalid: {
type: FieldType.STRING,
},
name: {
name: "name",
type: FieldType.STRING,
},
})
await createRows([
{ name: "foo", invalid: "id1" },
{ name: "bar", invalid: "id2" },
])
})

it("can get rows with all table data", async () => {
await expectSearch({
query: {},
}).toContain([
{ name: "foo", invalid: "id1" },
{ name: "bar", invalid: "id2" },
])
})
})

describe.each(["data_name_test", "name_data_test", "name_test_data_"])(
"special (%s) case",
column => {
Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/integrations/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { helpers, utils } from "@budibase/shared-core"
import { pipeline } from "stream/promises"
import tmp from "tmp"
import fs from "fs"
import { merge } from "lodash"

type PrimitiveTypes =
| FieldType.STRING
Expand Down Expand Up @@ -291,10 +292,12 @@ function copyExistingPropsOver(
const fetchedColumnDefinition: FieldSchema | undefined =
table.schema[key]
table.schema[key] = {
...existingTableSchema[key],
// merge the properties - anything missing will be filled in, old definition preferred
...merge(fetchedColumnDefinition, existingTableSchema[key]),
// always take externalType and autocolumn from the fetched definition
externalType:
existingTableSchema[key].externalType ||
table.schema[key]?.externalType,
fetchedColumnDefinition?.externalType,
autocolumn: fetchedColumnDefinition?.autocolumn,
} as FieldSchema
// check constraints which can be fetched from the DB (they could be updated)
Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/sdk/app/rows/search/internal/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ function buildInternalFieldList(
fieldList = fieldList.concat(
PROTECTED_INTERNAL_COLUMNS.map(col => `${table._id}.${col}`)
)
for (let col of Object.values(table.schema)) {
for (let key of Object.keys(table.schema)) {
const col = table.schema[key]
const isRelationship = col.type === FieldType.LINK
if (!opts?.relationships && isRelationship) {
continue
}
if (!isRelationship) {
fieldList.push(`${table._id}.${mapToUserColumn(col.name)}`)
fieldList.push(`${table._id}.${mapToUserColumn(key)}`)
} else {
const linkCol = col as RelationshipFieldMetadata
const relatedTable = tables.find(table => table._id === linkCol.tableId)
Expand Down

0 comments on commit 9733ba5

Please sign in to comment.