0275-video-file-unique.ts 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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<any> {
  7. // Delete duplicated keys
  8. {
  9. const query = 'DELETE FROM "server" s1 USING "server" s2 WHERE s1.id < s2.id AND s1."host" = s2."host"'
  10. await utils.sequelize.query(query)
  11. }
  12. {
  13. const query = 'DELETE FROM "videoFile" vf1 USING "videoFile" vf2 WHERE vf1.id < vf2.id ' +
  14. 'AND vf1."videoId" = vf2."videoId" AND vf1.resolution = vf2.resolution AND vf1.fps IS NULL'
  15. await utils.sequelize.query(query)
  16. }
  17. {
  18. const query = 'UPDATE "videoFile" SET fps = -1 WHERE fps IS NULL;'
  19. await utils.sequelize.query(query)
  20. }
  21. {
  22. const data = {
  23. type: Sequelize.INTEGER,
  24. allowNull: false,
  25. defaultValue: -1
  26. }
  27. await utils.queryInterface.changeColumn('videoFile', 'fps', data)
  28. }
  29. }
  30. function down (options) {
  31. throw new Error('Not implemented.')
  32. }
  33. export { up, down }