aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0585-video-file-names.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/migrations/0585-video-file-names.ts')
-rw-r--r--server/initializers/migrations/0585-video-file-names.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/server/initializers/migrations/0585-video-file-names.ts b/server/initializers/migrations/0585-video-file-names.ts
new file mode 100644
index 000000000..dd5fec3a1
--- /dev/null
+++ b/server/initializers/migrations/0585-video-file-names.ts
@@ -0,0 +1,55 @@
1import * as Sequelize from 'sequelize'
2
3async 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
48function down (options) {
49 throw new Error('Not implemented.')
50}
51
52export {
53 up,
54 down
55}