From c72ca658b9b949442ec0b0980a125e91ae63f486 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 1 Nov 2024 14:30:14 +0000 Subject: [PATCH 1/2] Fixing an issue with sample data being added to an app due to the changes to bulk import. --- .../server/src/api/controllers/table/utils.ts | 7 +++---- .../src/api/routes/tests/application.spec.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 743cce410b..4ea11c7043 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -123,7 +123,7 @@ export async function importToRows( data: Row[], table: Table, userId?: string, - opts?: { keepCouchId: boolean } + opts?: { keepCouchId?: boolean; allowRelationships?: boolean } ) { const originalTable = table const finalData: Row[] = [] @@ -136,16 +136,15 @@ export async function importToRows( // We use a reference to table here and update it after input processing, // so that we can auto increment auto IDs in imported data properly - const processed = await inputProcessing(userId, table, row, { + row = await inputProcessing(userId, table, row, { noAutoRelationships: true, }) - row = processed // However here we must reference the original table, as we want to mutate // the real schema of the table passed in, not the clone used for // incrementing auto IDs for (const [fieldName, schema] of Object.entries(originalTable.schema)) { - if (schema.type === FieldType.LINK) { + if (schema.type === FieldType.LINK && data.find(row => row[fieldName])) { throw new HTTPError( `Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`, 400 diff --git a/packages/server/src/api/routes/tests/application.spec.ts b/packages/server/src/api/routes/tests/application.spec.ts index 729f899379..6d85cdbda9 100644 --- a/packages/server/src/api/routes/tests/application.spec.ts +++ b/packages/server/src/api/routes/tests/application.spec.ts @@ -1,3 +1,5 @@ +import { DEFAULT_TABLES } from "../../../db/defaultData/datasource_bb_default" + jest.mock("../../../utilities/redis", () => ({ init: jest.fn(), getLocksById: () => { @@ -447,4 +449,18 @@ describe("/applications", () => { expect(devLogs.data.length).toBe(0) }) }) + + describe("POST /api/applications/:appId/sample", () => { + it("should be able to add sample data", async () => { + await config.api.application.addSampleData(config.getAppId()) + for (let table of DEFAULT_TABLES) { + const res = await config.api.row.search( + table._id!, + { query: {} }, + { status: 200 } + ) + expect(res.rows.length).not.toEqual(0) + } + }) + }) }) From 23f2df938e2583770d1909a4affaa36139907a14 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 1 Nov 2024 14:31:33 +0000 Subject: [PATCH 2/2] Removing un-necessary statement. --- packages/server/src/api/controllers/table/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 4ea11c7043..04e77fbe62 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -123,7 +123,7 @@ export async function importToRows( data: Row[], table: Table, userId?: string, - opts?: { keepCouchId?: boolean; allowRelationships?: boolean } + opts?: { keepCouchId: boolean } ) { const originalTable = table const finalData: Row[] = []