Fix for foreign keys being unsettlable after update, breaking Postgres test.
This commit is contained in:
parent
e022da5bc8
commit
1c09913d33
|
@ -30,6 +30,7 @@ import { cloneDeep } from "lodash/fp"
|
|||
import { processDates, processFormulas } from "../../../utilities/rowProcessor"
|
||||
import { db as dbCore } from "@budibase/backend-core"
|
||||
import sdk from "../../../sdk"
|
||||
import { isEditableColumn } from "../../../sdk/app/tables/validation"
|
||||
|
||||
export interface ManyRelationship {
|
||||
tableId?: string
|
||||
|
@ -298,8 +299,7 @@ export class ExternalRequest {
|
|||
if (
|
||||
row[key] == null ||
|
||||
newRow[key] ||
|
||||
field.autocolumn ||
|
||||
field.type === FieldTypes.FORMULA
|
||||
!sdk.tables.isEditableColumn(field)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from "../../../integrations/utils"
|
||||
import { Table, Database } from "@budibase/types"
|
||||
import datasources from "../datasources"
|
||||
import { checkExternalTableSchemas } from "./validation"
|
||||
import { checkExternalTableSchemas, isEditableColumn } from "./validation"
|
||||
|
||||
async function getAllInternalTables(db?: Database): Promise<Table[]> {
|
||||
if (!db) {
|
||||
|
@ -62,4 +62,5 @@ export default {
|
|||
getExternalTable,
|
||||
getTable,
|
||||
checkExternalTableSchemas,
|
||||
isEditableColumn,
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import {
|
||||
AutoReason,
|
||||
Datasource,
|
||||
FieldSchema,
|
||||
FieldType,
|
||||
RelationshipTypes,
|
||||
AutoReason,
|
||||
} from "@budibase/types"
|
||||
import { FieldTypes } from "../../../constants"
|
||||
|
||||
function checkForeignKeysAreAutoColumns(datasource: Datasource) {
|
||||
if (!datasource.entities) {
|
||||
|
@ -39,7 +41,8 @@ function checkForeignKeysAreAutoColumns(datasource: Datasource) {
|
|||
const shouldBeForeign = foreignKeys.find(
|
||||
options => options.tableId === table._id && options.key === column.name
|
||||
)
|
||||
if (shouldBeForeign) {
|
||||
// don't change already auto-columns to it, e.g. primary keys that are foreign
|
||||
if (shouldBeForeign && !column.autocolumn) {
|
||||
column.autocolumn = true
|
||||
column.autoReason = AutoReason.FOREIGN_KEY
|
||||
} else if (column.autoReason === AutoReason.FOREIGN_KEY) {
|
||||
|
@ -52,6 +55,13 @@ function checkForeignKeysAreAutoColumns(datasource: Datasource) {
|
|||
return datasource
|
||||
}
|
||||
|
||||
export function isEditableColumn(column: FieldSchema) {
|
||||
const isAutoColumn =
|
||||
column.autocolumn && column.autoReason !== AutoReason.FOREIGN_KEY
|
||||
const isFormula = column.type === FieldTypes.FORMULA
|
||||
return !(isAutoColumn || isFormula)
|
||||
}
|
||||
|
||||
export function checkExternalTableSchemas(datasource: Datasource) {
|
||||
return checkForeignKeysAreAutoColumns(datasource)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue