0190-video-comment-unique-url.ts 553 B

1234567891011121314151617181920212223
  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 "videoComment" s1 ' +
  9. 'USING (SELECT MIN(id) as id, url FROM "videoComment" GROUP BY "url" HAVING COUNT(*) > 1) s2 ' +
  10. 'WHERE s1."url" = s2."url" AND s1.id <> s2.id'
  11. await utils.sequelize.query(query)
  12. }
  13. }
  14. function down (options) {
  15. throw new Error('Not implemented.')
  16. }
  17. export {
  18. up,
  19. down
  20. }