aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-03 16:04:14 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-03 17:16:47 +0200
commitecb455b6c42bd75c9d87294c2479fa53b739d0a8 (patch)
tree1d9ea1864e3877e1b48bf520e95cdc337d391311 /server/initializers/migrations
parent40298b02546e8225dd21bf6048fe7f224aefc32a (diff)
downloadPeerTube-ecb455b6c42bd75c9d87294c2479fa53b739d0a8.tar.gz
PeerTube-ecb455b6c42bd75c9d87294c2479fa53b739d0a8.tar.zst
PeerTube-ecb455b6c42bd75c9d87294c2479fa53b739d0a8.zip
Add migration script
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0075-video-resolutions.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts
new file mode 100644
index 000000000..6bc1e72ab
--- /dev/null
+++ b/server/initializers/migrations/0075-video-resolutions.ts
@@ -0,0 +1,62 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3import { join } from 'path'
4
5import { readdirPromise, renamePromise } from '../../helpers/core-utils'
6import { CONFIG } from '../../initializers/constants'
7
8function up (utils: {
9 transaction: Sequelize.Transaction,
10 queryInterface: Sequelize.QueryInterface,
11 sequelize: Sequelize.Sequelize,
12 db: any
13}): Promise<void> {
14 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
15 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR
16
17 return readdirPromise(torrentDir)
18 .then(torrentFiles => {
19 const tasks: Promise<any>[] = []
20 for (const torrentFile of torrentFiles) {
21 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.torrent/.exec(torrentFile)
22 if (matches === null) {
23 console.log('Invalid torrent file name %s.', torrentFile)
24 continue
25 }
26
27 const newTorrentName = matches[1] + '-original.torrent'
28 const p = renamePromise(join(torrentDir, torrentFile), join(torrentDir, newTorrentName))
29 tasks.push(p)
30 }
31
32 return Promise.all(tasks)
33 })
34 .then(() => {
35 return readdirPromise(videoFileDir)
36 })
37 .then(videoFiles => {
38 const tasks: Promise<any>[] = []
39 for (const videoFile of videoFiles) {
40 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.([a-z0-9]+)/.exec(videoFile)
41 if (matches === null) {
42 console.log('Invalid video file name %s.', videoFile)
43 continue
44 }
45
46 const newVideoFileName = matches[1] + '-original.' + matches[2]
47 const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName))
48 tasks.push(p)
49 }
50
51 return Promise.all(tasks).then(() => undefined)
52 })
53}
54
55function down (options) {
56 throw new Error('Not implemented.')
57}
58
59export {
60 up,
61 down
62}