From b05f56222e87adf4d8687466dc64ac71903fddce Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 19 Apr 2024 13:13:12 +0200 Subject: [PATCH] Fix tests --- .../server/src/sdk/app/tables/tests/validation.spec.ts | 4 ++-- packages/server/src/sdk/app/tables/validation.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/server/src/sdk/app/tables/tests/validation.spec.ts b/packages/server/src/sdk/app/tables/tests/validation.spec.ts index 66b4222005..6f8efbaed1 100644 --- a/packages/server/src/sdk/app/tables/tests/validation.spec.ts +++ b/packages/server/src/sdk/app/tables/tests/validation.spec.ts @@ -125,7 +125,7 @@ describe("validation and update of external table schemas", () => { } it("should correctly set utilised foreign keys to autocolumns", () => { - const response = populateExternalTableSchemas(cloneDeep(SCHEMA) as any) + const response = populateExternalTableSchemas(cloneDeep(SCHEMA)) const foreignKey = getForeignKeyColumn(response) expect(foreignKey.autocolumn).toBe(true) expect(foreignKey.autoReason).toBe(AutoReason.FOREIGN_KEY) @@ -133,7 +133,7 @@ describe("validation and update of external table schemas", () => { }) it("should correctly unset foreign keys when no longer used", () => { - const setResponse = populateExternalTableSchemas(cloneDeep(SCHEMA) as any) + const setResponse = populateExternalTableSchemas(cloneDeep(SCHEMA)) const beforeFk = getForeignKeyColumn(setResponse) delete setResponse.entities!.client.schema.project delete setResponse.entities!.project.schema.client diff --git a/packages/server/src/sdk/app/tables/validation.ts b/packages/server/src/sdk/app/tables/validation.ts index 26e1cc8ef2..d71a156fdb 100644 --- a/packages/server/src/sdk/app/tables/validation.ts +++ b/packages/server/src/sdk/app/tables/validation.ts @@ -40,14 +40,14 @@ function checkForeignKeysAreAutoColumns(datasource: Datasource) { const shouldBeForeign = foreignKeys.find( options => options.tableId === table._id && options.key === column.name ) - if (column.autocolumn) { - continue - } // don't change already auto-columns to it, e.g. primary keys that are foreign - if (shouldBeForeign) { + if (shouldBeForeign && !column.autocolumn) { column.autocolumn = true column.autoReason = AutoReason.FOREIGN_KEY - } else if (column.autoReason === AutoReason.FOREIGN_KEY) { + } else if ( + !shouldBeForeign && + column.autoReason === AutoReason.FOREIGN_KEY + ) { delete column.autocolumn delete column.autoReason }