Fix for foreign keys being unsettlable after update, breaking Postgres test.

This commit is contained in:
mike12345567 2023-06-26 15:05:10 +01:00
parent e022da5bc8
commit 1c09913d33
3 changed files with 16 additions and 5 deletions

View File

@ -30,6 +30,7 @@ import { cloneDeep } from "lodash/fp"
import { processDates, processFormulas } from "../../../utilities/rowProcessor" import { processDates, processFormulas } from "../../../utilities/rowProcessor"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { isEditableColumn } from "../../../sdk/app/tables/validation"
export interface ManyRelationship { export interface ManyRelationship {
tableId?: string tableId?: string
@ -298,8 +299,7 @@ export class ExternalRequest {
if ( if (
row[key] == null || row[key] == null ||
newRow[key] || newRow[key] ||
field.autocolumn || !sdk.tables.isEditableColumn(field)
field.type === FieldTypes.FORMULA
) { ) {
continue continue
} }

View File

@ -7,7 +7,7 @@ import {
} from "../../../integrations/utils" } from "../../../integrations/utils"
import { Table, Database } from "@budibase/types" import { Table, Database } from "@budibase/types"
import datasources from "../datasources" import datasources from "../datasources"
import { checkExternalTableSchemas } from "./validation" import { checkExternalTableSchemas, isEditableColumn } from "./validation"
async function getAllInternalTables(db?: Database): Promise<Table[]> { async function getAllInternalTables(db?: Database): Promise<Table[]> {
if (!db) { if (!db) {
@ -62,4 +62,5 @@ export default {
getExternalTable, getExternalTable,
getTable, getTable,
checkExternalTableSchemas, checkExternalTableSchemas,
isEditableColumn,
} }

View File

@ -1,9 +1,11 @@
import { import {
AutoReason,
Datasource, Datasource,
FieldSchema,
FieldType, FieldType,
RelationshipTypes, RelationshipTypes,
AutoReason,
} from "@budibase/types" } from "@budibase/types"
import { FieldTypes } from "../../../constants"
function checkForeignKeysAreAutoColumns(datasource: Datasource) { function checkForeignKeysAreAutoColumns(datasource: Datasource) {
if (!datasource.entities) { if (!datasource.entities) {
@ -39,7 +41,8 @@ function checkForeignKeysAreAutoColumns(datasource: Datasource) {
const shouldBeForeign = foreignKeys.find( const shouldBeForeign = foreignKeys.find(
options => options.tableId === table._id && options.key === column.name 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.autocolumn = true
column.autoReason = AutoReason.FOREIGN_KEY column.autoReason = AutoReason.FOREIGN_KEY
} else if (column.autoReason === AutoReason.FOREIGN_KEY) { } else if (column.autoReason === AutoReason.FOREIGN_KEY) {
@ -52,6 +55,13 @@ function checkForeignKeysAreAutoColumns(datasource: Datasource) {
return 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) { export function checkExternalTableSchemas(datasource: Datasource) {
return checkForeignKeysAreAutoColumns(datasource) return checkForeignKeysAreAutoColumns(datasource)
} }