From 23b7a8de72b7637520359eaa8494a727078549f1 Mon Sep 17 00:00:00 2001
From: melohagan <101575380+melohagan@users.noreply.github.com>
Date: Fri, 6 Oct 2023 14:17:36 +0100
Subject: [PATCH 1/2] Allow relationship to be deleted even if missing (#11991)
* Allow relationship to be deleted even if missing
* Comment
---
.../server/src/db/linkedRows/LinkController.ts | 17 ++++++++++++-----
.../server/src/db/tests/linkController.spec.js | 15 +++++++++++++++
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/packages/server/src/db/linkedRows/LinkController.ts b/packages/server/src/db/linkedRows/LinkController.ts
index 5bfae49e8b..457819251a 100644
--- a/packages/server/src/db/linkedRows/LinkController.ts
+++ b/packages/server/src/db/linkedRows/LinkController.ts
@@ -308,12 +308,19 @@ class LinkController {
}
})
)
- // remove schema from other table
- let linkedTable = await this._db.get
(field.tableId)
- if (field.fieldName) {
- delete linkedTable.schema[field.fieldName]
+ try {
+ // remove schema from other table, if it exists
+ let linkedTable = await this._db.get(field.tableId)
+ if (field.fieldName) {
+ delete linkedTable.schema[field.fieldName]
+ }
+ await this._db.put(linkedTable)
+ } catch (error: any) {
+ // ignore missing to ensure broken relationship columns can be deleted
+ if (error.statusCode !== 404) {
+ throw error
+ }
}
- await this._db.put(linkedTable)
}
/**
diff --git a/packages/server/src/db/tests/linkController.spec.js b/packages/server/src/db/tests/linkController.spec.js
index 59d0f3f983..5caf35f61a 100644
--- a/packages/server/src/db/tests/linkController.spec.js
+++ b/packages/server/src/db/tests/linkController.spec.js
@@ -233,4 +233,19 @@ describe("test the link controller", () => {
}
await config.updateTable(table)
})
+
+ it("should be able to remove a linked field from a table, even if the linked table does not exist", async () => {
+ await createLinkedRow()
+ await createLinkedRow("link2")
+ table1.schema["link"].tableId = "not_found"
+ const controller = await createLinkController(table1, null, table1)
+ await context.doInAppContext(appId, async () => {
+ let before = await controller.getTableLinkDocs()
+ await controller.removeFieldFromTable("link")
+ let after = await controller.getTableLinkDocs()
+ expect(before.length).toEqual(2)
+ // shouldn't delete the other field
+ expect(after.length).toEqual(1)
+ })
+ })
})
From 9b52ae56282adcf1651fae4b693b679f5d6701fa Mon Sep 17 00:00:00 2001
From: Budibase Staging Release Bot <>
Date: Fri, 6 Oct 2023 13:17:58 +0000
Subject: [PATCH 2/2] Bump version to 2.11.13
---
lerna.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lerna.json b/lerna.json
index 6270454faa..f42284a20d 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "2.11.12",
+ "version": "2.11.13",
"npmClient": "yarn",
"packages": [
"packages/*"