1 import * as Sequelize from 'sequelize'
3 async function up (utils: {
4 transaction: Sequelize.Transaction
5 queryInterface: Sequelize.QueryInterface
6 sequelize: Sequelize.Sequelize
9 for (const column of [ 'filename', 'fileUrl', 'torrentFilename', 'torrentUrl' ]) {
11 type: Sequelize.STRING,
16 await utils.queryInterface.addColumn('videoFile', column, data)
19 // Generate filenames for webtorrent files
21 const webtorrentQuery = `SELECT "videoFile".id, "video".uuid, "videoFile".resolution, "videoFile".extname ` +
22 `FROM video INNER JOIN "videoFile" ON "videoFile"."videoId" = video.id`
24 const query = `UPDATE "videoFile" ` +
25 `SET filename = t.uuid || '-' || t.resolution || t.extname, ` +
26 `"torrentFilename" = t.uuid || '-' || t.resolution || '.torrent' ` +
27 `FROM (${webtorrentQuery}) AS t WHERE t.id = "videoFile"."id"`
29 await utils.sequelize.query(query)
32 // Generate filenames for HLS files
34 const hlsQuery = `SELECT "videoFile".id, "video".uuid, "videoFile".resolution, "videoFile".extname ` +
36 `INNER JOIN "videoStreamingPlaylist" ON "videoStreamingPlaylist"."videoId" = video.id ` +
37 `INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist".id`
39 const query = `UPDATE "videoFile" ` +
40 `SET filename = t.uuid || '-' || t.resolution || '-fragmented' || t.extname, ` +
41 `"torrentFilename" = t.uuid || '-' || t.resolution || '-hls.torrent' ` +
42 `FROM (${hlsQuery}) AS t WHERE t.id = "videoFile"."id"`
44 await utils.sequelize.query(query)
48 function down (options) {
49 throw new Error('Not implemented.')