0290-account-video-rate-url.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 data = {
  10. type: Sequelize.STRING(2000),
  11. allowNull: true
  12. }
  13. await utils.queryInterface.addColumn('accountVideoRate', 'url', data)
  14. }
  15. {
  16. const builtUrlQuery = `SELECT "actor"."url" || '/' || "accountVideoRate"."type" || 's/' || "videoId" ` +
  17. 'FROM "accountVideoRate" ' +
  18. 'INNER JOIN account ON account.id = "accountVideoRate"."accountId" ' +
  19. 'INNER JOIN actor ON actor.id = account."actorId" ' +
  20. 'WHERE "base".id = "accountVideoRate".id'
  21. const query = 'UPDATE "accountVideoRate" base SET "url" = (' + builtUrlQuery + ') WHERE "url" IS NULL'
  22. await utils.sequelize.query(query)
  23. }
  24. {
  25. const data = {
  26. type: Sequelize.STRING(2000),
  27. allowNull: false,
  28. defaultValue: null
  29. }
  30. await utils.queryInterface.changeColumn('accountVideoRate', 'url', data)
  31. }
  32. }
  33. function down (options) {
  34. throw new Error('Not implemented.')
  35. }
  36. export {
  37. up,
  38. down
  39. }