mirror of
https://github.com/wekan/wekan.git
synced 2025-12-29 21:58:49 +01:00
Fixes #2596 incorrect date types for created & updated
This commit is contained in:
parent
2c78aab3dc
commit
3b9f2ca7c2
22 changed files with 103 additions and 33 deletions
|
|
@ -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),
|
||||
},
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue