ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0640-unique-keys.ts 1.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839
  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. await utils.sequelize.query(
  10. 'DELETE FROM "actor" v1 USING (SELECT MIN(id) as id, "preferredUsername", "serverId" FROM "actor" ' +
  11. 'GROUP BY "preferredUsername", "serverId" HAVING COUNT(*) > 1 AND "serverId" IS NOT NULL) v2 ' +
  12. 'WHERE v1."preferredUsername" = v2."preferredUsername" AND v1."serverId" = v2."serverId" AND v1.id <> v2.id'
  13. )
  14. }
  15. {
  16. await utils.sequelize.query(
  17. 'DELETE FROM "actor" v1 USING (SELECT MIN(id) as id, "url" FROM "actor" GROUP BY "url" HAVING COUNT(*) > 1) v2 ' +
  18. 'WHERE v1."url" = v2."url" AND v1.id <> v2.id'
  19. )
  20. }
  21. {
  22. await utils.sequelize.query(
  23. 'DELETE FROM "tag" v1 USING (SELECT MIN(id) as id, "name" FROM "tag" GROUP BY "name" HAVING COUNT(*) > 1) v2 ' +
  24. 'WHERE v1."name" = v2."name" AND v1.id <> v2.id'
  25. )
  26. }
  27. }
  28. function down (options) {
  29. throw new Error('Not implemented.')
  30. }
  31. export {
  32. up,
  33. down
  34. }