aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0010-email-user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/migrations/0010-email-user.ts')
-rw-r--r--server/initializers/migrations/0010-email-user.ts39
1 files changed, 15 insertions, 24 deletions
diff --git a/server/initializers/migrations/0010-email-user.ts b/server/initializers/migrations/0010-email-user.ts
index 4b5d29394..e8865acdb 100644
--- a/server/initializers/migrations/0010-email-user.ts
+++ b/server/initializers/migrations/0010-email-user.ts
@@ -1,37 +1,28 @@
1import { waterfall } from 'async' 1import * as Sequelize from 'sequelize'
2 2import * as Promise from 'bluebird'
3// utils = { transaction, queryInterface, sequelize, Sequelize } 3
4function up (utils, finalCallback) { 4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
5 const q = utils.queryInterface 9 const q = utils.queryInterface
6 const Sequelize = utils.Sequelize
7 10
8 const data = { 11 const data = {
9 type: Sequelize.STRING(400), 12 type: Sequelize.STRING(400),
10 allowNull: false, 13 allowNull: false,
11 defaultValue: '' 14 defaultValue: ''
12 } 15 }
13 16 return q.addColumn('Users', 'email', data)
14 waterfall([ 17 .then(() => {
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\')' 18 const query = 'UPDATE "Users" SET "email" = CONCAT("username", \'@example.com\')'
24 utils.sequelize.query(query, { transaction: utils.transaction }).asCallback(function (err) { 19 return utils.sequelize.query(query, { transaction: utils.transaction })
25 return callback(err) 20 })
26 }) 21 .then(() => {
27 },
28
29 function nullOnDefault (callback) {
30 data.defaultValue = null 22 data.defaultValue = null
31 23
32 q.changeColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(callback) 24 return q.changeColumn('Users', 'email', data)
33 } 25 })
34 ], finalCallback)
35} 26}
36 27
37function down (options, callback) { 28function down (options, callback) {