Skip to content

Instantly share code, notes, and snippets.

@steve-ross
Created December 20, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve-ross/2a6e609e3f6c319b023678a2e6cc9cc7 to your computer and use it in GitHub Desktop.
Save steve-ross/2a6e609e3f6c319b023678a2e6cc9cc7 to your computer and use it in GitHub Desktop.
migration with temporary simple schema
Migrations.add({
version : 26,
name : 'Remove profile.email from users',
up : function(){
// add optional profile.email so we can remove it
var profile = _.extend({
email : {
type : String,
optional: true
}
}, Schemas.UserProfile._schema);
var user = Schemas.User._schema;
var profileSchema = new SimpleSchema(profile);
user.profile = {type: profileSchema, optional: true};
var userSchema = new SimpleSchema(user);
Meteor.users.attachSchema(userSchema, {replace: true});
Meteor.users.find({"profile.email": {$exists: true}}).forEach(function(u){
Meteor.users.update({_id: u._id}, {$unset: {"profile.email": ""}});
});
// reset the schema back to the original
Meteor.users.attachSchema(Schemas.User, {replace: true});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment