Browse Source

fix(nocodb): handle CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP case

pull/5642/head
Wing-Kam Wong 2 years ago
parent
commit
48868740f7
  1. 26
      packages/nocodb/src/version-upgrader/ncDateTimeUpgrader.ts

26
packages/nocodb/src/version-upgrader/ncDateTimeUpgrader.ts

@ -77,6 +77,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
}
const updateRecords = [];
const updatedAtRecords = [];
// get all date times columns
// and filter out the columns that are missing in database
@ -98,9 +99,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
return filteredColumns;
});
const dateTimeColumns = columns
.filter((c) => c.uidt === UITypes.DateTime)
.map((c) => c.column_name);
const dateTimeColumns = columns.filter(
(c) => c.uidt === UITypes.DateTime,
);
if (dateTimeColumns.length === 0) {
continue;
@ -120,10 +121,11 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
.reduce((acc, val) => Object.assign(acc, val), {});
for (const dateTimeColumn of dateTimeColumns) {
updateRecords.push(
await knex(getTnPath(knex, model))
const action = knex(getTnPath(knex, model))
.update({
[dateTimeColumn]: dayjs(record[dateTimeColumn])
[dateTimeColumn.column_name]: dayjs(
record[dateTimeColumn.column_name],
)
.utc()
.format(
knex.clientType().startsWith('mysql')
@ -131,11 +133,19 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
: 'YYYY-MM-DD HH:mm:ssZ',
),
})
.where(where),
);
.where(where);
if (
dateTimeColumn.cdf ===
'CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'
) {
updatedAtRecords.push(action);
} else {
updateRecords.push(action);
}
}
}
await Promise.all(updateRecords);
await Promise.all(updatedAtRecords);
} catch (e) {
// ignore the error related to deleted project
if (!isProjectDeleted) {

Loading…
Cancel
Save