aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-08-25 11:36:23 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-08-25 11:36:23 +0200
commit93e1258c7cbc0d1235ca6d2a1f7c1875985328b8 (patch)
treeb0a1f77af7ab54dc5f58f569fcd1e9d84b04c533 /server/initializers/migrations
parent69f224587e99d56008e1fa129d0641840a486620 (diff)
downloadPeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.tar.gz
PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.tar.zst
PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.zip
Move video file metadata in their own table
Will be used for user video quotas and multiple video resolutions
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0060-video-file.ts34
-rw-r--r--server/initializers/migrations/0065-video-file-size.ts46
2 files changed, 80 insertions, 0 deletions
diff --git a/server/initializers/migrations/0060-video-file.ts b/server/initializers/migrations/0060-video-file.ts
new file mode 100644
index 000000000..c362cf71a
--- /dev/null
+++ b/server/initializers/migrations/0060-video-file.ts
@@ -0,0 +1,34 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize,
8 db: any
9}): Promise<void> {
10 const q = utils.queryInterface
11
12 const query = 'INSERT INTO "VideoFiles" ("videoId", "resolution", "size", "extname", "infoHash", "createdAt", "updatedAt") ' +
13 'SELECT "id" AS "videoId", 0 AS "resolution", 0 AS "size", ' +
14 '"extname"::"text"::"enum_VideoFiles_extname" as "extname", "infoHash", "createdAt", "updatedAt" ' +
15 'FROM "Videos"'
16
17 return utils.db.VideoFile.sync()
18 .then(() => utils.sequelize.query(query))
19 .then(() => {
20 return q.removeColumn('Videos', 'extname')
21 })
22 .then(() => {
23 return q.removeColumn('Videos', 'infoHash')
24 })
25}
26
27function down (options) {
28 throw new Error('Not implemented.')
29}
30
31export {
32 up,
33 down
34}
diff --git a/server/initializers/migrations/0065-video-file-size.ts b/server/initializers/migrations/0065-video-file-size.ts
new file mode 100644
index 000000000..58f8f3bcc
--- /dev/null
+++ b/server/initializers/migrations/0065-video-file-size.ts
@@ -0,0 +1,46 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3import { stat } from 'fs'
4
5import { VideoInstance } from '../../models'
6
7function up (utils: {
8 transaction: Sequelize.Transaction,
9 queryInterface: Sequelize.QueryInterface,
10 sequelize: Sequelize.Sequelize,
11 db: any
12}): Promise<void> {
13 return utils.db.Video.listOwnedAndPopulateAuthorAndTags()
14 .then((videos: VideoInstance[]) => {
15 const tasks: Promise<any>[] = []
16
17 videos.forEach(video => {
18 video.VideoFiles.forEach(videoFile => {
19 const p = new Promise((res, rej) => {
20 stat(video.getVideoFilePath(videoFile), (err, stats) => {
21 if (err) return rej(err)
22
23 videoFile.size = stats.size
24 videoFile.save().then(res).catch(rej)
25 })
26 })
27
28 tasks.push(p)
29 })
30 })
31
32 return tasks
33 })
34 .then((tasks: Promise<any>[]) => {
35 return Promise.all(tasks)
36 })
37}
38
39function down (options) {
40 throw new Error('Not implemented.')
41}
42
43export {
44 up,
45 down
46}