aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /server/initializers/migrations
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0005-email-pod.ts38
-rw-r--r--server/initializers/migrations/0010-email-user.ts39
-rw-r--r--server/initializers/migrations/0015-video-views.ts13
-rw-r--r--server/initializers/migrations/0020-video-likes.ts13
-rw-r--r--server/initializers/migrations/0025-video-dislikes.ts13
-rw-r--r--server/initializers/migrations/0030-video-category.ts29
-rw-r--r--server/initializers/migrations/0035-video-licence.ts30
-rw-r--r--server/initializers/migrations/0040-video-nsfw.ts29
-rw-r--r--server/initializers/migrations/0045-user-display-nsfw.ts13
-rw-r--r--server/initializers/migrations/0050-video-language.ts13
10 files changed, 111 insertions, 119 deletions
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 @@
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),
@@ -11,27 +14,16 @@ function up (utils, finalCallback) {
11 defaultValue: '' 14 defaultValue: ''
12 } 15 }
13 16
14 waterfall([ 17 return q.addColumn('Pods', 'email', data)
15 18 .then(() => {
16 function addEmailColumn (callback) {
17 q.addColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(function (err) {
18 return callback(err)
19 })
20 },
21
22 function updateWithFakeEmails (callback) {
23 const query = 'UPDATE "Pods" SET "email" = \'dummy@example.com\'' 19 const query = 'UPDATE "Pods" SET "email" = \'dummy@example.com\''
24 utils.sequelize.query(query, { transaction: utils.transaction }).asCallback(function (err) { 20 return utils.sequelize.query(query, { transaction: utils.transaction })
25 return callback(err) 21 })
26 }) 22 .then(() => {
27 },
28
29 function nullOnDefault (callback) {
30 data.defaultValue = null 23 data.defaultValue = null
31 24
32 q.changeColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(callback) 25 return q.changeColumn('Pods', 'email', data)
33 } 26 })
34 ], finalCallback)
35} 27}
36 28
37function down (options, callback) { 29function 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 @@
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) {
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 @@
1// utils = { transaction, queryInterface, sequelize, Sequelize } 1import * as Sequelize from 'sequelize'
2function up (utils, finalCallback) { 2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
3 const q = utils.queryInterface 9 const q = utils.queryInterface
4 const Sequelize = utils.Sequelize
5 10
6 const data = { 11 const data = {
7 type: Sequelize.INTEGER, 12 type: Sequelize.INTEGER,
@@ -9,7 +14,7 @@ function up (utils, finalCallback) {
9 defaultValue: 0 14 defaultValue: 0
10 } 15 }
11 16
12 q.addColumn('Videos', 'views', data, { transaction: utils.transaction }).asCallback(finalCallback) 17 return q.addColumn('Videos', 'views', data)
13} 18}
14 19
15function down (options, callback) { 20function 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 @@
1// utils = { transaction, queryInterface, sequelize, Sequelize } 1import * as Sequelize from 'sequelize'
2function up (utils, finalCallback) { 2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
3 const q = utils.queryInterface 9 const q = utils.queryInterface
4 const Sequelize = utils.Sequelize
5 10
6 const data = { 11 const data = {
7 type: Sequelize.INTEGER, 12 type: Sequelize.INTEGER,
@@ -9,7 +14,7 @@ function up (utils, finalCallback) {
9 defaultValue: 0 14 defaultValue: 0
10 } 15 }
11 16
12 q.addColumn('Videos', 'likes', data, { transaction: utils.transaction }).asCallback(finalCallback) 17 return q.addColumn('Videos', 'likes', data)
13} 18}
14 19
15function down (options, callback) { 20function 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 @@
1// utils = { transaction, queryInterface, sequelize, Sequelize } 1import * as Sequelize from 'sequelize'
2function up (utils, finalCallback) { 2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
3 const q = utils.queryInterface 9 const q = utils.queryInterface
4 const Sequelize = utils.Sequelize
5 10
6 const data = { 11 const data = {
7 type: Sequelize.INTEGER, 12 type: Sequelize.INTEGER,
@@ -9,7 +14,7 @@ function up (utils, finalCallback) {
9 defaultValue: 0 14 defaultValue: 0
10 } 15 }
11 16
12 q.addColumn('Videos', 'dislikes', data, { transaction: utils.transaction }).asCallback(finalCallback) 17 return q.addColumn('Videos', 'dislikes', data)
13} 18}
14 19
15function down (options, callback) { 20function 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 @@
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.INTEGER, 12 type: Sequelize.INTEGER,
@@ -11,20 +14,12 @@ function up (utils, finalCallback) {
11 defaultValue: 0 14 defaultValue: 0
12 } 15 }
13 16
14 waterfall([ 17 return q.addColumn('Videos', 'category', data)
15 18 .then(() => {
16 function addCategoryColumn (callback) {
17 q.addColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(function (err) {
18 return callback(err)
19 })
20 },
21
22 function nullOnDefault (callback) {
23 data.defaultValue = null 19 data.defaultValue = null
24 20
25 q.changeColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(callback) 21 return q.changeColumn('Videos', 'category', data)
26 } 22 })
27 ], finalCallback)
28} 23}
29 24
30function down (options, callback) { 25function 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 @@
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.INTEGER, 12 type: Sequelize.INTEGER,
@@ -11,20 +14,11 @@ function up (utils, finalCallback) {
11 defaultValue: 0 14 defaultValue: 0
12 } 15 }
13 16
14 waterfall([ 17 return q.addColumn('Videos', 'licence', data)
15 18 .then(() => {
16 function addLicenceColumn (callback) {
17 q.addColumn('Videos', 'licence', data, { transaction: utils.transaction }).asCallback(function (err) {
18 return callback(err)
19 })
20 },
21
22 function nullOnDefault (callback) {
23 data.defaultValue = null 19 data.defaultValue = null
24 20 return q.changeColumn('Videos', 'licence', data)
25 q.changeColumn('Videos', 'licence', data, { transaction: utils.transaction }).asCallback(callback) 21 })
26 }
27 ], finalCallback)
28} 22}
29 23
30function down (options, callback) { 24function 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 @@
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.BOOLEAN, 12 type: Sequelize.BOOLEAN,
@@ -11,20 +14,12 @@ function up (utils, finalCallback) {
11 defaultValue: false 14 defaultValue: false
12 } 15 }
13 16
14 waterfall([ 17 return q.addColumn('Videos', 'nsfw', data)
15 18 .then(() => {
16 function addNSFWColumn (callback) {
17 q.addColumn('Videos', 'nsfw', data, { transaction: utils.transaction }).asCallback(function (err) {
18 return callback(err)
19 })
20 },
21
22 function nullOnDefault (callback) {
23 data.defaultValue = null 19 data.defaultValue = null
24 20
25 q.changeColumn('Videos', 'nsfw', data, { transaction: utils.transaction }).asCallback(callback) 21 return q.changeColumn('Videos', 'nsfw', data)
26 } 22 })
27 ], finalCallback)
28} 23}
29 24
30function down (options, callback) { 25function 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 @@
1// utils = { transaction, queryInterface, sequelize, Sequelize } 1import * as Sequelize from 'sequelize'
2function up (utils, finalCallback) { 2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
3 const q = utils.queryInterface 9 const q = utils.queryInterface
4 const Sequelize = utils.Sequelize
5 10
6 const data = { 11 const data = {
7 type: Sequelize.BOOLEAN, 12 type: Sequelize.BOOLEAN,
@@ -9,7 +14,7 @@ function up (utils, finalCallback) {
9 defaultValue: false 14 defaultValue: false
10 } 15 }
11 16
12 q.addColumn('Users', 'displayNSFW', data, { transaction: utils.transaction }).asCallback(finalCallback) 17 return q.addColumn('Users', 'displayNSFW', data)
13} 18}
14 19
15function down (options, callback) { 20function 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 @@
1// utils = { transaction, queryInterface, sequelize, Sequelize } 1import * as Sequelize from 'sequelize'
2function up (utils, finalCallback) { 2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
3 const q = utils.queryInterface 9 const q = utils.queryInterface
4 const Sequelize = utils.Sequelize
5 10
6 const data = { 11 const data = {
7 type: Sequelize.INTEGER, 12 type: Sequelize.INTEGER,
@@ -9,7 +14,7 @@ function up (utils, finalCallback) {
9 defaultValue: null 14 defaultValue: null
10 } 15 }
11 16
12 q.addColumn('Videos', 'language', data, { transaction: utils.transaction }).asCallback(finalCallback) 17 return q.addColumn('Videos', 'language', data)
13} 18}
14 19
15function down (options, callback) { 20function down (options, callback) {