aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-17 09:36:09 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-18 13:38:09 +0100
commit2451916e45420fedf556913ce121f3964c4b57d6 (patch)
treec8a0e35285cac08acc0a2f3fefb33a27006e9df5 /server/initializers
parent90a8bd305de4153ec21137a73ff482dcc2e3e19b (diff)
downloadPeerTube-2451916e45420fedf556913ce121f3964c4b57d6.tar.gz
PeerTube-2451916e45420fedf556913ce121f3964c4b57d6.tar.zst
PeerTube-2451916e45420fedf556913ce121f3964c4b57d6.zip
Add video files migration
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0585-video-file-names.ts55
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
27const LAST_MIGRATION_VERSION = 580 27const 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 @@
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}