0600-duplicate-video-files.ts 880 B

123456789101112131415161718192021222324252627282930313233
  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 = 'DELETE FROM "videoFile" f1 ' +
  10. 'USING (SELECT MIN(id) as id, "torrentFilename" FROM "videoFile" GROUP BY "torrentFilename" HAVING COUNT(*) > 1) f2 ' +
  11. 'WHERE f1."torrentFilename" = f2."torrentFilename" AND f1.id <> f2.id'
  12. await utils.sequelize.query(query)
  13. }
  14. {
  15. const query = 'DELETE FROM "videoFile" f1 ' +
  16. 'USING (SELECT MIN(id) as id, "filename" FROM "videoFile" GROUP BY "filename" HAVING COUNT(*) > 1) f2 ' +
  17. 'WHERE f1."filename" = f2."filename" AND f1.id <> f2.id'
  18. await utils.sequelize.query(query)
  19. }
  20. }
  21. function down (options) {
  22. throw new Error('Not implemented.')
  23. }
  24. export {
  25. up,
  26. down
  27. }