From 674a402b37b25408c9e47a4249f828bc27d137eb Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 4 Jan 2024 13:19:18 +0000 Subject: [PATCH] feat: `CreateTime` or `LastModifiedTime` - update column - WIP --- .../nocodb/src/services/columns.service.ts | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index cf6af2e3f8..6264829b1f 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -292,6 +292,41 @@ export class ColumnsService { NcError.notImplemented( `Updating ${colBody.uidt} => ${colBody.uidt} is not implemented`, ); + } else if ( + [UITypes.CreateTime, UITypes.LastModifiedTime].includes(colBody.uidt) + ) { + // todo: correct this + const existingColumn = await table.getColumns().then((col) => { + return col.find((c) => c.uidt === colBody.uidt); + }); + + if (!existingColumn) { + const sqlClient = await reuseOrSave('sqlClient', reuse, async () => + NcConnectionMgrv2.getSqlClient(source), + ); + const dbColumns = ( + await sqlClient.columnList({ + tn: table.table_name, + schema: source.getConfig()?.schema, + }) + )?.data?.list; + + // todo: check type as well + const dbColumn = dbColumns.find( + (c) => + c.column_name === + (c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'), + ); + + if (!dbColumn) { + // create column in db + } + + await Column.insert({ + ...colBody, + fk_model_id: table.id, + }); + } } else if ( [UITypes.SingleSelect, UITypes.MultiSelect].includes(colBody.uidt) ) { @@ -2151,10 +2186,11 @@ export class ColumnsService { // on delete create time or last modified time, keep the column in table and delete the column from meta case UITypes.CreateTime: - case UITypes.LastModifiedTime: { - await Column.delete(param.columnId, ncMeta); - } - break; + case UITypes.LastModifiedTime: + { + await Column.delete(param.columnId, ncMeta); + } + break; default: { const tableUpdateBody = { ...table,