aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-18 11:09:00 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-19 11:30:21 +0200
commitcbb513e737bfca3ad3dbd43ad9614968e6e207cf (patch)
tree50bc30a7db992f0ee5971366b4b0287a9d7fa790 /server/initializers/migrations
parent371906639ee9b6ea4daae504bc7c2b15856c3f38 (diff)
downloadPeerTube-cbb513e737bfca3ad3dbd43ad9614968e6e207cf.tar.gz
PeerTube-cbb513e737bfca3ad3dbd43ad9614968e6e207cf.tar.zst
PeerTube-cbb513e737bfca3ad3dbd43ad9614968e6e207cf.zip
Add server migration for playlists
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0530-playlist-multiple-video.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/server/initializers/migrations/0530-playlist-multiple-video.ts b/server/initializers/migrations/0530-playlist-multiple-video.ts
new file mode 100644
index 000000000..51a8c06b0
--- /dev/null
+++ b/server/initializers/migrations/0530-playlist-multiple-video.ts
@@ -0,0 +1,46 @@
1import * as Sequelize from 'sequelize'
2import { WEBSERVER } from '../constants'
3
4async function up (utils: {
5 transaction: Sequelize.Transaction
6 queryInterface: Sequelize.QueryInterface
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
9 {
10 const field = {
11 type: Sequelize.STRING,
12 allowNull: true
13 }
14 await utils.queryInterface.changeColumn('videoPlaylistElement', 'url', field)
15 }
16
17 {
18 await utils.sequelize.query('DROP INDEX IF EXISTS video_playlist_element_video_playlist_id_video_id;')
19 }
20
21 {
22 const selectPlaylistUUID = 'SELECT "uuid" FROM "videoPlaylist" WHERE "id" = "videoPlaylistElement"."videoPlaylistId"'
23 const url = `'${WEBSERVER.URL}' || '/video-playlists/' || (${selectPlaylistUUID}) || '/videos/' || "videoPlaylistElement"."id"`
24
25 const query = `
26 UPDATE "videoPlaylistElement" SET "url" = ${url} WHERE id IN (
27 SELECT "videoPlaylistElement"."id" FROM "videoPlaylistElement"
28 INNER JOIN "videoPlaylist" ON "videoPlaylist".id = "videoPlaylistElement"."videoPlaylistId"
29 INNER JOIN account ON account.id = "videoPlaylist"."ownerAccountId"
30 INNER JOIN actor ON actor.id = account."actorId"
31 WHERE actor."serverId" IS NULL
32 )`
33
34 await utils.sequelize.query(query)
35 }
36
37}
38
39function down (options) {
40 throw new Error('Not implemented.')
41}
42
43export {
44 up,
45 down
46}