aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0040-video-remote-id.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-11-14 22:49:19 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-11-16 20:29:26 +0100
commit2550fab35e0113264369f9637e1bea169efdfc8f (patch)
tree23480a9565de29791545612864af240ccceb5d1f /server/initializers/migrations/0040-video-remote-id.js
parentc92372d0aa8bd2bc02152941cfd4546b45949368 (diff)
downloadPeerTube-2550fab35e0113264369f9637e1bea169efdfc8f.tar.gz
PeerTube-2550fab35e0113264369f9637e1bea169efdfc8f.tar.zst
PeerTube-2550fab35e0113264369f9637e1bea169efdfc8f.zip
Server: add migration scripts to the new mongo schemes
Diffstat (limited to 'server/initializers/migrations/0040-video-remote-id.js')
-rw-r--r--server/initializers/migrations/0040-video-remote-id.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/server/initializers/migrations/0040-video-remote-id.js b/server/initializers/migrations/0040-video-remote-id.js
new file mode 100644
index 000000000..5cf856b2e
--- /dev/null
+++ b/server/initializers/migrations/0040-video-remote-id.js
@@ -0,0 +1,63 @@
1/*
2 Use remote id as identifier
3*/
4
5const each = require('async/each')
6const map = require('lodash/map')
7const mongoose = require('mongoose')
8const readline = require('readline')
9
10const rl = readline.createInterface({
11 input: process.stdin,
12 output: process.stdout
13})
14
15const logger = require('../../helpers/logger')
16const friends = require('../../lib/friends')
17
18const Pod = mongoose.model('Pod')
19const Video = mongoose.model('Video')
20
21exports.up = function (callback) {
22 Pod.find({}).lean().exec(function (err, pods) {
23 if (err) return callback(err)
24
25 // We need to quit friends first
26 if (pods.length === 0) {
27 return setVideosRemoteId(callback)
28 }
29
30 const timeout = setTimeout(function () {
31 throw new Error('You need to enter a value!')
32 }, 10000)
33
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.')
36
37 clearTimeout(timeout)
38 rl.close()
39
40 const urls = map(pods, 'url')
41 logger.info('Saying goodbye to: ' + urls.join(', '))
42
43 friends.quitFriends(function () {
44 setVideosRemoteId(callback)
45 })
46 })
47 })
48}
49
50exports.down = function (callback) {
51 throw new Error('Not implemented.')
52}
53
54function setVideosRemoteId (callback) {
55 Video.find({}, function (err, videos) {
56 if (err) return callback(err)
57
58 each(videos, function (video, callbackEach) {
59 video.remoteId = null
60 video.save(callbackEach)
61 }, callback)
62 })
63}