Created
December 20, 2017 14:14
-
-
Save steve-ross/2a6e609e3f6c319b023678a2e6cc9cc7 to your computer and use it in GitHub Desktop.
migration with temporary simple schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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