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. 42
      packages/nocodb/src/version-upgrader/ncDateTimeUpgrader.ts

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

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

Loading…
Cancel
Save