2
1

0185-video-share-url.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as Sequelize from 'sequelize'
  2. async function up (utils: {
  3. transaction: Sequelize.Transaction,
  4. queryInterface: Sequelize.QueryInterface,
  5. sequelize: Sequelize.Sequelize
  6. }): Promise<void> {
  7. {
  8. const query = 'DELETE FROM "videoShare" s1 ' +
  9. 'USING (SELECT MIN(id) as id, "actorId", "videoId" FROM "videoShare" GROUP BY "actorId", "videoId" HAVING COUNT(*) > 1) s2 ' +
  10. 'WHERE s1."actorId" = s2."actorId" AND s1."videoId" = s2."videoId" AND s1.id <> s2.id'
  11. await utils.sequelize.query(query)
  12. }
  13. {
  14. const data = {
  15. type: Sequelize.STRING,
  16. allowNull: true,
  17. defaultValue: null
  18. }
  19. await utils.queryInterface.addColumn('videoShare', 'url', data)
  20. const query = `UPDATE "videoShare" SET "url" = (SELECT "url" FROM "video" WHERE "id" = "videoId") || '/announces/' || "actorId"`
  21. await utils.sequelize.query(query)
  22. data.allowNull = false
  23. await utils.queryInterface.changeColumn('videoShare', 'url', data)
  24. }
  25. }
  26. function down (options) {
  27. throw new Error('Not implemented.')
  28. }
  29. export {
  30. up,
  31. down
  32. }