From 6fcd19ba737f1f5614a56c6925adb882dea43b8d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Jul 2017 13:26:25 +0200 Subject: Move to promises Closes https://github.com/Chocobozzz/PeerTube/issues/74 --- server/initializers/migrations/0005-email-pod.ts | 38 +++++++++------------ server/initializers/migrations/0010-email-user.ts | 39 +++++++++------------- server/initializers/migrations/0015-video-views.ts | 13 +++++--- server/initializers/migrations/0020-video-likes.ts | 13 +++++--- .../initializers/migrations/0025-video-dislikes.ts | 13 +++++--- .../initializers/migrations/0030-video-category.ts | 29 +++++++--------- .../initializers/migrations/0035-video-licence.ts | 30 +++++++---------- server/initializers/migrations/0040-video-nsfw.ts | 29 +++++++--------- .../migrations/0045-user-display-nsfw.ts | 13 +++++--- .../initializers/migrations/0050-video-language.ts | 13 +++++--- 10 files changed, 111 insertions(+), 119 deletions(-) (limited to 'server/initializers/migrations') diff --git a/server/initializers/migrations/0005-email-pod.ts b/server/initializers/migrations/0005-email-pod.ts index a9200c47f..ceefaad4a 100644 --- a/server/initializers/migrations/0005-email-pod.ts +++ b/server/initializers/migrations/0005-email-pod.ts @@ -1,9 +1,12 @@ -import { waterfall } from 'async' - -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.STRING(400), @@ -11,27 +14,16 @@ function up (utils, finalCallback) { defaultValue: '' } - waterfall([ - - function addEmailColumn (callback) { - q.addColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function updateWithFakeEmails (callback) { + return q.addColumn('Pods', 'email', data) + .then(() => { const query = 'UPDATE "Pods" SET "email" = \'dummy@example.com\'' - utils.sequelize.query(query, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function nullOnDefault (callback) { + return utils.sequelize.query(query, { transaction: utils.transaction }) + }) + .then(() => { data.defaultValue = null - q.changeColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(callback) - } - ], finalCallback) + return q.changeColumn('Pods', 'email', data) + }) } function down (options, callback) { 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 @@ -import { waterfall } from 'async' - -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.STRING(400), allowNull: false, defaultValue: '' } - - waterfall([ - - function addEmailColumn (callback) { - q.addColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function updateWithFakeEmails (callback) { + return q.addColumn('Users', 'email', data) + .then(() => { const query = 'UPDATE "Users" SET "email" = CONCAT("username", \'@example.com\')' - utils.sequelize.query(query, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function nullOnDefault (callback) { + return utils.sequelize.query(query, { transaction: utils.transaction }) + }) + .then(() => { data.defaultValue = null - q.changeColumn('Users', 'email', data, { transaction: utils.transaction }).asCallback(callback) - } - ], finalCallback) + return q.changeColumn('Users', 'email', data) + }) } function down (options, callback) { diff --git a/server/initializers/migrations/0015-video-views.ts b/server/initializers/migrations/0015-video-views.ts index e70869404..df274d817 100644 --- a/server/initializers/migrations/0015-video-views.ts +++ b/server/initializers/migrations/0015-video-views.ts @@ -1,7 +1,12 @@ -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.INTEGER, @@ -9,7 +14,7 @@ function up (utils, finalCallback) { defaultValue: 0 } - q.addColumn('Videos', 'views', data, { transaction: utils.transaction }).asCallback(finalCallback) + return q.addColumn('Videos', 'views', data) } function down (options, callback) { diff --git a/server/initializers/migrations/0020-video-likes.ts b/server/initializers/migrations/0020-video-likes.ts index e435d0657..3d7182d0a 100644 --- a/server/initializers/migrations/0020-video-likes.ts +++ b/server/initializers/migrations/0020-video-likes.ts @@ -1,7 +1,12 @@ -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.INTEGER, @@ -9,7 +14,7 @@ function up (utils, finalCallback) { defaultValue: 0 } - q.addColumn('Videos', 'likes', data, { transaction: utils.transaction }).asCallback(finalCallback) + return q.addColumn('Videos', 'likes', data) } function down (options, callback) { diff --git a/server/initializers/migrations/0025-video-dislikes.ts b/server/initializers/migrations/0025-video-dislikes.ts index 57e54e904..ed41095dc 100644 --- a/server/initializers/migrations/0025-video-dislikes.ts +++ b/server/initializers/migrations/0025-video-dislikes.ts @@ -1,7 +1,12 @@ -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.INTEGER, @@ -9,7 +14,7 @@ function up (utils, finalCallback) { defaultValue: 0 } - q.addColumn('Videos', 'dislikes', data, { transaction: utils.transaction }).asCallback(finalCallback) + return q.addColumn('Videos', 'dislikes', data) } function down (options, callback) { diff --git a/server/initializers/migrations/0030-video-category.ts b/server/initializers/migrations/0030-video-category.ts index 1073f449c..f5adee8f9 100644 --- a/server/initializers/migrations/0030-video-category.ts +++ b/server/initializers/migrations/0030-video-category.ts @@ -1,9 +1,12 @@ -import { waterfall } from 'async' - -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.INTEGER, @@ -11,20 +14,12 @@ function up (utils, finalCallback) { defaultValue: 0 } - waterfall([ - - function addCategoryColumn (callback) { - q.addColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function nullOnDefault (callback) { + return q.addColumn('Videos', 'category', data) + .then(() => { data.defaultValue = null - q.changeColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(callback) - } - ], finalCallback) + return q.changeColumn('Videos', 'category', data) + }) } function down (options, callback) { diff --git a/server/initializers/migrations/0035-video-licence.ts b/server/initializers/migrations/0035-video-licence.ts index 9316b3c37..00c64d8e7 100644 --- a/server/initializers/migrations/0035-video-licence.ts +++ b/server/initializers/migrations/0035-video-licence.ts @@ -1,9 +1,12 @@ -import { waterfall } from 'async' - -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.INTEGER, @@ -11,20 +14,11 @@ function up (utils, finalCallback) { defaultValue: 0 } - waterfall([ - - function addLicenceColumn (callback) { - q.addColumn('Videos', 'licence', data, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function nullOnDefault (callback) { + return q.addColumn('Videos', 'licence', data) + .then(() => { data.defaultValue = null - - q.changeColumn('Videos', 'licence', data, { transaction: utils.transaction }).asCallback(callback) - } - ], finalCallback) + return q.changeColumn('Videos', 'licence', data) + }) } function down (options, callback) { diff --git a/server/initializers/migrations/0040-video-nsfw.ts b/server/initializers/migrations/0040-video-nsfw.ts index c61f496f1..046876b61 100644 --- a/server/initializers/migrations/0040-video-nsfw.ts +++ b/server/initializers/migrations/0040-video-nsfw.ts @@ -1,9 +1,12 @@ -import { waterfall } from 'async' - -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.BOOLEAN, @@ -11,20 +14,12 @@ function up (utils, finalCallback) { defaultValue: false } - waterfall([ - - function addNSFWColumn (callback) { - q.addColumn('Videos', 'nsfw', data, { transaction: utils.transaction }).asCallback(function (err) { - return callback(err) - }) - }, - - function nullOnDefault (callback) { + return q.addColumn('Videos', 'nsfw', data) + .then(() => { data.defaultValue = null - q.changeColumn('Videos', 'nsfw', data, { transaction: utils.transaction }).asCallback(callback) - } - ], finalCallback) + return q.changeColumn('Videos', 'nsfw', data) + }) } function down (options, callback) { diff --git a/server/initializers/migrations/0045-user-display-nsfw.ts b/server/initializers/migrations/0045-user-display-nsfw.ts index 1ca317795..75bd3bbea 100644 --- a/server/initializers/migrations/0045-user-display-nsfw.ts +++ b/server/initializers/migrations/0045-user-display-nsfw.ts @@ -1,7 +1,12 @@ -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.BOOLEAN, @@ -9,7 +14,7 @@ function up (utils, finalCallback) { defaultValue: false } - q.addColumn('Users', 'displayNSFW', data, { transaction: utils.transaction }).asCallback(finalCallback) + return q.addColumn('Users', 'displayNSFW', data) } function down (options, callback) { diff --git a/server/initializers/migrations/0050-video-language.ts b/server/initializers/migrations/0050-video-language.ts index 95d0a473a..ed08f5866 100644 --- a/server/initializers/migrations/0050-video-language.ts +++ b/server/initializers/migrations/0050-video-language.ts @@ -1,7 +1,12 @@ -// utils = { transaction, queryInterface, sequelize, Sequelize } -function up (utils, finalCallback) { +import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' + +function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { const q = utils.queryInterface - const Sequelize = utils.Sequelize const data = { type: Sequelize.INTEGER, @@ -9,7 +14,7 @@ function up (utils, finalCallback) { defaultValue: null } - q.addColumn('Videos', 'language', data, { transaction: utils.transaction }).asCallback(finalCallback) + return q.addColumn('Videos', 'language', data) } function down (options, callback) { -- cgit v1.2.3