]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0370-thumbnail.ts
Fix object storage migration
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0370-thumbnail.ts
CommitLineData
9cc8d43e
C
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
a1587156
C
4 transaction: Sequelize.Transaction
5 queryInterface: Sequelize.QueryInterface
6 sequelize: Sequelize.Sequelize
9cc8d43e
C
7 db: any
8}): Promise<void> {
9 {
10 const query = `
11CREATE TABLE IF NOT EXISTS "thumbnail"
12(
13 "id" SERIAL,
14 "filename" VARCHAR(255) NOT NULL,
15 "height" INTEGER DEFAULT NULL,
16 "width" INTEGER DEFAULT NULL,
17 "type" INTEGER NOT NULL,
18 "fileUrl" VARCHAR(255),
19 "videoId" INTEGER REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
20 "videoPlaylistId" INTEGER REFERENCES "videoPlaylist" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
21 "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
22 "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
23 PRIMARY KEY ("id")
24);`
25 await utils.sequelize.query(query)
26 }
27
28 {
29 // All video thumbnails
30 const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' +
31 'SELECT uuid || \'.jpg\', 1, id, 110, 200, NOW(), NOW() FROM "video"'
32 await utils.sequelize.query(query)
33 }
34
35 {
36 // All video previews
37 const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' +
38 'SELECT uuid || \'.jpg\', 2, id, 315, 560, NOW(), NOW() FROM "video"'
39 await utils.sequelize.query(query)
40 }
41}
42
43function down (options) {
44 throw new Error('Not implemented.')
45}
46
47export {
48 up,
49 down
50}