Browse Source

fix(nocodb): skip null datetime and add more comments

pull/5642/head
Wing-Kam Wong 2 years ago
parent
commit
636e4f64fe
  1. 9
      packages/nocodb/src/version-upgrader/ncDateTimeUpgrader.ts

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

@ -76,7 +76,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
continue; continue;
} }
// for normal date time fields
const updateRecords = []; const updateRecords = [];
// for fields with auto update (e.g. updated_at)
const updatedAtRecords = []; const updatedAtRecords = [];
// get all date times columns // get all date times columns
@ -121,6 +123,10 @@ 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) {
if (!record[dateTimeColumn.column_name]) {
// skip null case
continue;
}
const action = knex(getTnPath(knex, model)) const action = knex(getTnPath(knex, model))
.update({ .update({
[dateTimeColumn.column_name]: dayjs( [dateTimeColumn.column_name]: dayjs(
@ -144,7 +150,10 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
} }
} }
} }
// update those general date time fields first
await Promise.all(updateRecords); await Promise.all(updateRecords);
// updated_at will be modified due to above change
// update those right here
await Promise.all(updatedAtRecords); await Promise.all(updatedAtRecords);
} catch (e) { } catch (e) {
// ignore the error related to deleted project // ignore the error related to deleted project

Loading…
Cancel
Save