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