0305-fix-unfederated-videos.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` +
  10. `(` +
  11. `SELECT ` +
  12. `video.url || '/announces/' || "videoChannel"."actorId" as url, ` +
  13. `"videoChannel"."actorId" AS "actorId", ` +
  14. `"video"."id" AS "videoId", ` +
  15. `NOW() AS "createdAt", ` +
  16. `NOW() AS "updatedAt" ` +
  17. `FROM video ` +
  18. `INNER JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id" ` +
  19. `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` +
  20. `) ` +
  21. `ON CONFLICT DO NOTHING`
  22. await utils.sequelize.query(query)
  23. }
  24. {
  25. const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` +
  26. `(` +
  27. `SELECT ` +
  28. `video.url || '/announces/' || (SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) as url, ` +
  29. `(SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) AS "actorId", ` +
  30. `"video"."id" AS "videoId", ` +
  31. `NOW() AS "createdAt", ` +
  32. `NOW() AS "updatedAt" ` +
  33. `FROM video ` +
  34. `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` +
  35. `) ` +
  36. `ON CONFLICT DO NOTHING`
  37. await utils.sequelize.query(query)
  38. }
  39. }
  40. function down (options) {
  41. throw new Error('Not implemented.')
  42. }
  43. export {
  44. up,
  45. down
  46. }