From 6105f747c0f285924dd93630296b1bee75463fe5 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 4 Jan 2024 13:19:19 +0000 Subject: [PATCH] feat: create column if missing in table(created/updated time) --- .../nocodb/src/services/columns.service.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 59ec3b4f62..9453dd257b 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -1720,7 +1720,30 @@ export class ColumnsService { if (!dbColumn) { // create column in db - const column = sqlClient; + const tableUpdateBody = { + ...table, + tn: table.table_name, + originalColumns: table.columns.map((c) => ({ + ...c, + cn: c.column_name, + })), + columns: [ + ...table.columns.map((c) => ({ ...c, cn: c.column_name })), + { + ...colBody, + cn: UITypes.CreateTime ? 'created_at' : 'updated_at', + altered: Altered.NEW_COLUMN, + }, + ], + }; + + const sqlClient = await reuseOrSave('sqlClient', reuse, async () => + NcConnectionMgrv2.getSqlClient(source), + ); + const sqlMgr = await reuseOrSave('sqlMgr', reuse, async () => + ProjectMgrv2.getSqlMgr({ id: source.base_id }), + ); + await sqlMgr.sqlOpPlus(source, 'tableUpdate', tableUpdateBody); } await Column.insert({