0010-email-user.ts 875 B

123456789101112131415161718192021222324252627282930313233343536
  1. import * as Sequelize from 'sequelize'
  2. import * as Promise from 'bluebird'
  3. import { Migration } from '../../models/migrations'
  4. function up (utils: {
  5. transaction: Sequelize.Transaction,
  6. queryInterface: Sequelize.QueryInterface,
  7. sequelize: Sequelize.Sequelize
  8. }): Promise<void> {
  9. const q = utils.queryInterface
  10. const data = {
  11. type: Sequelize.STRING(400),
  12. allowNull: false,
  13. defaultValue: ''
  14. } as Migration.String
  15. return q.addColumn('Users', 'email', data)
  16. .then(() => {
  17. const query = 'UPDATE "Users" SET "email" = CONCAT("username", \'@example.com\')'
  18. return utils.sequelize.query(query, { transaction: utils.transaction })
  19. })
  20. .then(() => {
  21. data.defaultValue = null
  22. return q.changeColumn('Users', 'email', data)
  23. })
  24. }
  25. function down (options) {
  26. throw new Error('Not implemented.')
  27. }
  28. export {
  29. up,
  30. down
  31. }