]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/migrations/0040-video-remote-id.js
2 Use remote id as identifier
5 const each
= require('async/each')
6 const map
= require('lodash/map')
7 const mongoose
= require('mongoose')
8 const readline
= require('readline')
10 const rl
= readline
.createInterface({
12 output: process
.stdout
15 const logger
= require('../../helpers/logger')
16 const friends
= require('../../lib/friends')
18 const Pod
= mongoose
.model('Pod')
19 const Video
= mongoose
.model('Video')
21 exports
.up = function (callback
) {
22 Pod
.find({}).lean().exec(function (err
, pods
) {
23 if (err
) return callback(err
)
25 // We need to quit friends first
26 if (pods
.length
=== 0) {
27 return setVideosRemoteId(callback
)
30 const timeout
= setTimeout(function () {
31 throw new Error('You need to enter a value!')
34 rl
.question('I am sorry but I need to quit friends for upgrading. Do you want to continue? (yes/*)', function (answer
) {
35 if (answer
!== 'yes') throw new Error('I cannot continue.')
40 const urls
= map(pods
, 'url')
41 logger
.info('Saying goodbye to: ' + urls
.join(', '))
43 friends
.quitFriends(function () {
44 setVideosRemoteId(callback
)
50 exports
.down = function (callback
) {
51 throw new Error('Not implemented.')
54 function setVideosRemoteId (callback
) {
55 Video
.find({}, function (err
, videos
) {
56 if (err
) return callback(err
)
58 each(videos
, function (video
, callbackEach
) {
60 video
.save(callbackEach
)