From c1e791bad0b079af67398f6407221e6dcbb573dd Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 25 Jul 2018 22:01:25 +0200 Subject: expliciting type checks and predicates (server only) --- server/initializers/installer.ts | 2 +- server/initializers/migrations/0005-email-pod.ts | 3 ++- server/initializers/migrations/0010-email-user.ts | 3 ++- server/initializers/migrations/0030-video-category.ts | 3 ++- server/initializers/migrations/0035-video-licence.ts | 3 ++- server/initializers/migrations/0040-video-nsfw.ts | 3 ++- server/initializers/migrations/0055-video-uuid.ts | 2 +- server/initializers/migrations/0070-user-video-quota.ts | 3 ++- server/initializers/migrations/0155-video-comments-enabled.ts | 3 ++- server/initializers/migrations/0230-kue-to-bull.ts | 9 +++------ server/initializers/migrator.ts | 2 +- 11 files changed, 20 insertions(+), 16 deletions(-) (limited to 'server/initializers') diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 1f513a9c3..1926c40dd 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -52,7 +52,7 @@ function createDirectoriesIfNotExist () { const cacheDirectories = Object.keys(CACHE) .map(k => CACHE[k].DIRECTORY) - const tasks = [] + const tasks: Promise[] = [] for (const key of Object.keys(storage)) { const dir = storage[key] tasks.push(mkdirpPromise(dir)) diff --git a/server/initializers/migrations/0005-email-pod.ts b/server/initializers/migrations/0005-email-pod.ts index ab60f3adb..c34a12255 100644 --- a/server/initializers/migrations/0005-email-pod.ts +++ b/server/initializers/migrations/0005-email-pod.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { Migration } from '../../models/migrations' function up (utils: { transaction: Sequelize.Transaction, @@ -12,7 +13,7 @@ function up (utils: { type: Sequelize.STRING(400), allowNull: false, defaultValue: '' - } + } as Migration.String return q.addColumn('Pods', 'email', data) .then(() => { diff --git a/server/initializers/migrations/0010-email-user.ts b/server/initializers/migrations/0010-email-user.ts index 33d13ce55..37a7b0bb3 100644 --- a/server/initializers/migrations/0010-email-user.ts +++ b/server/initializers/migrations/0010-email-user.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { Migration } from '../../models/migrations' function up (utils: { transaction: Sequelize.Transaction, @@ -12,7 +13,7 @@ function up (utils: { type: Sequelize.STRING(400), allowNull: false, defaultValue: '' - } + } as Migration.String return q.addColumn('Users', 'email', data) .then(() => { const query = 'UPDATE "Users" SET "email" = CONCAT("username", \'@example.com\')' diff --git a/server/initializers/migrations/0030-video-category.ts b/server/initializers/migrations/0030-video-category.ts index 41bc1aa98..f784f820d 100644 --- a/server/initializers/migrations/0030-video-category.ts +++ b/server/initializers/migrations/0030-video-category.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { Migration } from '../../models/migrations' function up (utils: { transaction: Sequelize.Transaction, @@ -12,7 +13,7 @@ function up (utils: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 - } + } as Migration.Integer return q.addColumn('Videos', 'category', data) .then(() => { diff --git a/server/initializers/migrations/0035-video-licence.ts b/server/initializers/migrations/0035-video-licence.ts index 7ab49e147..3d0b0bac9 100644 --- a/server/initializers/migrations/0035-video-licence.ts +++ b/server/initializers/migrations/0035-video-licence.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { Migration } from '../../models/migrations' function up (utils: { transaction: Sequelize.Transaction, @@ -12,7 +13,7 @@ function up (utils: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 - } + } as Migration.Integer return q.addColumn('Videos', 'licence', data) .then(() => { diff --git a/server/initializers/migrations/0040-video-nsfw.ts b/server/initializers/migrations/0040-video-nsfw.ts index 0460e661d..f7f70d3c4 100644 --- a/server/initializers/migrations/0040-video-nsfw.ts +++ b/server/initializers/migrations/0040-video-nsfw.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { Migration } from '../../models/migrations' function up (utils: { transaction: Sequelize.Transaction, @@ -12,7 +13,7 @@ function up (utils: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false - } + } as Migration.Boolean return q.addColumn('Videos', 'nsfw', data) .then(() => { diff --git a/server/initializers/migrations/0055-video-uuid.ts b/server/initializers/migrations/0055-video-uuid.ts index 9bc65917c..6db25f193 100644 --- a/server/initializers/migrations/0055-video-uuid.ts +++ b/server/initializers/migrations/0055-video-uuid.ts @@ -24,7 +24,7 @@ function up (utils: { return utils.sequelize.query(query) }) .then(() => { - dataUUID.defaultValue = null + dataUUID.defaultValue = null // FIXME:default value cannot be null if string return q.changeColumn('Videos', 'uuid', dataUUID) }) diff --git a/server/initializers/migrations/0070-user-video-quota.ts b/server/initializers/migrations/0070-user-video-quota.ts index dec4d46dd..37683432f 100644 --- a/server/initializers/migrations/0070-user-video-quota.ts +++ b/server/initializers/migrations/0070-user-video-quota.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { Migration } from '../../models/migrations' function up (utils: { transaction: Sequelize.Transaction, @@ -13,7 +14,7 @@ function up (utils: { type: Sequelize.BIGINT, allowNull: false, defaultValue: -1 - } + } as Migration.BigInteger return q.addColumn('Users', 'videoQuota', data) .then(() => { diff --git a/server/initializers/migrations/0155-video-comments-enabled.ts b/server/initializers/migrations/0155-video-comments-enabled.ts index 59f4110de..6949d3a0c 100644 --- a/server/initializers/migrations/0155-video-comments-enabled.ts +++ b/server/initializers/migrations/0155-video-comments-enabled.ts @@ -1,4 +1,5 @@ import * as Sequelize from 'sequelize' +import { Migration } from '../../models/migrations' async function up (utils: { transaction: Sequelize.Transaction, @@ -9,7 +10,7 @@ async function up (utils: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true - } + } as Migration.Boolean await utils.queryInterface.addColumn('video', 'commentsEnabled', data) data.defaultValue = null diff --git a/server/initializers/migrations/0230-kue-to-bull.ts b/server/initializers/migrations/0230-kue-to-bull.ts index 5fad87a61..5f4d88bef 100644 --- a/server/initializers/migrations/0230-kue-to-bull.ts +++ b/server/initializers/migrations/0230-kue-to-bull.ts @@ -2,6 +2,7 @@ import * as Sequelize from 'sequelize' import { createClient } from 'redis' import { CONFIG } from '../constants' import { JobQueue } from '../../lib/job-queue' +import { Redis } from '../../lib/redis' import { initDatabaseModels } from '../database' async function up (utils: { @@ -12,11 +13,7 @@ async function up (utils: { await initDatabaseModels(false) return new Promise((res, rej) => { - const client = createClient({ - host: CONFIG.REDIS.HOSTNAME, - port: CONFIG.REDIS.PORT, - db: CONFIG.REDIS.DB - }) + const client = createClient(Redis.getRedisClient()) const jobsPrefix = 'q-' + CONFIG.WEBSERVER.HOST @@ -36,7 +33,7 @@ async function up (utils: { return res({ type: job.type, payload: parsedData }) } catch (err) { console.error('Cannot parse data %s.', job.data) - return res(null) + return res(undefined) } }) }) diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts index 466369729..539e2bc8f 100644 --- a/server/initializers/migrator.ts +++ b/server/initializers/migrator.ts @@ -11,7 +11,7 @@ async function migrate () { // The installer will do that if (tables.length === 0) return - let actualVersion: number = null + let actualVersion: number | null = null const [ rows ] = await sequelizeTypescript.query('SELECT "migrationVersion" FROM "application"') if (rows && rows[0] && rows[0].migrationVersion) { -- cgit v1.2.3