0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-19 01:12:45 +00:00

add MIGRATE environment variable

This commit is contained in:
Charlie Humphreys
2022-06-25 00:00:41 -05:00
parent c7d5d6800b
commit 8ee832e633

View File

@@ -68,7 +68,8 @@ 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') {
Homebrew.count({ tags: '' }, async (err, count)=>{
if(!err) { if(!err) {
if(count > 0) { if(count > 0) {
Homebrew.updateMany({ tags: '' }, { tags: [] }, { multi: true }, function(err, data) { Homebrew.updateMany({ tags: '' }, { tags: [] }, { multi: true }, function(err, data) {
@@ -84,7 +85,8 @@ Homebrew.count({ tags: '' }, async (err, count)=>{
} else { } else {
console.log('An error occurred while counting brews with the old schema', err); console.log('An error occurred while counting brews with the old schema', err);
} }
}); });
}
module.exports = { module.exports = {
schema : HomebrewSchema, schema : HomebrewSchema,