0370-thumbnail.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 query = `
  10. CREATE TABLE IF NOT EXISTS "thumbnail"
  11. (
  12. "id" SERIAL,
  13. "filename" VARCHAR(255) NOT NULL,
  14. "height" INTEGER DEFAULT NULL,
  15. "width" INTEGER DEFAULT NULL,
  16. "type" INTEGER NOT NULL,
  17. "fileUrl" VARCHAR(255),
  18. "videoId" INTEGER REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
  19. "videoPlaylistId" INTEGER REFERENCES "videoPlaylist" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
  20. "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
  21. "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
  22. PRIMARY KEY ("id")
  23. );`
  24. await utils.sequelize.query(query)
  25. }
  26. {
  27. // All video thumbnails
  28. const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' +
  29. 'SELECT uuid || \'.jpg\', 1, id, 110, 200, NOW(), NOW() FROM "video"'
  30. await utils.sequelize.query(query)
  31. }
  32. {
  33. // All video previews
  34. const query = 'INSERT INTO "thumbnail" ("filename", "type", "videoId", "height", "width", "createdAt", "updatedAt")' +
  35. 'SELECT uuid || \'.jpg\', 2, id, 315, 560, NOW(), NOW() FROM "video"'
  36. await utils.sequelize.query(query)
  37. }
  38. }
  39. function down (options) {
  40. throw new Error('Not implemented.')
  41. }
  42. export {
  43. up,
  44. down
  45. }