ActivityPub-federated video streaming platform using P2P directly in your web browser
Use manual migration script for slow migrations
Chocobozzz27a7cfd94def
diff --git a/server/core/initializers/migrations/1100-video-infohash.ts b/server/core/initializers/migrations/1100-video-infohash.tsindex 4576a406af..6f378c1cc5 100644--- a/server/core/initializers/migrations/1100-video-infohash.ts+++ b/server/core/initializers/migrations/1100-video-infohash.ts@@ -20,46 +20,8 @@ CREATE TABLE IF NOT EXISTS "videoInfohash" (await utils.sequelize.query(query, { transaction })}- // Don't re-hydrate video streaming playlists infohash, PeerTube will re-generate them on the next startup-- // Classic infohash are stored as 40 char hex on the video file- {- await utils.sequelize.query(- `CREATE OR REPLACE FUNCTION safe_decode_hex(input text)-RETURNS bytea AS $$-BEGIN- RETURN decode(input, 'hex');-EXCEPTION- WHEN others THEN- RETURN NULL;-END;-$$ LANGUAGE plpgsql IMMUTABLE;`,- { transaction }- )-- await utils.sequelize.query(- `INSERT INTO "videoInfohash" ("infohash", "videoFileId") ` +- `SELECT safe_decode_hex("infoHash"), "id" FROM "videoFile" WHERE "infoHash" IS NOT NULL AND safe_decode_hex("infoHash") IS NOT NULL`,- { transaction }- )-- await utils.sequelize.query(`DROP FUNCTION safe_decode_hex(text);`, { transaction })- }-- // Dropping a column also drops indexes that only depend on it (the old GIN index, and "videoFile"."infoHash")- {- await utils.sequelize.query(- `ALTER TABLE "videoStreamingPlaylist" DROP COLUMN "p2pMediaLoaderInfohashes"`,- { transaction }- )- }-- {- await utils.sequelize.query(- `ALTER TABLE "videoFile" DROP COLUMN "infoHash"`,- { transaction }- )- }+ // Backfilling "videoInfohash" from the old columns, and dropping these columns,+ // is done in server/scripts/migrations/peertube-8.3.ts because it can take a while on big instances}function down () {diff --git a/server/core/initializers/migrations/1110-video-content-updated-at.ts b/server/core/initializers/migrations/1110-video-content-updated-at.tsindex cc5b6be021..98a51491ec 100644--- a/server/core/initializers/migrations/1110-video-content-updated-at.ts+++ b/server/core/initializers/migrations/1110-video-content-updated-at.ts@@ -5,15 +5,11 @@ async function up (utils: {queryInterface: Sequelize.QueryInterfacesequelize: Sequelize.Sequelize}): Promise<void> {+ // No need to update `sitemapContentUpdatedAt`, we'll use `publishedAt` by defaultawait utils.sequelize.query(`ALTER TABLE "video" ADD COLUMN IF NOT EXISTS "sitemapContentUpdatedAt" TIMESTAMP WITH TIME ZONE`,{ transaction: utils.transaction })-- await utils.sequelize.query(- `UPDATE "video" SET "sitemapContentUpdatedAt" = "updatedAt" WHERE "sitemapContentUpdatedAt" IS NULL`,- { transaction: utils.transaction }- )}function down (options) {diff --git a/server/scripts/migrations/peertube-8.3.ts b/server/scripts/migrations/peertube-8.3.tsindex fcd0a62020..e6d03c3fde 100644--- a/server/scripts/migrations/peertube-8.3.ts+++ b/server/scripts/migrations/peertube-8.3.ts@@ -9,6 +9,7 @@ run()async function run () {await fillVideoSearchTable()+ await migrateVideoInfohashes()}async function fillVideoSearchTable () {@@ -25,3 +26,41 @@ async function fillVideoSearchTable () {console.log('videoSearch table filled.\n')}++async function migrateVideoInfohashes () {+ const videoFileColumns = await sequelizeTypescript.getQueryInterface().describeTable('videoFile')+ if (!videoFileColumns['infoHash']) {+ console.log('Video infohashes already migrated, skipping.\n')+ return+ }++ console.log('Migrating video infohashes...')++ // Don't re-hydrate video streaming playlists infohash, PeerTube will re-generate them on the next startup++ // Classic infohash are stored as 40 char hex on the video file+ await sequelizeTypescript.query(`+ CREATE OR REPLACE FUNCTION safe_decode_hex(input text)+ RETURNS bytea AS $$+ BEGIN+ RETURN decode(input, 'hex');+ EXCEPTION+ WHEN others THEN+ RETURN NULL;+ END;+ $$ LANGUAGE plpgsql IMMUTABLE;+ `)++ await sequelizeTypescript.query(+ `INSERT INTO "videoInfohash" ("infohash", "videoFileId") ` ++ `SELECT safe_decode_hex("infoHash"), "id" FROM "videoFile" WHERE "infoHash" IS NOT NULL AND safe_decode_hex("infoHash") IS NOT NULL`+ )++ await sequelizeTypescript.query(`DROP FUNCTION safe_decode_hex(text);`)++ // Dropping a column also drops indexes that only depend on it (the old GIN index, and "videoFile"."infoHash")+ await sequelizeTypescript.query(`ALTER TABLE "videoStreamingPlaylist" DROP COLUMN IF EXISTS "p2pMediaLoaderInfohashes"`)+ await sequelizeTypescript.query(`ALTER TABLE "videoFile" DROP COLUMN IF EXISTS "infoHash"`)++ console.log('Video infohashes migrated.\n')+}