I have a staging environment and I want to reset the database at specific points, while all the rest of the VM / host system, as well as the docker system remains as is. Preferrably using MUP and not a login shell.
Is that even possible?
I have a staging environment and I want to reset the database at specific points, while all the rest of the VM / host system, as well as the docker system remains as is. Preferrably using MUP and not a login shell.
Is that even possible?
I can’t think of a way of doing this via MUP, but it should be possible via ssh
into the host and connecting to the mongo
container to drop the collections manually.
My approach is to always create a root
user in my Meteor.users collection - this is the account I log in with to perform administrative tasks - I have an entire /root
route with admin pages which only my account can access.
Then, via these /root
pages I can perform some admin tasks, such as resetting the database.
Also, in my staging server’s mup.js
config file I set an environment variable STAGING: 'true'
which I use to disable certain admin features in production so I don’t do them by accident!
// server/main.js
// easily test if this is the staging server:
Meteor.isStaging = this.process.env.STAGING === 'true';
// create the root account if it doesn't exist:
Meteor.startup(function() {
console.log('startup, rootEmail:', global.rootEmail);
if ( !Meteor.users.findOne({'emails.address': global.rootEmail}, {fields:{_id: 1}}) ) {
const adminId = Accounts.createUser({
email: global.rootEmail,
profile: {name: "root"},
});
Accounts.sendResetPasswordEmail(adminId);
console.log('Admin account created!!');
}
});
// server/methods/rootFunctions.js
Meteor.methods({
'server.rootFunctions': function(func, data) {
/************************** VALIDATE PERMISSIONS ***********************************/
check(this.userId, String); // check if someone logged in
if (Meteor.users.findOne(this.userId, {fields: {'emails.address': 1}}).emails[0].address!=global.rootEmail) throw new Match.Error(500,'you are not root');
/***********************************************************************************/
// reset database -- STAGING only
if (func=='resetDatabase') {
if (!Meteor.isStaging) throw new Meteor.Error("Don't reset DB in production!");
Meteor.users.remove({'emails.address': {$ne: global.rootEmail}}, {multi: true});
myCollection.remove({}, {multi: true});
myOtherCollection.remove({}, {multi: true});
return 'done';
}
// delete user
else if (func=='deleteUser') {
check(data.userId, String);
...
}
// other root funttions...