0795-duplicate-runner-name.ts 580 B

123456789101112131415161718192021222324
  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. const { transaction } = utils
  8. const query = 'DELETE FROM "runner" r1 ' +
  9. 'USING (SELECT MIN(id) as id, "name" FROM "runner" GROUP BY "name" HAVING COUNT(*) > 1) r2 ' +
  10. 'WHERE r1."name" = r2."name" AND r1.id <> r2.id'
  11. await utils.sequelize.query(query, { transaction })
  12. }
  13. function down (options) {
  14. throw new Error('Not implemented.')
  15. }
  16. export {
  17. up,
  18. down
  19. }