diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index e96136e6d6..25837c2008 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5600,10 +5600,14 @@ class BaseModelSqlv2 { model?: Model; knex?: XKnex; }) { - const columnName = 'updated_at'; + const columnName = await model.getColumns().then((columns) => { + return columns.find((c) => c.uidt === UITypes.LastModifiedTime)?.column_name; + }); + + if(!columnName) return; const qb = knex(model.table_name).update({ - [columnName]: this.dbDriver.fn.now(), + [columnName]: Noco.ncMeta.now(), }); for (const rowId of Array.isArray(rowIds) ? rowIds : [rowIds]) { diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 7836078e44..e1c45a84e3 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -1692,10 +1692,10 @@ export class ColumnsService { // else create a new column in meta and db const existingColumn = await table.getColumns().then((col) => { return col.find( - (c) => - c.uidt === colBody.uidt || - c.column_name === - (c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'), + (c) => c.uidt === colBody.uidt && c.system, + // || + // c.column_name === + // (c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'), ); }); @@ -1741,6 +1741,17 @@ export class ColumnsService { await sqlMgr.sqlOpPlus(source, 'tableUpdate', tableUpdateBody); } + const title = getUniqueColumnAliasName( + table.columns, + UITypes.CreateTime ? 'CreatedAt' : 'UpdatedAt', + ); + + await Column.insert({ + ...colBody, + title, + system: 1, + fk_model_id: table.id, + }); await Column.insert({ ...colBody, fk_model_id: table.id,