]>
Commit | Line | Data |
---|---|---|
2451916e C |
1 | import * as Sequelize from 'sequelize' |
2 | ||
3 | async function up (utils: { | |
4 | transaction: Sequelize.Transaction | |
5 | queryInterface: Sequelize.QueryInterface | |
6 | sequelize: Sequelize.Sequelize | |
7 | db: any | |
8 | }): Promise<void> { | |
9 | for (const column of [ 'filename', 'fileUrl', 'torrentFilename', 'torrentUrl' ]) { | |
10 | const data = { | |
11 | type: Sequelize.STRING, | |
12 | allowNull: true, | |
13 | defaultValue: null | |
14 | } | |
15 | ||
16 | await utils.queryInterface.addColumn('videoFile', column, data) | |
17 | } | |
18 | ||
19 | // Generate filenames for webtorrent files | |
20 | { | |
21 | const webtorrentQuery = `SELECT "videoFile".id, "video".uuid, "videoFile".resolution, "videoFile".extname ` + | |
22 | `FROM video INNER JOIN "videoFile" ON "videoFile"."videoId" = video.id` | |
23 | ||
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"` | |
28 | ||
29 | await utils.sequelize.query(query) | |
30 | } | |
31 | ||
32 | // Generate filenames for HLS files | |
33 | { | |
34 | const hlsQuery = `SELECT "videoFile".id, "video".uuid, "videoFile".resolution, "videoFile".extname ` + | |
35 | `FROM video ` + | |
36 | `INNER JOIN "videoStreamingPlaylist" ON "videoStreamingPlaylist"."videoId" = video.id ` + | |
37 | `INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist".id` | |
38 | ||
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"` | |
43 | ||
44 | await utils.sequelize.query(query) | |
45 | } | |
46 | } | |
47 | ||
48 | function down (options) { | |
49 | throw new Error('Not implemented.') | |
50 | } | |
51 | ||
52 | export { | |
53 | up, | |
54 | down | |
55 | } |