ニジカ投稿局 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.

0560-user-feed-token.ts 1.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as Sequelize from 'sequelize'
  2. import { buildUUID } from '@peertube/peertube-node-utils'
  3. async function up (utils: {
  4. transaction: Sequelize.Transaction
  5. queryInterface: Sequelize.QueryInterface
  6. sequelize: Sequelize.Sequelize
  7. db: any
  8. }): Promise<void> {
  9. const q = utils.queryInterface
  10. {
  11. // Create uuid column for users
  12. const userFeedTokenUUID = {
  13. type: Sequelize.UUID,
  14. defaultValue: Sequelize.UUIDV4,
  15. allowNull: true
  16. }
  17. await q.addColumn('user', 'feedToken', userFeedTokenUUID)
  18. }
  19. // Set UUID to previous users
  20. {
  21. const query = 'SELECT * FROM "user" WHERE "feedToken" IS NULL'
  22. const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
  23. const users = await utils.sequelize.query<any>(query, options)
  24. for (const user of users) {
  25. const queryUpdate = `UPDATE "user" SET "feedToken" = '${buildUUID()}' WHERE id = ${user.id}`
  26. await utils.sequelize.query(queryUpdate)
  27. }
  28. }
  29. {
  30. const userFeedTokenUUID = {
  31. type: Sequelize.UUID,
  32. defaultValue: Sequelize.UUIDV4,
  33. allowNull: false
  34. }
  35. await q.changeColumn('user', 'feedToken', userFeedTokenUUID)
  36. }
  37. }
  38. function down (options) {
  39. throw new Error('Not implemented.')
  40. }
  41. export {
  42. up,
  43. down
  44. }