Browse Source

feat: populate system columns for created/updated

pull/7304/head
Pranav C 11 months ago
parent
commit
0007251dbb
  1. 8
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 19
      packages/nocodb/src/services/columns.service.ts

8
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]) {

19
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,

Loading…
Cancel
Save