diff options
author | Justin Reynolds <justinr1234@gmail.com> | 2019-09-05 12:29:45 -0500 |
---|---|---|
committer | Justin Reynolds <justinr1234@gmail.com> | 2019-09-05 12:29:45 -0500 |
commit | 3b9f2ca7c2fffa230bb0c6d4254a88deb9fbb023 (patch) | |
tree | 356ab6f5693852464bdb975934c53f63445e6d5f /server | |
parent | 2c78aab3dc91ee276bfb5e4717ada72dc84ca3b0 (diff) | |
download | wekan-3b9f2ca7c2fffa230bb0c6d4254a88deb9fbb023.tar.gz wekan-3b9f2ca7c2fffa230bb0c6d4254a88deb9fbb023.tar.bz2 wekan-3b9f2ca7c2fffa230bb0c6d4254a88deb9fbb023.zip |
Fixes #2596 incorrect date types for created & updated
Diffstat (limited to 'server')
-rw-r--r-- | server/migrations.js | 74 |
1 files changed, 41 insertions, 33 deletions
diff --git a/server/migrations.js b/server/migrations.js index f3776edd..836220f3 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -684,39 +684,6 @@ Migrations.add('mutate-boardIds-in-customfields', () => { }); }); -const firstBatchOfDbsToAddCreatedAndUpdated = [ - AccountSettings, - Actions, - Activities, - Announcements, - Boards, - CardComments, - Cards, - ChecklistItems, - Checklists, - CustomFields, - Integrations, - InvitationCodes, - Lists, - Rules, - Settings, - Swimlanes, - Triggers, - UnsavedEdits, -]; - -firstBatchOfDbsToAddCreatedAndUpdated.forEach(db => { - db.before.insert((userId, doc) => { - doc.createdAt = Date.now(); - doc.updatedAt = doc.createdAt; - }); - - db.before.update((userId, doc, fieldNames, modifier) => { - modifier.$set = modifier.$set || {}; - modifier.$set.updatedAt = new Date(); - }); -}); - const modifiedAtTables = [ AccountSettings, Actions, @@ -769,3 +736,44 @@ Migrations.add('add-missing-created-and-modified', () => { console.error(e); }); }); + +Migrations.add('fix-incorrect-dates', () => { + const tables = [ + AccountSettings, + Actions, + Activities, + Announcements, + Boards, + CardComments, + Cards, + ChecklistItems, + Checklists, + CustomFields, + Integrations, + InvitationCodes, + Lists, + Rules, + Settings, + Swimlanes, + Triggers, + UnsavedEdits, + ]; + + // Dates were previously created with Date.now() which is a number, not a date + tables.forEach(t => + t + .rawCollection() + .find({ $or: [{ createdAt: { $type: 1 } }, { updatedAt: { $type: 1 } }] }) + .forEach(({ _id, createdAt, updatedAt }) => { + t.rawCollection().update( + { _id }, + { + $set: { + createdAt: new Date(createdAt), + updatedAt: new Date(updatedAt), + }, + }, + ); + }), + ); +}); |