diff --git a/packages/server/src/api/controllers/row/internal.ts b/packages/server/src/api/controllers/row/internal.ts index cc1450060c..e3cb419236 100644 --- a/packages/server/src/api/controllers/row/internal.ts +++ b/packages/server/src/api/controllers/row/internal.ts @@ -118,8 +118,11 @@ export async function patch(ctx: UserCtx) { combinedRow[key] = inputs[key] } + // need to copy the table so it can be differenced on way out + const tableClone = cloneDeep(dbTable) + // this returns the table and row incase they have been updated - let { table, row } = inputProcessing(ctx.user, dbTable, combinedRow) + let { table, row } = inputProcessing(ctx.user, tableClone, combinedRow) const validateResult = await utils.validate({ row, table, @@ -163,7 +166,12 @@ export async function save(ctx: UserCtx) { // this returns the table and row incase they have been updated const dbTable = await db.get(inputs.tableId) - let { table, row } = inputProcessing(ctx.user, dbTable, inputs) + + // need to copy the table so it can be differenced on way out + const tableClone = cloneDeep(dbTable) + + let { table, row } = inputProcessing(ctx.user, tableClone, inputs) + const validateResult = await utils.validate({ row, table, diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index 105dd21ae0..a8041dac3b 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -79,6 +79,60 @@ describe("/rows", () => { await assertQueryUsage(queryUsage + 1) }) + it("Increment row autoId per create row request", async () => { + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + + const newTable = await config.createTable({ + name: "TestTableAuto", + type: "table", + key: "name", + schema: { + ...table.schema, + "Row ID": { + name: "Row ID", + type: "number", + subtype: "autoID", + icon: "ri-magic-line", + autocolumn: true, + constraints: { + type: "number", + presence: false, + numericality: { + greaterThanOrEqualTo: "", + lessThanOrEqualTo: "", + }, + }, + }, + } + }) + + const ids = [1,2,3] + + // Performing several create row requests should increment the autoID fields accordingly + const createRow = async (id) => { + const res = await request + .post(`/api/${newTable._id}/rows`) + .send({ + name: "row_" + id + }) + .set(config.defaultHeaders()) + .expect('Content-Type', /json/) + .expect(200) + expect(res.res.statusMessage).toEqual(`${newTable.name} saved successfully`) + expect(res.body.name).toEqual("row_" + id) + expect(res.body._rev).toBeDefined() + expect(res.body["Row ID"]).toEqual(id) + } + + for (let i=0; i { const existing = await config.createRow() const rowUsage = await getRowUsage()