aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0030-video-magnet.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/0030-video-magnet.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/0030-video-magnet.js')
-rw-r--r--server/initializers/migrations/0030-video-magnet.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/initializers/migrations/0030-video-magnet.js b/server/initializers/migrations/0030-video-magnet.js
new file mode 100644
index 000000000..b9119d61c
--- /dev/null
+++ b/server/initializers/migrations/0030-video-magnet.js
@@ -0,0 +1,32 @@
1/*
2 Change video magnet structures
3*/
4
5const each = require('async/each')
6const magnet = require('magnet-uri')
7const mongoose = require('mongoose')
8
9const Video = mongoose.model('Video')
10
11exports.up = function (callback) {
12 // Use of lean because the new Video scheme does not have magnetUri field
13 Video.find({ }).lean().exec(function (err, videos) {
14 if (err) throw err
15
16 each(videos, function (video, callbackEach) {
17 const parsed = magnet.decode(video.magnetUri)
18 const infoHash = parsed.infoHash
19
20 Video.load(video._id, function (err, videoObj) {
21 if (err) return callbackEach(err)
22
23 videoObj.magnet.infoHash = infoHash
24 videoObj.save(callbackEach)
25 })
26 }, callback)
27 })
28}
29
30exports.down = function (callback) {
31 throw new Error('Not implemented.')
32}