Add server migration for playlists

pull/3108/head
Chocobozzz 2020-08-18 11:09:00 +02:00 committed by Chocobozzz
parent 371906639e
commit cbb513e737
2 changed files with 47 additions and 1 deletions

View File

@ -23,7 +23,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
// ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 525
const LAST_MIGRATION_VERSION = 530
// ---------------------------------------------------------------------------

View File

@ -0,0 +1,46 @@
import * as Sequelize from 'sequelize'
import { WEBSERVER } from '../constants'
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
sequelize: Sequelize.Sequelize
}): Promise<void> {
{
const field = {
type: Sequelize.STRING,
allowNull: true
}
await utils.queryInterface.changeColumn('videoPlaylistElement', 'url', field)
}
{
await utils.sequelize.query('DROP INDEX IF EXISTS video_playlist_element_video_playlist_id_video_id;')
}
{
const selectPlaylistUUID = 'SELECT "uuid" FROM "videoPlaylist" WHERE "id" = "videoPlaylistElement"."videoPlaylistId"'
const url = `'${WEBSERVER.URL}' || '/video-playlists/' || (${selectPlaylistUUID}) || '/videos/' || "videoPlaylistElement"."id"`
const query = `
UPDATE "videoPlaylistElement" SET "url" = ${url} WHERE id IN (
SELECT "videoPlaylistElement"."id" FROM "videoPlaylistElement"
INNER JOIN "videoPlaylist" ON "videoPlaylist".id = "videoPlaylistElement"."videoPlaylistId"
INNER JOIN account ON account.id = "videoPlaylist"."ownerAccountId"
INNER JOIN actor ON actor.id = account."actorId"
WHERE actor."serverId" IS NULL
)`
await utils.sequelize.query(query)
}
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}