aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0035-url-to-host.js
blob: 6243304d5f385b0959e919a7e1dbe43549458cf2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
  Change video magnet structures
*/

const each = require('async/each')
const mongoose = require('mongoose')

const Video = mongoose.model('Video')

exports.up = function (callback) {
  // Use of lean because the new Video scheme does not have podUrl field
  Video.find({ }).lean().exec(function (err, videos) {
    if (err) throw err

    each(videos, function (video, callbackEach) {
      Video.load(video._id, function (err, videoObj) {
        if (err) return callbackEach(err)

        const host = video.podUrl.split('://')[1]

        videoObj.podHost = host
        videoObj.save(callbackEach)
      })
    }, callback)
  })
}

exports.down = function (callback) {
  throw new Error('Not implemented.')
}