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

0520-abuses-split.ts 2.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. await utils.queryInterface.renameTable('videoAbuse', 'abuse')
  8. await utils.sequelize.query(`
  9. ALTER TABLE "abuse"
  10. ADD COLUMN "flaggedAccountId" INTEGER REFERENCES "account" ("id") ON DELETE SET NULL ON UPDATE CASCADE
  11. `)
  12. await utils.sequelize.query(`
  13. UPDATE "abuse" SET "videoId" = NULL
  14. WHERE "videoId" NOT IN (SELECT "id" FROM "video")
  15. `)
  16. await utils.sequelize.query(`
  17. UPDATE "abuse" SET "flaggedAccountId" = "videoChannel"."accountId"
  18. FROM "video" INNER JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id"
  19. WHERE "abuse"."videoId" = "video"."id"
  20. `)
  21. await utils.sequelize.query('DROP INDEX IF EXISTS video_abuse_video_id;')
  22. await utils.sequelize.query('DROP INDEX IF EXISTS video_abuse_reporter_account_id;')
  23. await utils.sequelize.query(`
  24. CREATE TABLE IF NOT EXISTS "videoAbuse" (
  25. "id" serial,
  26. "startAt" integer DEFAULT NULL,
  27. "endAt" integer DEFAULT NULL,
  28. "deletedVideo" jsonb DEFAULT NULL,
  29. "abuseId" integer NOT NULL REFERENCES "abuse" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
  30. "videoId" integer REFERENCES "video" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
  31. "createdAt" TIMESTAMP WITH time zone NOT NULL,
  32. "updatedAt" timestamp WITH time zone NOT NULL,
  33. PRIMARY KEY ("id")
  34. );
  35. `)
  36. await utils.sequelize.query(`
  37. CREATE TABLE IF NOT EXISTS "commentAbuse" (
  38. "id" serial,
  39. "abuseId" integer NOT NULL REFERENCES "abuse" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
  40. "videoCommentId" integer REFERENCES "videoComment" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
  41. "createdAt" timestamp WITH time zone NOT NULL,
  42. "updatedAt" timestamp WITH time zone NOT NULL,
  43. PRIMARY KEY ("id")
  44. );
  45. `)
  46. await utils.sequelize.query(`
  47. INSERT INTO "videoAbuse" ("startAt", "endAt", "deletedVideo", "abuseId", "videoId", "createdAt", "updatedAt")
  48. SELECT "abuse"."startAt", "abuse"."endAt", "abuse"."deletedVideo", "abuse"."id", "abuse"."videoId",
  49. "abuse"."createdAt", "abuse"."updatedAt"
  50. FROM "abuse"
  51. `)
  52. await utils.queryInterface.removeColumn('abuse', 'startAt')
  53. await utils.queryInterface.removeColumn('abuse', 'endAt')
  54. await utils.queryInterface.removeColumn('abuse', 'deletedVideo')
  55. await utils.queryInterface.removeColumn('abuse', 'videoId')
  56. await utils.sequelize.query('DROP INDEX IF EXISTS user_notification_video_abuse_id')
  57. await utils.queryInterface.renameColumn('userNotification', 'videoAbuseId', 'abuseId')
  58. await utils.sequelize.query(
  59. 'ALTER INDEX IF EXISTS "videoAbuse_pkey" RENAME TO "abuse_pkey"'
  60. )
  61. await utils.queryInterface.renameColumn('userNotificationSetting', 'videoAbuseAsModerator', 'abuseAsModerator')
  62. }
  63. function down (options) {
  64. throw new Error('Not implemented.')
  65. }
  66. export {
  67. up,
  68. down
  69. }