diff options
Diffstat (limited to 'server/initializers/migrations/0010-email-user.ts')
-rw-r--r-- | server/initializers/migrations/0010-email-user.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/server/initializers/migrations/0010-email-user.ts b/server/initializers/migrations/0010-email-user.ts new file mode 100644 index 000000000..4b5d29394 --- /dev/null +++ b/server/initializers/migrations/0010-email-user.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import { waterfall } from 'async' | ||
2 | |||
3 | // utils = { transaction, queryInterface, sequelize, Sequelize } | ||
4 | function up (utils, finalCallback) { | ||
5 | const q = utils.queryInterface | ||
6 | const Sequelize = utils.Sequelize | ||
7 | |||
8 | const data = { | ||
9 | type: Sequelize.STRING(400), | ||
10 | allowNull: false, | ||
11 | defaultValue: '' | ||
12 | } | ||
13 | |||
14 | waterfall([ | ||
15 | |||
16 | function addEmailColumn (callback) { | ||
17 | q.addColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(function (err) { | ||
18 | return callback(err) | ||
19 | }) | ||
20 | }, | ||
21 | |||
22 | function updateWithFakeEmails (callback) { | ||
23 | const query = 'UPDATE "Users" SET "email" = CONCAT("username", \'@example.com\')' | ||
24 | utils.sequelize.query(query, { transaction: utils.transaction }).asCallback(function (err) { | ||
25 | return callback(err) | ||
26 | }) | ||
27 | }, | ||
28 | |||
29 | function nullOnDefault (callback) { | ||
30 | data.defaultValue = null | ||
31 | |||
32 | q.changeColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(callback) | ||
33 | } | ||
34 | ], finalCallback) | ||
35 | } | ||
36 | |||
37 | function down (options, callback) { | ||
38 | throw new Error('Not implemented.') | ||
39 | } | ||
40 | |||
41 | export { | ||
42 | up, | ||
43 | down | ||
44 | } | ||