v3: define migration spec and misc fixes

This commit is contained in:
Matteo Pagliazzi
2016-04-25 13:51:08 +02:00
parent b6f79aff0b
commit 12b05b9492
7 changed files with 22 additions and 22 deletions

View File

@@ -7,6 +7,10 @@
// It requires two environment variables: MONGODB_OLD and MONGODB_NEW
/*
tags must have a name
*/
console.log('Starting migrations/api_v3/users.js.');
import Q from 'q';
@@ -72,9 +76,10 @@ async function processUser (_id) {
newUser.tasksOrder[`${oldTask.type}s`].push(newTask._id);
// newTask.legacyId = oldTask.id;
let newTaskObject = newTask.toObject();
newTaskObject.legacyId = oldTask.id;
batchInsertTasks.insert(newTask.toObject());
batchInsertTasks.insert(newTaskObject);
});
await Q.all([

View File

@@ -24,6 +24,9 @@ let schema = new Schema({
group: {type: String, ref: 'Group', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
memberCount: {type: Number, default: 1},
prize: {type: Number, default: 0, min: 0}, // TODO no update?
}, {
strict: true,
minimize: false, // So empty objects are returned
});
schema.plugin(baseModel, {
@@ -153,6 +156,7 @@ schema.methods.addTasks = async function challengeAddTasks (tasks) {
// Sync each user sequentially
// TODO are we sure it's the best solution?
// use bulk ops? http://stackoverflow.com/questions/16726330/mongoose-mongodb-batch-insert
for (let memberId of membersIds) {
let updateTasksOrderQ = {$push: {}};
let toSave = [];

View File

@@ -13,6 +13,9 @@ import {
export let schema = new mongoose.Schema({
event: {type: String, enum: ['wondercon', 'google_6mo']},
user: {type: String, ref: 'User'},
}, {
strict: true,
minimize: false, // So empty objects are returned
});
schema.plugin(baseModel, {

View File

@@ -15,6 +15,9 @@ export let schema = new mongoose.Schema({
lowercase: true, // TODO migrate existing to lowerCase
validator: [validator.isEmail, 'Invalid email.'],
},
}, {
strict: true,
minimize: false, // So empty objects are returned
});
export let model = mongoose.model('EmailUnsubscription', schema);

View File

@@ -91,21 +91,6 @@ schema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
// Basic fields to fetch for populating a group info
export let basicFields = 'name type privacy';
// TODO migration
/**
* Derby duplicated stuff. This is a temporary solution, once we're completely off derby we'll run an mongo migration
* to remove duplicates, then take these fucntions out
*/
/* function removeDuplicates(doc){
// Remove duplicate members
if (doc.members) {
var uniqMembers = _.uniq(doc.members);
if (uniqMembers.length != doc.members.length) {
doc.members = uniqMembers;
}
}
}*/
// TODO test
schema.pre('remove', true, async function preRemoveGroup (next, done) {
next();

View File

@@ -7,8 +7,8 @@ export let schema = new Schema({
name: {type: String, required: true},
challenge: {type: String},
}, {
minimize: true, // So empty objects are returned
strict: true,
minimize: false, // So empty objects are returned
});
schema.plugin(baseModel, {

View File

@@ -115,10 +115,10 @@ export let schema = new Schema({
},
balance: {type: Number, default: 0},
// Not saved on the user TODO remove with migration
/* filters: {type: Schema.Types.Mixed, default: () => {
// Not saved on the user right now
filters: {type: Schema.Types.Mixed, default: () => {
return {};
}}, */
}},
purchased: {
ads: {type: Boolean, default: false},
@@ -524,7 +524,7 @@ export let schema = new Schema({
},
}, {
strict: true,
minimize: false, // So empty objects are returned TODO make sure it's in every model
minimize: false, // So empty objects are returned
});
schema.plugin(baseModel, {