1
0
Fork 0

Fix migration script

This commit is contained in:
Chocobozzz 2016-11-21 22:08:40 +01:00
parent a86444089e
commit 04968ab477
1 changed files with 5 additions and 9 deletions

View File

@ -2,7 +2,6 @@
Use remote id as identifier Use remote id as identifier
*/ */
const each = require('async/each')
const map = require('lodash/map') const map = require('lodash/map')
const mongoose = require('mongoose') const mongoose = require('mongoose')
const readline = require('readline') const readline = require('readline')
@ -40,8 +39,8 @@ exports.up = function (callback) {
const urls = map(pods, 'url') const urls = map(pods, 'url')
logger.info('Saying goodbye to: ' + urls.join(', ')) logger.info('Saying goodbye to: ' + urls.join(', '))
friends.quitFriends(function () { setVideosRemoteId(function () {
setVideosRemoteId(callback) friends.quitFriends(callback)
}) })
}) })
}) })
@ -52,12 +51,9 @@ exports.down = function (callback) {
} }
function setVideosRemoteId (callback) { function setVideosRemoteId (callback) {
Video.find({}, function (err, videos) { Video.update({ filename: { $ne: null } }, { remoteId: null }, function (err) {
if (err) return callback(err) if (err) throw err
each(videos, function (video, callbackEach) { Video.update({ filename: null }, { remoteId: mongoose.Types.ObjectId() }, callback)
video.remoteId = null
video.save(callbackEach)
}, callback)
}) })
} }