From 9cc8d43e37a61709e7275c2a799bdf976dd940ca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 24 Apr 2019 10:28:57 +0200 Subject: Add migrations --- server/initializers/migrations/0370-thumbnail.ts | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 server/initializers/migrations/0370-thumbnail.ts (limited to 'server/initializers/migrations') diff --git a/server/initializers/migrations/0370-thumbnail.ts b/server/initializers/migrations/0370-thumbnail.ts new file mode 100644 index 000000000..384ca1a15 --- /dev/null +++ b/server/initializers/migrations/0370-thumbnail.ts @@ -0,0 +1,50 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize, + db: any +}): Promise { + { + const query = ` +CREATE TABLE IF NOT EXISTS "thumbnail" +( + "id" SERIAL, + "filename" VARCHAR(255) NOT NULL, + "height" INTEGER DEFAULT NULL, + "width" INTEGER DEFAULT NULL, + "type" INTEGER NOT NULL, + "fileUrl" VARCHAR(255), + "videoId" INTEGER REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + "videoPlaylistId" INTEGER REFERENCES "videoPlaylist" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, + "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, + PRIMARY KEY ("id") +);` + await utils.sequelize.query(query) + } + + { + // All video thumbnails + const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' + + 'SELECT uuid || \'.jpg\', 1, id, 110, 200, NOW(), NOW() FROM "video"' + await utils.sequelize.query(query) + } + + { + // All video previews + const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' + + 'SELECT uuid || \'.jpg\', 2, id, 315, 560, NOW(), NOW() FROM "video"' + await utils.sequelize.query(query) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3