0010-email-user.ts 837 B

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