Browse Source

feat: `CreateTime` or `LastModifiedTime` - update column - WIP

pull/7304/head
Pranav C 9 months ago
parent
commit
674a402b37
  1. 44
      packages/nocodb/src/services/columns.service.ts

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

Loading…
Cancel
Save