From 9567011bf01f36c7f796ac1e0f1fb12c71635e53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 30 Oct 2017 10:16:27 +0100 Subject: Add lazy description on server --- server/initializers/constants.ts | 5 +++-- server/initializers/database.ts | 9 ++++++-- .../migrations/0090-videos-description.ts | 25 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 server/initializers/migrations/0090-videos-description.ts (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6dc9737d2..adccb9f41 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -15,7 +15,7 @@ import { // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 85 +const LAST_MIGRATION_VERSION = 90 // --------------------------------------------------------------------------- @@ -122,7 +122,8 @@ const CONSTRAINTS_FIELDS = { }, VIDEOS: { NAME: { min: 3, max: 120 }, // Length - DESCRIPTION: { min: 3, max: 250 }, // Length + TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length + DESCRIPTION: { min: 3, max: 3000 }, // Length EXTNAME: [ '.mp4', '.ogv', '.webm' ], INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2 DURATION: { min: 1, max: 7200 }, // Number diff --git a/server/initializers/database.ts b/server/initializers/database.ts index dfad01581..141566c3a 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -84,9 +84,14 @@ database.init = async (silent: boolean) => { const filePaths = await getModelFiles(modelDirectory) for (const filePath of filePaths) { - const model = sequelize.import(filePath) + try { + const model = sequelize.import(filePath) - database[model['name']] = model + database[model['name']] = model + } catch (err) { + logger.error('Cannot import database model %s.', filePath, err) + process.exit(0) + } } for (const modelName of Object.keys(database)) { diff --git a/server/initializers/migrations/0090-videos-description.ts b/server/initializers/migrations/0090-videos-description.ts new file mode 100644 index 000000000..6f98dcade --- /dev/null +++ b/server/initializers/migrations/0090-videos-description.ts @@ -0,0 +1,25 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize, + db: any +}): Promise { + const q = utils.queryInterface + + const data = { + type: Sequelize.STRING(3000), + allowNull: false + } + await q.changeColumn('Videos', 'description', data) +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3