0205-user-nsfw-policy.ts 970 B

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. }): Promise<void> {
  7. {
  8. const data = {
  9. type: Sequelize.ENUM('do_not_list', 'blur', 'display'),
  10. allowNull: true,
  11. defaultValue: null
  12. }
  13. await utils.queryInterface.addColumn('user', 'nsfwPolicy', data)
  14. }
  15. {
  16. const query = 'UPDATE "user" SET "nsfwPolicy" = \'do_not_list\''
  17. await utils.sequelize.query(query)
  18. }
  19. {
  20. const query = 'UPDATE "user" SET "nsfwPolicy" = \'display\' WHERE "displayNSFW" = true'
  21. await utils.sequelize.query(query)
  22. }
  23. {
  24. const query = 'ALTER TABLE "user" ALTER COLUMN "nsfwPolicy" SET NOT NULL'
  25. await utils.sequelize.query(query)
  26. }
  27. {
  28. await utils.queryInterface.removeColumn('user', 'displayNSFW')
  29. }
  30. }
  31. function down (options) {
  32. throw new Error('Not implemented.')
  33. }
  34. export {
  35. up,
  36. down
  37. }