0200-video-published-at.ts 868 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.DATE,
  10. allowNull: true,
  11. defaultValue: Sequelize.NOW
  12. }
  13. await utils.queryInterface.addColumn('video', 'publishedAt', data)
  14. }
  15. {
  16. const query = 'UPDATE video SET "publishedAt" = video."createdAt"'
  17. await utils.sequelize.query(query)
  18. }
  19. // Sequelize does not alter the column with NOW as default value
  20. {
  21. const data = {
  22. type: Sequelize.DATE,
  23. allowNull: false,
  24. defaultValue: Sequelize.NOW
  25. }
  26. await utils.queryInterface.changeColumn('video', 'publishedAt', data)
  27. }
  28. }
  29. function down (options) {
  30. throw new Error('Not implemented.')
  31. }
  32. export {
  33. up,
  34. down
  35. }