0450-streaming-playlist-files.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as Sequelize from 'sequelize'
  2. async function up (utils: {
  3. transaction: Sequelize.Transaction
  4. queryInterface: Sequelize.QueryInterface
  5. sequelize: Sequelize.Sequelize
  6. db: any
  7. }): Promise<void> {
  8. {
  9. const data = {
  10. type: Sequelize.INTEGER,
  11. allowNull: true,
  12. references: {
  13. model: 'videoStreamingPlaylist',
  14. key: 'id'
  15. },
  16. onDelete: 'CASCADE'
  17. }
  18. await utils.queryInterface.addColumn('videoFile', 'videoStreamingPlaylistId', data)
  19. }
  20. {
  21. const data = {
  22. type: Sequelize.INTEGER,
  23. allowNull: true
  24. }
  25. await utils.queryInterface.changeColumn('videoFile', 'videoId', data)
  26. }
  27. {
  28. await utils.queryInterface.removeIndex('videoFile', 'video_file_video_id_resolution_fps')
  29. }
  30. {
  31. const query = 'insert into "videoFile" ' +
  32. '(resolution, size, "infoHash", "videoId", "createdAt", "updatedAt", fps, extname, "videoStreamingPlaylistId")' +
  33. '(SELECT "videoFile".resolution, "videoFile".size, \'fake\', NULL, "videoFile"."createdAt", "videoFile"."updatedAt", ' +
  34. '"videoFile"."fps", "videoFile".extname, "videoStreamingPlaylist".id FROM "videoStreamingPlaylist" ' +
  35. 'inner join video ON video.id = "videoStreamingPlaylist"."videoId" inner join "videoFile" ON "videoFile"."videoId" = video.id)'
  36. await utils.sequelize.query(query, { transaction: utils.transaction })
  37. }
  38. }
  39. function down (options) {
  40. throw new Error('Not implemented.')
  41. }
  42. export {
  43. up,
  44. down
  45. }