mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 02:02:51 +00:00
add MIGRATE environment variable
This commit is contained in:
@@ -68,23 +68,25 @@ HomebrewSchema.statics.getByUser = function(username, allowAccess=false, fields=
|
|||||||
|
|
||||||
const Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
const Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
||||||
|
|
||||||
Homebrew.count({ tags: '' }, async (err, count)=>{
|
if(process.env.MIGRATE === 'true') {
|
||||||
if(!err) {
|
Homebrew.count({ tags: '' }, async (err, count)=>{
|
||||||
if(count > 0) {
|
if(!err) {
|
||||||
Homebrew.updateMany({ tags: '' }, { tags: [] }, { multi: true }, function(err, data) {
|
if(count > 0) {
|
||||||
if(!err) {
|
Homebrew.updateMany({ tags: '' }, { tags: [] }, { multi: true }, function(err, data) {
|
||||||
console.log('Successfully updated all brews to new schema definition');
|
if(!err) {
|
||||||
} else {
|
console.log('Successfully updated all brews to new schema definition');
|
||||||
console.log('An error occurred while updating brews to the new schema', err);
|
} else {
|
||||||
}
|
console.log('An error occurred while updating brews to the new schema', err);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('No brews to update');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('No brews to update');
|
console.log('An error occurred while counting brews with the old schema', err);
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
console.log('An error occurred while counting brews with the old schema', err);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
schema : HomebrewSchema,
|
schema : HomebrewSchema,
|
||||||
|
|||||||
Reference in New Issue
Block a user