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