diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/initializers | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/checker.ts (renamed from server/initializers/checker.js) | 24 | ||||
-rw-r--r-- | server/initializers/constants.ts (renamed from server/initializers/constants.js) | 52 | ||||
-rw-r--r-- | server/initializers/database.ts (renamed from server/initializers/database.js) | 51 | ||||
-rw-r--r-- | server/initializers/index.ts | 6 | ||||
-rw-r--r-- | server/initializers/installer.ts (renamed from server/initializers/installer.js) | 44 | ||||
-rw-r--r-- | server/initializers/migrations/0005-email-pod.ts (renamed from server/initializers/migrations/0005-email-pod.js) | 13 | ||||
-rw-r--r-- | server/initializers/migrations/0010-email-user.ts (renamed from server/initializers/migrations/0010-email-user.js) | 13 | ||||
-rw-r--r-- | server/initializers/migrations/0015-video-views.ts (renamed from server/initializers/migrations/0015-video-views.js) | 11 | ||||
-rw-r--r-- | server/initializers/migrations/0020-video-likes.ts (renamed from server/initializers/migrations/0020-video-likes.js) | 11 | ||||
-rw-r--r-- | server/initializers/migrations/0025-video-dislikes.ts (renamed from server/initializers/migrations/0025-video-dislikes.js) | 11 | ||||
-rw-r--r-- | server/initializers/migrations/0030-video-category.ts (renamed from server/initializers/migrations/0030-video-category.js) | 13 | ||||
-rw-r--r-- | server/initializers/migrations/0035-video-licence.ts (renamed from server/initializers/migrations/0035-video-licence.js) | 13 | ||||
-rw-r--r-- | server/initializers/migrations/0040-video-nsfw.ts (renamed from server/initializers/migrations/0040-video-nsfw.js) | 13 | ||||
-rw-r--r-- | server/initializers/migrations/0045-user-display-nsfw.ts (renamed from server/initializers/migrations/0045-user-display-nsfw.js) | 11 | ||||
-rw-r--r-- | server/initializers/migrations/0050-video-language.ts (renamed from server/initializers/migrations/0050-video-language.js) | 11 | ||||
-rw-r--r-- | server/initializers/migrator.ts (renamed from server/initializers/migrator.js) | 25 |
16 files changed, 169 insertions, 153 deletions
diff --git a/server/initializers/checker.js b/server/initializers/checker.ts index aa8dea4bf..370dff2d4 100644 --- a/server/initializers/checker.js +++ b/server/initializers/checker.ts | |||
@@ -1,17 +1,7 @@ | |||
1 | 'use strict' | 1 | import config = require('config') |
2 | 2 | ||
3 | const config = require('config') | ||
4 | |||
5 | const constants = require('./constants') | ||
6 | const db = require('./database') | 3 | const db = require('./database') |
7 | 4 | import { CONFIG } from './constants' | |
8 | const checker = { | ||
9 | checkConfig, | ||
10 | checkFFmpeg, | ||
11 | checkMissedConfig, | ||
12 | clientsExist, | ||
13 | usersExist | ||
14 | } | ||
15 | 5 | ||
16 | // Some checks on configuration files | 6 | // Some checks on configuration files |
17 | function checkConfig () { | 7 | function checkConfig () { |
@@ -50,7 +40,7 @@ function checkFFmpeg (callback) { | |||
50 | 40 | ||
51 | Ffmpeg.getAvailableCodecs(function (err, codecs) { | 41 | Ffmpeg.getAvailableCodecs(function (err, codecs) { |
52 | if (err) return callback(err) | 42 | if (err) return callback(err) |
53 | if (constants.CONFIG.TRANSCODING.ENABLED === false) return callback(null) | 43 | if (CONFIG.TRANSCODING.ENABLED === false) return callback(null) |
54 | 44 | ||
55 | const canEncode = [ 'libx264' ] | 45 | const canEncode = [ 'libx264' ] |
56 | canEncode.forEach(function (codec) { | 46 | canEncode.forEach(function (codec) { |
@@ -85,4 +75,10 @@ function usersExist (callback) { | |||
85 | 75 | ||
86 | // --------------------------------------------------------------------------- | 76 | // --------------------------------------------------------------------------- |
87 | 77 | ||
88 | module.exports = checker | 78 | export { |
79 | checkConfig, | ||
80 | checkFFmpeg, | ||
81 | checkMissedConfig, | ||
82 | clientsExist, | ||
83 | usersExist | ||
84 | } | ||
diff --git a/server/initializers/constants.js b/server/initializers/constants.ts index 87e9c8002..6bdc261ad 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | 'use strict' | 1 | import config = require('config') |
2 | 2 | import { join } from 'path' | |
3 | const config = require('config') | ||
4 | const path = require('path') | ||
5 | 3 | ||
6 | // --------------------------------------------------------------------------- | 4 | // --------------------------------------------------------------------------- |
7 | 5 | ||
@@ -36,38 +34,40 @@ const OAUTH_LIFETIME = { | |||
36 | 34 | ||
37 | const CONFIG = { | 35 | const CONFIG = { |
38 | LISTEN: { | 36 | LISTEN: { |
39 | PORT: config.get('listen.port') | 37 | PORT: config.get<number>('listen.port') |
40 | }, | 38 | }, |
41 | DATABASE: { | 39 | DATABASE: { |
42 | DBNAME: 'peertube' + config.get('database.suffix'), | 40 | DBNAME: 'peertube' + config.get<string>('database.suffix'), |
43 | HOSTNAME: config.get('database.hostname'), | 41 | HOSTNAME: config.get<string>('database.hostname'), |
44 | PORT: config.get('database.port'), | 42 | PORT: config.get<number>('database.port'), |
45 | USERNAME: config.get('database.username'), | 43 | USERNAME: config.get<string>('database.username'), |
46 | PASSWORD: config.get('database.password') | 44 | PASSWORD: config.get<string>('database.password') |
47 | }, | 45 | }, |
48 | STORAGE: { | 46 | STORAGE: { |
49 | CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')), | 47 | CERT_DIR: join(__dirname, '..', '..', config.get<string>('storage.certs')), |
50 | LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')), | 48 | LOG_DIR: join(__dirname, '..', '..', config.get<string>('storage.logs')), |
51 | VIDEOS_DIR: path.join(__dirname, '..', '..', config.get('storage.videos')), | 49 | VIDEOS_DIR: join(__dirname, '..', '..', config.get<string>('storage.videos')), |
52 | THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')), | 50 | THUMBNAILS_DIR: join(__dirname, '..', '..', config.get<string>('storage.thumbnails')), |
53 | PREVIEWS_DIR: path.join(__dirname, '..', '..', config.get('storage.previews')), | 51 | PREVIEWS_DIR: join(__dirname, '..', '..', config.get<string>('storage.previews')), |
54 | TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents')) | 52 | TORRENTS_DIR: join(__dirname, '..', '..', config.get<string>('storage.torrents')) |
55 | }, | 53 | }, |
56 | WEBSERVER: { | 54 | WEBSERVER: { |
57 | SCHEME: config.get('webserver.https') === true ? 'https' : 'http', | 55 | SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http', |
58 | WS: config.get('webserver.https') === true ? 'wss' : 'ws', | 56 | WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws', |
59 | HOSTNAME: config.get('webserver.hostname'), | 57 | HOSTNAME: config.get<string>('webserver.hostname'), |
60 | PORT: config.get('webserver.port') | 58 | PORT: config.get<number>('webserver.port'), |
59 | URL: '', | ||
60 | HOST: '' | ||
61 | }, | 61 | }, |
62 | ADMIN: { | 62 | ADMIN: { |
63 | EMAIL: config.get('admin.email') | 63 | EMAIL: config.get<string>('admin.email') |
64 | }, | 64 | }, |
65 | SIGNUP: { | 65 | SIGNUP: { |
66 | ENABLED: config.get('signup.enabled') | 66 | ENABLED: config.get<boolean>('signup.enabled') |
67 | }, | 67 | }, |
68 | TRANSCODING: { | 68 | TRANSCODING: { |
69 | ENABLED: config.get('transcoding.enabled'), | 69 | ENABLED: config.get<boolean>('transcoding.enabled'), |
70 | THREADS: config.get('transcoding.threads') | 70 | THREADS: config.get<number>('transcoding.threads') |
71 | } | 71 | } |
72 | } | 72 | } |
73 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | 73 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
@@ -283,12 +283,12 @@ if (isTestInstance() === true) { | |||
283 | JOBS_FETCHING_INTERVAL = 10000 | 283 | JOBS_FETCHING_INTERVAL = 10000 |
284 | REMOTE_SCHEME.HTTP = 'http' | 284 | REMOTE_SCHEME.HTTP = 'http' |
285 | REMOTE_SCHEME.WS = 'ws' | 285 | REMOTE_SCHEME.WS = 'ws' |
286 | STATIC_MAX_AGE = 0 | 286 | STATIC_MAX_AGE = '0' |
287 | } | 287 | } |
288 | 288 | ||
289 | // --------------------------------------------------------------------------- | 289 | // --------------------------------------------------------------------------- |
290 | 290 | ||
291 | module.exports = { | 291 | export { |
292 | API_VERSION, | 292 | API_VERSION, |
293 | BCRYPT_SALT_SIZE, | 293 | BCRYPT_SALT_SIZE, |
294 | CONFIG, | 294 | CONFIG, |
diff --git a/server/initializers/database.js b/server/initializers/database.ts index 043152a0e..753a06669 100644 --- a/server/initializers/database.js +++ b/server/initializers/database.ts | |||
@@ -1,24 +1,23 @@ | |||
1 | 'use strict' | 1 | import fs = require('fs') |
2 | import { join } from 'path' | ||
3 | import Sequelize = require('sequelize') | ||
2 | 4 | ||
3 | const fs = require('fs') | 5 | import { CONFIG } from './constants' |
4 | const path = require('path') | 6 | // Do not use barrel, we need to load database first |
5 | const Sequelize = require('sequelize') | 7 | import { logger } from '../helpers/logger' |
8 | import { isTestInstance } from '../helpers/utils' | ||
6 | 9 | ||
7 | const constants = require('../initializers/constants') | 10 | const dbname = CONFIG.DATABASE.DBNAME |
8 | const logger = require('../helpers/logger') | 11 | const username = CONFIG.DATABASE.USERNAME |
9 | const utils = require('../helpers/utils') | 12 | const password = CONFIG.DATABASE.PASSWORD |
10 | 13 | ||
11 | const database = {} | 14 | const database: any = {} |
12 | |||
13 | const dbname = constants.CONFIG.DATABASE.DBNAME | ||
14 | const username = constants.CONFIG.DATABASE.USERNAME | ||
15 | const password = constants.CONFIG.DATABASE.PASSWORD | ||
16 | 15 | ||
17 | const sequelize = new Sequelize(dbname, username, password, { | 16 | const sequelize = new Sequelize(dbname, username, password, { |
18 | dialect: 'postgres', | 17 | dialect: 'postgres', |
19 | host: constants.CONFIG.DATABASE.HOSTNAME, | 18 | host: CONFIG.DATABASE.HOSTNAME, |
20 | port: constants.CONFIG.DATABASE.PORT, | 19 | port: CONFIG.DATABASE.PORT, |
21 | benchmark: utils.isTestInstance(), | 20 | benchmark: isTestInstance(), |
22 | 21 | ||
23 | logging: function (message, benchmark) { | 22 | logging: function (message, benchmark) { |
24 | let newMessage = message | 23 | let newMessage = message |
@@ -31,24 +30,16 @@ const sequelize = new Sequelize(dbname, username, password, { | |||
31 | }) | 30 | }) |
32 | 31 | ||
33 | database.sequelize = sequelize | 32 | database.sequelize = sequelize |
34 | database.Sequelize = Sequelize | ||
35 | database.init = init | ||
36 | |||
37 | // --------------------------------------------------------------------------- | ||
38 | 33 | ||
39 | module.exports = database | 34 | database.init = function (silent, callback) { |
40 | |||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
43 | function init (silent, callback) { | ||
44 | if (!callback) { | 35 | if (!callback) { |
45 | callback = silent | 36 | callback = silent |
46 | silent = false | 37 | silent = false |
47 | } | 38 | } |
48 | 39 | ||
49 | if (!callback) callback = function () {} | 40 | if (!callback) callback = function () { /* empty */ } |
50 | 41 | ||
51 | const modelDirectory = path.join(__dirname, '..', 'models') | 42 | const modelDirectory = join(__dirname, '..', 'models') |
52 | fs.readdir(modelDirectory, function (err, files) { | 43 | fs.readdir(modelDirectory, function (err, files) { |
53 | if (err) throw err | 44 | if (err) throw err |
54 | 45 | ||
@@ -59,9 +50,9 @@ function init (silent, callback) { | |||
59 | return true | 50 | return true |
60 | }) | 51 | }) |
61 | .forEach(function (file) { | 52 | .forEach(function (file) { |
62 | const model = sequelize.import(path.join(modelDirectory, file)) | 53 | const model = sequelize.import(join(modelDirectory, file)) |
63 | 54 | ||
64 | database[model.name] = model | 55 | database[model['name']] = model |
65 | }) | 56 | }) |
66 | 57 | ||
67 | Object.keys(database).forEach(function (modelName) { | 58 | Object.keys(database).forEach(function (modelName) { |
@@ -75,3 +66,7 @@ function init (silent, callback) { | |||
75 | return callback(null) | 66 | return callback(null) |
76 | }) | 67 | }) |
77 | } | 68 | } |
69 | |||
70 | // --------------------------------------------------------------------------- | ||
71 | |||
72 | module.exports = database | ||
diff --git a/server/initializers/index.ts b/server/initializers/index.ts new file mode 100644 index 000000000..b8400ff84 --- /dev/null +++ b/server/initializers/index.ts | |||
@@ -0,0 +1,6 @@ | |||
1 | // Constants first, databse in second! | ||
2 | export * from './constants' | ||
3 | export * from './database' | ||
4 | export * from './checker' | ||
5 | export * from './installer' | ||
6 | export * from './migrator' | ||
diff --git a/server/initializers/installer.js b/server/initializers/installer.ts index 837a987dd..cd1404d48 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.ts | |||
@@ -1,21 +1,13 @@ | |||
1 | 'use strict' | 1 | import { join } from 'path' |
2 | import config = require('config') | ||
3 | import { each, series } from 'async' | ||
4 | import mkdirp = require('mkdirp') | ||
5 | import passwordGenerator = require('password-generator') | ||
2 | 6 | ||
3 | const config = require('config') | ||
4 | const each = require('async/each') | ||
5 | const mkdirp = require('mkdirp') | ||
6 | const passwordGenerator = require('password-generator') | ||
7 | const path = require('path') | ||
8 | const series = require('async/series') | ||
9 | |||
10 | const checker = require('./checker') | ||
11 | const constants = require('./constants') | ||
12 | const db = require('./database') | 7 | const db = require('./database') |
13 | const logger = require('../helpers/logger') | 8 | import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION } from './constants' |
14 | const peertubeCrypto = require('../helpers/peertube-crypto') | 9 | import { clientsExist, usersExist } from './checker' |
15 | 10 | import { logger, createCertsIfNotExist } from '../helpers' | |
16 | const installer = { | ||
17 | installApplication | ||
18 | } | ||
19 | 11 | ||
20 | function installApplication (callback) { | 12 | function installApplication (callback) { |
21 | series([ | 13 | series([ |
@@ -29,7 +21,7 @@ function installApplication (callback) { | |||
29 | }, | 21 | }, |
30 | 22 | ||
31 | function createCertificates (callbackAsync) { | 23 | function createCertificates (callbackAsync) { |
32 | peertubeCrypto.createCertsIfNotExist(callbackAsync) | 24 | createCertsIfNotExist(callbackAsync) |
33 | }, | 25 | }, |
34 | 26 | ||
35 | function createOAuthClient (callbackAsync) { | 27 | function createOAuthClient (callbackAsync) { |
@@ -44,7 +36,9 @@ function installApplication (callback) { | |||
44 | 36 | ||
45 | // --------------------------------------------------------------------------- | 37 | // --------------------------------------------------------------------------- |
46 | 38 | ||
47 | module.exports = installer | 39 | export { |
40 | installApplication | ||
41 | } | ||
48 | 42 | ||
49 | // --------------------------------------------------------------------------- | 43 | // --------------------------------------------------------------------------- |
50 | 44 | ||
@@ -53,12 +47,12 @@ function createDirectoriesIfNotExist (callback) { | |||
53 | 47 | ||
54 | each(Object.keys(storages), function (key, callbackEach) { | 48 | each(Object.keys(storages), function (key, callbackEach) { |
55 | const dir = storages[key] | 49 | const dir = storages[key] |
56 | mkdirp(path.join(__dirname, '..', '..', dir), callbackEach) | 50 | mkdirp(join(__dirname, '..', '..', dir), callbackEach) |
57 | }, callback) | 51 | }, callback) |
58 | } | 52 | } |
59 | 53 | ||
60 | function createOAuthClientIfNotExist (callback) { | 54 | function createOAuthClientIfNotExist (callback) { |
61 | checker.clientsExist(function (err, exist) { | 55 | clientsExist(function (err, exist) { |
62 | if (err) return callback(err) | 56 | if (err) return callback(err) |
63 | 57 | ||
64 | // Nothing to do, clients already exist | 58 | // Nothing to do, clients already exist |
@@ -86,7 +80,7 @@ function createOAuthClientIfNotExist (callback) { | |||
86 | } | 80 | } |
87 | 81 | ||
88 | function createOAuthAdminIfNotExist (callback) { | 82 | function createOAuthAdminIfNotExist (callback) { |
89 | checker.usersExist(function (err, exist) { | 83 | usersExist(function (err, exist) { |
90 | if (err) return callback(err) | 84 | if (err) return callback(err) |
91 | 85 | ||
92 | // Nothing to do, users already exist | 86 | // Nothing to do, users already exist |
@@ -95,9 +89,9 @@ function createOAuthAdminIfNotExist (callback) { | |||
95 | logger.info('Creating the administrator.') | 89 | logger.info('Creating the administrator.') |
96 | 90 | ||
97 | const username = 'root' | 91 | const username = 'root' |
98 | const role = constants.USER_ROLES.ADMIN | 92 | const role = USER_ROLES.ADMIN |
99 | const email = constants.CONFIG.ADMIN.EMAIL | 93 | const email = CONFIG.ADMIN.EMAIL |
100 | const createOptions = {} | 94 | const createOptions: { validate?: boolean } = {} |
101 | let password = '' | 95 | let password = '' |
102 | 96 | ||
103 | // Do not generate a random password for tests | 97 | // Do not generate a random password for tests |
@@ -128,7 +122,7 @@ function createOAuthAdminIfNotExist (callback) { | |||
128 | logger.info('User password: ' + password) | 122 | logger.info('User password: ' + password) |
129 | 123 | ||
130 | logger.info('Creating Application table.') | 124 | logger.info('Creating Application table.') |
131 | db.Application.create({ migrationVersion: constants.LAST_MIGRATION_VERSION }).asCallback(callback) | 125 | db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }).asCallback(callback) |
132 | }) | 126 | }) |
133 | }) | 127 | }) |
134 | } | 128 | } |
diff --git a/server/initializers/migrations/0005-email-pod.js b/server/initializers/migrations/0005-email-pod.ts index 9bbb354bf..a9200c47f 100644 --- a/server/initializers/migrations/0005-email-pod.js +++ b/server/initializers/migrations/0005-email-pod.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | 'use strict' | 1 | import { waterfall } from 'async' |
2 | |||
3 | const waterfall = require('async/waterfall') | ||
4 | 2 | ||
5 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 3 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
6 | exports.up = function (utils, finalCallback) { | 4 | function up (utils, finalCallback) { |
7 | const q = utils.queryInterface | 5 | const q = utils.queryInterface |
8 | const Sequelize = utils.Sequelize | 6 | const Sequelize = utils.Sequelize |
9 | 7 | ||
@@ -36,6 +34,11 @@ exports.up = function (utils, finalCallback) { | |||
36 | ], finalCallback) | 34 | ], finalCallback) |
37 | } | 35 | } |
38 | 36 | ||
39 | exports.down = function (options, callback) { | 37 | function down (options, callback) { |
40 | throw new Error('Not implemented.') | 38 | throw new Error('Not implemented.') |
41 | } | 39 | } |
40 | |||
41 | export { | ||
42 | up, | ||
43 | down | ||
44 | } | ||
diff --git a/server/initializers/migrations/0010-email-user.js b/server/initializers/migrations/0010-email-user.ts index 1ab27133a..4b5d29394 100644 --- a/server/initializers/migrations/0010-email-user.js +++ b/server/initializers/migrations/0010-email-user.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | 'use strict' | 1 | import { waterfall } from 'async' |
2 | |||
3 | const waterfall = require('async/waterfall') | ||
4 | 2 | ||
5 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 3 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
6 | exports.up = function (utils, finalCallback) { | 4 | function up (utils, finalCallback) { |
7 | const q = utils.queryInterface | 5 | const q = utils.queryInterface |
8 | const Sequelize = utils.Sequelize | 6 | const Sequelize = utils.Sequelize |
9 | 7 | ||
@@ -36,6 +34,11 @@ exports.up = function (utils, finalCallback) { | |||
36 | ], finalCallback) | 34 | ], finalCallback) |
37 | } | 35 | } |
38 | 36 | ||
39 | exports.down = function (options, callback) { | 37 | function down (options, callback) { |
40 | throw new Error('Not implemented.') | 38 | throw new Error('Not implemented.') |
41 | } | 39 | } |
40 | |||
41 | export { | ||
42 | up, | ||
43 | down | ||
44 | } | ||
diff --git a/server/initializers/migrations/0015-video-views.js b/server/initializers/migrations/0015-video-views.ts index ae49fe73c..e70869404 100644 --- a/server/initializers/migrations/0015-video-views.js +++ b/server/initializers/migrations/0015-video-views.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 1 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
4 | exports.up = function (utils, finalCallback) { | 2 | function up (utils, finalCallback) { |
5 | const q = utils.queryInterface | 3 | const q = utils.queryInterface |
6 | const Sequelize = utils.Sequelize | 4 | const Sequelize = utils.Sequelize |
7 | 5 | ||
@@ -14,6 +12,11 @@ exports.up = function (utils, finalCallback) { | |||
14 | q.addColumn('Videos', 'views', data, { transaction: utils.transaction }).asCallback(finalCallback) | 12 | q.addColumn('Videos', 'views', data, { transaction: utils.transaction }).asCallback(finalCallback) |
15 | } | 13 | } |
16 | 14 | ||
17 | exports.down = function (options, callback) { | 15 | function down (options, callback) { |
18 | throw new Error('Not implemented.') | 16 | throw new Error('Not implemented.') |
19 | } | 17 | } |
18 | |||
19 | export { | ||
20 | up, | ||
21 | down | ||
22 | } | ||
diff --git a/server/initializers/migrations/0020-video-likes.js b/server/initializers/migrations/0020-video-likes.ts index 6db62cb90..e435d0657 100644 --- a/server/initializers/migrations/0020-video-likes.js +++ b/server/initializers/migrations/0020-video-likes.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 1 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
4 | exports.up = function (utils, finalCallback) { | 2 | function up (utils, finalCallback) { |
5 | const q = utils.queryInterface | 3 | const q = utils.queryInterface |
6 | const Sequelize = utils.Sequelize | 4 | const Sequelize = utils.Sequelize |
7 | 5 | ||
@@ -14,6 +12,11 @@ exports.up = function (utils, finalCallback) { | |||
14 | q.addColumn('Videos', 'likes', data, { transaction: utils.transaction }).asCallback(finalCallback) | 12 | q.addColumn('Videos', 'likes', data, { transaction: utils.transaction }).asCallback(finalCallback) |
15 | } | 13 | } |
16 | 14 | ||
17 | exports.down = function (options, callback) { | 15 | function down (options, callback) { |
18 | throw new Error('Not implemented.') | 16 | throw new Error('Not implemented.') |
19 | } | 17 | } |
18 | |||
19 | export { | ||
20 | up, | ||
21 | down | ||
22 | } | ||
diff --git a/server/initializers/migrations/0025-video-dislikes.js b/server/initializers/migrations/0025-video-dislikes.ts index 40d2e7351..57e54e904 100644 --- a/server/initializers/migrations/0025-video-dislikes.js +++ b/server/initializers/migrations/0025-video-dislikes.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 1 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
4 | exports.up = function (utils, finalCallback) { | 2 | function up (utils, finalCallback) { |
5 | const q = utils.queryInterface | 3 | const q = utils.queryInterface |
6 | const Sequelize = utils.Sequelize | 4 | const Sequelize = utils.Sequelize |
7 | 5 | ||
@@ -14,6 +12,11 @@ exports.up = function (utils, finalCallback) { | |||
14 | q.addColumn('Videos', 'dislikes', data, { transaction: utils.transaction }).asCallback(finalCallback) | 12 | q.addColumn('Videos', 'dislikes', data, { transaction: utils.transaction }).asCallback(finalCallback) |
15 | } | 13 | } |
16 | 14 | ||
17 | exports.down = function (options, callback) { | 15 | function down (options, callback) { |
18 | throw new Error('Not implemented.') | 16 | throw new Error('Not implemented.') |
19 | } | 17 | } |
18 | |||
19 | export { | ||
20 | up, | ||
21 | down | ||
22 | } | ||
diff --git a/server/initializers/migrations/0030-video-category.js b/server/initializers/migrations/0030-video-category.ts index ada95b2fe..1073f449c 100644 --- a/server/initializers/migrations/0030-video-category.js +++ b/server/initializers/migrations/0030-video-category.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | 'use strict' | 1 | import { waterfall } from 'async' |
2 | |||
3 | const waterfall = require('async/waterfall') | ||
4 | 2 | ||
5 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 3 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
6 | exports.up = function (utils, finalCallback) { | 4 | function up (utils, finalCallback) { |
7 | const q = utils.queryInterface | 5 | const q = utils.queryInterface |
8 | const Sequelize = utils.Sequelize | 6 | const Sequelize = utils.Sequelize |
9 | 7 | ||
@@ -29,6 +27,11 @@ exports.up = function (utils, finalCallback) { | |||
29 | ], finalCallback) | 27 | ], finalCallback) |
30 | } | 28 | } |
31 | 29 | ||
32 | exports.down = function (options, callback) { | 30 | function down (options, callback) { |
33 | throw new Error('Not implemented.') | 31 | throw new Error('Not implemented.') |
34 | } | 32 | } |
33 | |||
34 | export { | ||
35 | up, | ||
36 | down | ||
37 | } | ||
diff --git a/server/initializers/migrations/0035-video-licence.js b/server/initializers/migrations/0035-video-licence.ts index 9cf75858d..9316b3c37 100644 --- a/server/initializers/migrations/0035-video-licence.js +++ b/server/initializers/migrations/0035-video-licence.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | 'use strict' | 1 | import { waterfall } from 'async' |
2 | |||
3 | const waterfall = require('async/waterfall') | ||
4 | 2 | ||
5 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 3 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
6 | exports.up = function (utils, finalCallback) { | 4 | function up (utils, finalCallback) { |
7 | const q = utils.queryInterface | 5 | const q = utils.queryInterface |
8 | const Sequelize = utils.Sequelize | 6 | const Sequelize = utils.Sequelize |
9 | 7 | ||
@@ -29,6 +27,11 @@ exports.up = function (utils, finalCallback) { | |||
29 | ], finalCallback) | 27 | ], finalCallback) |
30 | } | 28 | } |
31 | 29 | ||
32 | exports.down = function (options, callback) { | 30 | function down (options, callback) { |
33 | throw new Error('Not implemented.') | 31 | throw new Error('Not implemented.') |
34 | } | 32 | } |
33 | |||
34 | export { | ||
35 | up, | ||
36 | down | ||
37 | } | ||
diff --git a/server/initializers/migrations/0040-video-nsfw.js b/server/initializers/migrations/0040-video-nsfw.ts index 7f3692b28..c61f496f1 100644 --- a/server/initializers/migrations/0040-video-nsfw.js +++ b/server/initializers/migrations/0040-video-nsfw.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | 'use strict' | 1 | import { waterfall } from 'async' |
2 | |||
3 | const waterfall = require('async/waterfall') | ||
4 | 2 | ||
5 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 3 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
6 | exports.up = function (utils, finalCallback) { | 4 | function up (utils, finalCallback) { |
7 | const q = utils.queryInterface | 5 | const q = utils.queryInterface |
8 | const Sequelize = utils.Sequelize | 6 | const Sequelize = utils.Sequelize |
9 | 7 | ||
@@ -29,6 +27,11 @@ exports.up = function (utils, finalCallback) { | |||
29 | ], finalCallback) | 27 | ], finalCallback) |
30 | } | 28 | } |
31 | 29 | ||
32 | exports.down = function (options, callback) { | 30 | function down (options, callback) { |
33 | throw new Error('Not implemented.') | 31 | throw new Error('Not implemented.') |
34 | } | 32 | } |
33 | |||
34 | export { | ||
35 | up, | ||
36 | down | ||
37 | } | ||
diff --git a/server/initializers/migrations/0045-user-display-nsfw.js b/server/initializers/migrations/0045-user-display-nsfw.ts index 03624e593..1ca317795 100644 --- a/server/initializers/migrations/0045-user-display-nsfw.js +++ b/server/initializers/migrations/0045-user-display-nsfw.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 1 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
4 | exports.up = function (utils, finalCallback) { | 2 | function up (utils, finalCallback) { |
5 | const q = utils.queryInterface | 3 | const q = utils.queryInterface |
6 | const Sequelize = utils.Sequelize | 4 | const Sequelize = utils.Sequelize |
7 | 5 | ||
@@ -14,6 +12,11 @@ exports.up = function (utils, finalCallback) { | |||
14 | q.addColumn('Users', 'displayNSFW', data, { transaction: utils.transaction }).asCallback(finalCallback) | 12 | q.addColumn('Users', 'displayNSFW', data, { transaction: utils.transaction }).asCallback(finalCallback) |
15 | } | 13 | } |
16 | 14 | ||
17 | exports.down = function (options, callback) { | 15 | function down (options, callback) { |
18 | throw new Error('Not implemented.') | 16 | throw new Error('Not implemented.') |
19 | } | 17 | } |
18 | |||
19 | export { | ||
20 | up, | ||
21 | down | ||
22 | } | ||
diff --git a/server/initializers/migrations/0050-video-language.js b/server/initializers/migrations/0050-video-language.ts index 1c978758d..95d0a473a 100644 --- a/server/initializers/migrations/0050-video-language.js +++ b/server/initializers/migrations/0050-video-language.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // utils = { transaction, queryInterface, sequelize, Sequelize } | 1 | // utils = { transaction, queryInterface, sequelize, Sequelize } |
4 | exports.up = function (utils, finalCallback) { | 2 | function up (utils, finalCallback) { |
5 | const q = utils.queryInterface | 3 | const q = utils.queryInterface |
6 | const Sequelize = utils.Sequelize | 4 | const Sequelize = utils.Sequelize |
7 | 5 | ||
@@ -14,6 +12,11 @@ exports.up = function (utils, finalCallback) { | |||
14 | q.addColumn('Videos', 'language', data, { transaction: utils.transaction }).asCallback(finalCallback) | 12 | q.addColumn('Videos', 'language', data, { transaction: utils.transaction }).asCallback(finalCallback) |
15 | } | 13 | } |
16 | 14 | ||
17 | exports.down = function (options, callback) { | 15 | function down (options, callback) { |
18 | throw new Error('Not implemented.') | 16 | throw new Error('Not implemented.') |
19 | } | 17 | } |
18 | |||
19 | export { | ||
20 | up, | ||
21 | down | ||
22 | } | ||
diff --git a/server/initializers/migrator.js b/server/initializers/migrator.ts index 9a6415b1a..cfa3220e0 100644 --- a/server/initializers/migrator.js +++ b/server/initializers/migrator.ts | |||
@@ -1,17 +1,10 @@ | |||
1 | 'use strict' | 1 | import { waterfall, eachSeries } from 'async' |
2 | import fs = require('fs') | ||
3 | import path = require('path') | ||
2 | 4 | ||
3 | const waterfall = require('async/waterfall') | ||
4 | const eachSeries = require('async/eachSeries') | ||
5 | const fs = require('fs') | ||
6 | const path = require('path') | ||
7 | |||
8 | const constants = require('./constants') | ||
9 | const db = require('./database') | 5 | const db = require('./database') |
10 | const logger = require('../helpers/logger') | 6 | import { LAST_MIGRATION_VERSION } from './constants' |
11 | 7 | import { logger } from '../helpers' | |
12 | const migrator = { | ||
13 | migrate: migrate | ||
14 | } | ||
15 | 8 | ||
16 | function migrate (finalCallback) { | 9 | function migrate (finalCallback) { |
17 | waterfall([ | 10 | waterfall([ |
@@ -46,7 +39,7 @@ function migrate (finalCallback) { | |||
46 | 39 | ||
47 | function abortMigrationIfNotNeeded (actualVersion, callback) { | 40 | function abortMigrationIfNotNeeded (actualVersion, callback) { |
48 | // No need migrations | 41 | // No need migrations |
49 | if (actualVersion >= constants.LAST_MIGRATION_VERSION) return finalCallback(null) | 42 | if (actualVersion >= LAST_MIGRATION_VERSION) return finalCallback(null) |
50 | 43 | ||
51 | return callback(null, actualVersion) | 44 | return callback(null, actualVersion) |
52 | }, | 45 | }, |
@@ -66,7 +59,7 @@ function migrate (finalCallback) { | |||
66 | }, function (err) { | 59 | }, function (err) { |
67 | if (err) return callback(err) | 60 | if (err) return callback(err) |
68 | 61 | ||
69 | logger.info('Migrations finished. New migration version schema: %s', constants.LAST_MIGRATION_VERSION) | 62 | logger.info('Migrations finished. New migration version schema: %s', LAST_MIGRATION_VERSION) |
70 | return callback(null) | 63 | return callback(null) |
71 | }) | 64 | }) |
72 | } | 65 | } |
@@ -75,7 +68,9 @@ function migrate (finalCallback) { | |||
75 | 68 | ||
76 | // --------------------------------------------------------------------------- | 69 | // --------------------------------------------------------------------------- |
77 | 70 | ||
78 | module.exports = migrator | 71 | export { |
72 | migrate | ||
73 | } | ||
79 | 74 | ||
80 | // --------------------------------------------------------------------------- | 75 | // --------------------------------------------------------------------------- |
81 | 76 | ||