]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0450-streaming-playlist-files.ts
Upgrade server dep
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0450-streaming-playlist-files.ts
CommitLineData
d7a25329 1import * as Sequelize from 'sequelize'
d441f2ed
C
2import { join } from 'path'
3import { HLS_STREAMING_PLAYLIST_DIRECTORY, WEBSERVER } from '@server/initializers/constants'
4import { CONFIG } from '@server/initializers/config'
5import { pathExists, stat, writeFile } from 'fs-extra'
6import * as parseTorrent from 'parse-torrent'
7import { createTorrentPromise } from '@server/helpers/webtorrent'
d7a25329
C
8
9async function up (utils: {
10 transaction: Sequelize.Transaction,
11 queryInterface: Sequelize.QueryInterface,
12 sequelize: Sequelize.Sequelize,
13 db: any
14}): Promise<void> {
15 {
16 const data = {
17 type: Sequelize.INTEGER,
18 allowNull: true,
19 references: {
20 model: 'videoStreamingPlaylist',
21 key: 'id'
22 },
23 onDelete: 'CASCADE'
24 }
25
26 await utils.queryInterface.addColumn('videoFile', 'videoStreamingPlaylistId', data)
27 }
28
29 {
30 const data = {
31 type: Sequelize.INTEGER,
32 allowNull: true
33 }
34
35 await utils.queryInterface.changeColumn('videoFile', 'videoId', data)
36 }
d441f2ed
C
37
38 {
39 await utils.queryInterface.removeIndex('videoFile', 'video_file_video_id_resolution_fps')
40 }
41
42 {
43 const query = 'insert into "videoFile" ' +
44 '(resolution, size, "infoHash", "videoId", "createdAt", "updatedAt", fps, extname, "videoStreamingPlaylistId")' +
45 '(SELECT "videoFile".resolution, "videoFile".size, \'fake\', NULL, "videoFile"."createdAt", "videoFile"."updatedAt", "videoFile"."fps", ' +
46 '"videoFile".extname, "videoStreamingPlaylist".id FROM "videoStreamingPlaylist" ' +
47 'inner join video ON video.id = "videoStreamingPlaylist"."videoId" inner join "videoFile" ON "videoFile"."videoId" = video.id)'
48
49 await utils.sequelize.query(query, { transaction: utils.transaction })
50 }
d7a25329
C
51}
52
53function down (options) {
54 throw new Error('Not implemented.')
55}
56
57export {
58 up,
59 down
60}