diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-02-18 11:56:28 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-02-18 12:13:33 +0100 |
commit | 5804c0db337ecf492fc61b98a3de7b730a0d8ce3 (patch) | |
tree | 83c0e8d8f10ec0f9ca269624feaba48970a7a0e3 /server/initializers/migrations/0010-email-user.js | |
parent | c1a7ab7f04fdb1601cf1e41c4e372dbd3c81f3de (diff) | |
download | PeerTube-5804c0db337ecf492fc61b98a3de7b730a0d8ce3.tar.gz PeerTube-5804c0db337ecf492fc61b98a3de7b730a0d8ce3.tar.zst PeerTube-5804c0db337ecf492fc61b98a3de7b730a0d8ce3.zip |
Server: fix migration scripts
Diffstat (limited to 'server/initializers/migrations/0010-email-user.js')
-rw-r--r-- | server/initializers/migrations/0010-email-user.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/initializers/migrations/0010-email-user.js b/server/initializers/migrations/0010-email-user.js new file mode 100644 index 000000000..1ab27133a --- /dev/null +++ b/server/initializers/migrations/0010-email-user.js | |||
@@ -0,0 +1,41 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const waterfall = require('async/waterfall') | ||
4 | |||
5 | // utils = { transaction, queryInterface, sequelize, Sequelize } | ||
6 | exports.up = function (utils, finalCallback) { | ||
7 | const q = utils.queryInterface | ||
8 | const Sequelize = utils.Sequelize | ||
9 | |||
10 | const data = { | ||
11 | type: Sequelize.STRING(400), | ||
12 | allowNull: false, | ||
13 | defaultValue: '' | ||
14 | } | ||
15 | |||
16 | waterfall([ | ||
17 | |||
18 | function addEmailColumn (callback) { | ||
19 | q.addColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(function (err) { | ||
20 | return callback(err) | ||
21 | }) | ||
22 | }, | ||
23 | |||
24 | function updateWithFakeEmails (callback) { | ||
25 | const query = 'UPDATE "Users" SET "email" = CONCAT("username", \'@example.com\')' | ||
26 | utils.sequelize.query(query, { transaction: utils.transaction }).asCallback(function (err) { | ||
27 | return callback(err) | ||
28 | }) | ||
29 | }, | ||
30 | |||
31 | function nullOnDefault (callback) { | ||
32 | data.defaultValue = null | ||
33 | |||
34 | q.changeColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(callback) | ||
35 | } | ||
36 | ], finalCallback) | ||
37 | } | ||
38 | |||
39 | exports.down = function (options, callback) { | ||
40 | throw new Error('Not implemented.') | ||
41 | } | ||