]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0035-url-to-host.js
Update scripts with postgresql
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0035-url-to-host.js
CommitLineData
2550fab3
C
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}