diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0585-video-file-names.ts | 55 |
2 files changed, 56 insertions, 1 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6b0984186..c4c7ffdac 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' | |||
24 | 24 | ||
25 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
26 | 26 | ||
27 | const LAST_MIGRATION_VERSION = 580 | 27 | const LAST_MIGRATION_VERSION = 585 |
28 | 28 | ||
29 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
30 | 30 | ||
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 @@ | |||
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 | } | ||