From 56b13bd193b076d32925f0ad14b755b250b803a8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Dec 2018 11:24:34 +0100 Subject: Fix federation of some videos If we don't transcode additional resolutions, and user decided to wait transcoding before publishing the video --- server/initializers/constants.ts | 2 +- .../migrations/0305-fix-unfederated-videos.ts | 52 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 server/initializers/migrations/0305-fix-unfederated-videos.ts (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6e463a1d6..b326a6c7b 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -16,7 +16,7 @@ let config: IConfig = require('config') // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 300 +const LAST_MIGRATION_VERSION = 305 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0305-fix-unfederated-videos.ts b/server/initializers/migrations/0305-fix-unfederated-videos.ts new file mode 100644 index 000000000..be206601f --- /dev/null +++ b/server/initializers/migrations/0305-fix-unfederated-videos.ts @@ -0,0 +1,52 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize, + db: any +}): Promise { + { + const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` + + `(` + + `SELECT ` + + `video.url || '/announces/' || "videoChannel"."actorId" as url, ` + + `"videoChannel"."actorId" AS "actorId", ` + + `"video"."id" AS "videoId", ` + + `NOW() AS "createdAt", ` + + `NOW() AS "updatedAt" ` + + `FROM video ` + + `INNER JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id" ` + + `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` + + `) ` + + `ON CONFLICT DO NOTHING` + + await utils.sequelize.query(query) + } + + { + const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` + + `(` + + `SELECT ` + + `video.url || '/announces/' || (SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) as url, ` + + `(SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) AS "actorId", ` + + `"video"."id" AS "videoId", ` + + `NOW() AS "createdAt", ` + + `NOW() AS "updatedAt" ` + + `FROM video ` + + `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` + + `) ` + + `ON CONFLICT DO NOTHING` + + await utils.sequelize.query(query) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3