aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/migrations
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-21 11:56:19 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-10-24 14:48:24 +0200
commitfc097052abfbd646950a26f02b31b9925a5f3961 (patch)
tree06ea94aabb8be0d3d0a934f89a7908b643f884b5 /scripts/migrations
parent326f36929a2bc37185e9188ee4eff17b52a329e5 (diff)
downloadPeerTube-fc097052abfbd646950a26f02b31b9925a5f3961.tar.gz
PeerTube-fc097052abfbd646950a26f02b31b9925a5f3961.tar.zst
PeerTube-fc097052abfbd646950a26f02b31b9925a5f3961.zip
Add migration script
Diffstat (limited to 'scripts/migrations')
-rw-r--r--scripts/migrations/peertube-5.0.ts71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/migrations/peertube-5.0.ts b/scripts/migrations/peertube-5.0.ts
new file mode 100644
index 000000000..a0f51a64c
--- /dev/null
+++ b/scripts/migrations/peertube-5.0.ts
@@ -0,0 +1,71 @@
1import { ensureDir } from 'fs-extra'
2import { Op } from 'sequelize'
3import { updateTorrentMetadata } from '@server/helpers/webtorrent'
4import { DIRECTORIES } from '@server/initializers/constants'
5import { moveFilesIfPrivacyChanged } from '@server/lib/video-privacy'
6import { VideoModel } from '@server/models/video/video'
7import { MVideoFullLight } from '@server/types/models'
8import { VideoPrivacy } from '@shared/models'
9import { initDatabaseModels } from '../../server/initializers/database'
10
11run()
12 .then(() => process.exit(0))
13 .catch(err => {
14 console.error(err)
15 process.exit(-1)
16 })
17
18async function run () {
19 console.log('Moving private video files in dedicated folders.')
20
21 await ensureDir(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE)
22 await ensureDir(DIRECTORIES.VIDEOS.PRIVATE)
23
24 await initDatabaseModels(true)
25
26 const videos = await VideoModel.unscoped().findAll({
27 attributes: [ 'uuid' ],
28 where: {
29 privacy: {
30 [Op.in]: [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]
31 }
32 }
33 })
34
35 for (const { uuid } of videos) {
36 try {
37 console.log('Moving files of video %s.', uuid)
38
39 const video = await VideoModel.loadFull(uuid)
40
41 try {
42 await moveFilesIfPrivacyChanged(video, VideoPrivacy.PUBLIC)
43 } catch (err) {
44 console.error('Cannot move files of video %s.', uuid, err)
45 }
46
47 try {
48 await updateTorrents(video)
49 } catch (err) {
50 console.error('Cannot regenerate torrents of video %s.', uuid, err)
51 }
52 } catch (err) {
53 console.error('Cannot process video %s.', uuid, err)
54 }
55 }
56}
57
58async function updateTorrents (video: MVideoFullLight) {
59 for (const file of video.VideoFiles) {
60 await updateTorrentMetadata(video, file)
61
62 await file.save()
63 }
64
65 const playlist = video.getHLSPlaylist()
66 for (const file of (playlist?.VideoFiles || [])) {
67 await updateTorrentMetadata(playlist, file)
68
69 await file.save()
70 }
71}