From 6302d599cdf98b5a5363a2a1dcdc266447950191 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Feb 2021 14:08:16 +0100 Subject: Generate a name for caption files --- server/initializers/constants.ts | 2 +- .../migrations/0580-caption-filename.ts | 48 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 server/initializers/migrations/0580-caption-filename.ts (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index a9f7a8e58..be5db8fe8 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 575 +const LAST_MIGRATION_VERSION = 580 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0580-caption-filename.ts b/server/initializers/migrations/0580-caption-filename.ts new file mode 100644 index 000000000..5281fd0c0 --- /dev/null +++ b/server/initializers/migrations/0580-caption-filename.ts @@ -0,0 +1,48 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + { + const data = { + type: Sequelize.STRING, + allowNull: true, + defaultValue: null + } + + await utils.queryInterface.addColumn('videoCaption', 'filename', data) + } + + { + const query = `UPDATE "videoCaption" SET "filename" = s.uuid || '-' || s.language || '.vtt' ` + + `FROM (` + + ` SELECT "videoCaption"."id", video.uuid, "videoCaption".language ` + + ` FROM "videoCaption" INNER JOIN video ON video.id = "videoCaption"."videoId"` + + `) AS s ` + + `WHERE "videoCaption".id = s.id` + + await utils.sequelize.query(query) + } + + { + const data = { + type: Sequelize.STRING, + allowNull: false, + defaultValue: null + } + + await utils.queryInterface.changeColumn('videoCaption', 'filename', data) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3