]>
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 map
= require('lodash/map')
6 const mongoose
= require('mongoose')
7 const readline
= require('readline')
9 const rl
= readline
.createInterface({
11 output: process
.stdout
14 const logger
= require('../../helpers/logger')
15 const friends
= require('../../lib/friends')
17 const Pod
= mongoose
.model('Pod')
18 const Video
= mongoose
.model('Video')
20 exports
.up = function (callback
) {
21 Pod
.find({}).lean().exec(function (err
, pods
) {
22 if (err
) return callback(err
)
24 // We need to quit friends first
25 if (pods
.length
=== 0) {
26 return setVideosRemoteId(callback
)
29 const timeout
= setTimeout(function () {
30 throw new Error('You need to enter a value!')
33 rl
.question('I am sorry but I need to quit friends for upgrading. Do you want to continue? (yes/*)', function (answer
) {
34 if (answer
!== 'yes') throw new Error('I cannot continue.')
39 const urls
= map(pods
, 'url')
40 logger
.info('Saying goodbye to: ' + urls
.join(', '))
42 setVideosRemoteId(function () {
43 friends
.quitFriends(callback
)
49 exports
.down = function (callback
) {
50 throw new Error('Not implemented.')
53 function setVideosRemoteId (callback
) {
54 Video
.update({ filename: { $ne: null } }, { remoteId: null }, function (err
) {
57 Video
.update({ filename: null }, { remoteId: mongoose
.Types
.ObjectId() }, callback
)