0530-playlist-multiple-video.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as Sequelize from 'sequelize'
  2. import { WEBSERVER } from '../constants'
  3. async function up (utils: {
  4. transaction: Sequelize.Transaction
  5. queryInterface: Sequelize.QueryInterface
  6. sequelize: Sequelize.Sequelize
  7. }): Promise<void> {
  8. {
  9. const field = {
  10. type: Sequelize.STRING,
  11. allowNull: true
  12. }
  13. await utils.queryInterface.changeColumn('videoPlaylistElement', 'url', field)
  14. }
  15. {
  16. await utils.sequelize.query('DROP INDEX IF EXISTS video_playlist_element_video_playlist_id_video_id;')
  17. }
  18. {
  19. const selectPlaylistUUID = 'SELECT "uuid" FROM "videoPlaylist" WHERE "id" = "videoPlaylistElement"."videoPlaylistId"'
  20. const url = `'${WEBSERVER.URL}' || '/video-playlists/' || (${selectPlaylistUUID}) || '/videos/' || "videoPlaylistElement"."id"`
  21. const query = `
  22. UPDATE "videoPlaylistElement" SET "url" = ${url} WHERE id IN (
  23. SELECT "videoPlaylistElement"."id" FROM "videoPlaylistElement"
  24. INNER JOIN "videoPlaylist" ON "videoPlaylist".id = "videoPlaylistElement"."videoPlaylistId"
  25. INNER JOIN account ON account.id = "videoPlaylist"."ownerAccountId"
  26. INNER JOIN actor ON actor.id = account."actorId"
  27. WHERE actor."serverId" IS NULL
  28. )`
  29. await utils.sequelize.query(query)
  30. }
  31. }
  32. function down (options) {
  33. throw new Error('Not implemented.')
  34. }
  35. export {
  36. up,
  37. down
  38. }