summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-05-13 14:50:03 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-05-13 14:50:03 +0200
commita70ce65c52c3533a7fc828fb55a72e5c82b70949 (patch)
tree43d575abe639aa3f6dc912e2ee953a41e74be365
parent2cc820632b3db3f8c0e028aa0f8b6d68854c7fc0 (diff)
downloadwekan-a70ce65c52c3533a7fc828fb55a72e5c82b70949.tar.gz
wekan-a70ce65c52c3533a7fc828fb55a72e5c82b70949.tar.bz2
wekan-a70ce65c52c3533a7fc828fb55a72e5c82b70949.zip
Don't validate migration functions against the current schema
-rw-r--r--server/migrations.js31
1 files changed, 19 insertions, 12 deletions
diff --git a/server/migrations.js b/server/migrations.js
index d7ff5b53..ce4724cc 100644
--- a/server/migrations.js
+++ b/server/migrations.js
@@ -4,6 +4,16 @@
//
// Migrations.add(name, migrationCallback, optionalOrder);
+// In the context of migration functions we don't want to validate database
+// mutation queries against the current (ie, latest) collection schema. Doing
+// that would work at the time we write the migration but would break in the
+// future when we'll update again the concerned collection schema.
+//
+// To prevent this bug we always have to set the `validate` option to false. We
+// generally use the shorthandlers defined below.
+var noValidate = { validate: false };
+var noValidateMulti = _.extend(noValidate, { multi: true });
+
Migrations.add('board-background-color', function() {
var defaultColor = '#16A085';
Boards.update({
@@ -17,9 +27,7 @@ Migrations.add('board-background-color', function() {
color: defaultColor
}
}
- }, {
- multi: true
- });
+ }, noValidateMulti);
});
Migrations.add('lowercase-board-permission', function() {
@@ -27,7 +35,7 @@ Migrations.add('lowercase-board-permission', function() {
Boards.update(
{ permission: permission },
{ $set: { permission: permission.toLowerCase() } },
- { multi: true }
+ noValidateMulti
);
});
});
@@ -42,7 +50,7 @@ Migrations.add('change-attachments-type-for-non-images', function() {
'original.type': newTypeForNonImage,
'copies.attachments.type': newTypeForNonImage
}
- });
+ }, noValidate);
}
});
});
@@ -51,10 +59,10 @@ Migrations.add('card-covers', function() {
Cards.find().forEach(function(card) {
var cover = Attachments.findOne({ cardId: card._id, cover: true });
if (cover) {
- Cards.update(card._id, {$set: {coverId: cover._id}});
+ Cards.update(card._id, {$set: {coverId: cover._id}}, noValidate);
}
});
- Attachments.update({}, {$unset: {cover: ''}}, {multi: true});
+ Attachments.update({}, {$unset: {cover: ''}}, noValidateMulti);
});
Migrations.add('use-css-class-for-boards-colors', function() {
@@ -69,17 +77,17 @@ Migrations.add('use-css-class-for-boards-colors', function() {
Boards.find().forEach(function(board) {
var oldBoardColor = board.background.color;
var newBoardColor = associationTable[oldBoardColor];
- Boards._collection.update({ _id: board._id }, {
+ Boards.update(board._id, {
$set: { color: newBoardColor },
$unset: { background: '' }
- });
+ }, noValidate);
});
});
Migrations.add('denormalize-star-number-per-board', function() {
Boards.find().forEach(function(board) {
var nStars = Users.find({'profile.starredBoards': board._id}).count();
- Boards.update(board._id, {$set: {stars: nStars}});
+ Boards.update(board._id, {$set: {stars: nStars}}, noValidate);
});
});
@@ -107,7 +115,6 @@ Migrations.add('add-member-isactive-field', function() {
isActive: false
});
});
- Boards._collection.update({_id: board._id},
- {$set: {members: newMemberSet}});
+ Boards.update(board._id, {$set: {members: newMemberSet}}, noValidate);
});
});