From c83eb7ec7e4d3117c20af2b1c91010f2343856c3 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 6 Nov 2022 21:48:13 +0100 Subject: [PATCH] style(migrations): fix formatting errors Signed-off-by: David Mehren --- lib/models/index.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/models/index.js b/lib/models/index.js index 74fb8682b..f4e51a177 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -9,7 +9,7 @@ const Umzug = require('umzug') // core const config = require('../config') const logger = require('../logger') -const {isSQLite} = require("../utils"); +const { isSQLite } = require('../utils') const dbconfig = cloneDeep(config.db) dbconfig.logging = config.debug @@ -34,12 +34,17 @@ function stripNullByte (value) { // eslint-disable-next-line no-control-regex return value ? value.replace(/\u0000/g, '') : value } + sequelize.stripNullByte = stripNullByte function processData (data, _default, process) { - if (data === undefined) return data - else return data === null ? _default : (process ? process(data) : data) + if (data === undefined) { + return data + } else { + return data === null ? _default : (process ? process(data) : data) + } } + sequelize.processData = processData const db = {} @@ -81,24 +86,24 @@ const umzug = new Umzug({ db.runMigrations = async function runMigrations () { // checks migrations and run them if they are not already applied // exit in case of unsuccessful migrations - const savepointName = 'migration'; + const savepointName = 'migration' try { if (isSQLite(sequelize)) { // Deactivate foreign_keys for sqlite, so that sequelize does not accidentally delete data when recreating tables via cascading delete. // See https://github.com/hedgedoc/hedgedoc/issues/2809 await sequelize.query('PRAGMA foreign_keys = OFF;') - await this.sequelize.query(`SAVEPOINT ${savepointName};`); + await this.sequelize.query(`SAVEPOINT ${savepointName};`) } await umzug.up() if (isSQLite(sequelize)) { // Run a foreign keys integrity check - const foreignKeyCheckResult = await sequelize.query('PRAGMA foreign_key_check;') + const foreignKeyCheckResult = await sequelize.query('PRAGMA foreign_key_check;', { type: sequelize.QueryTypes.SELECT }) if (foreignKeyCheckResult.length > 0) { - throw Error(`Foreign key violations detected: ${JSON.stringify(foreignKeyCheckResult, null, 2)}`); + throw Error(`Foreign key violations detected: ${JSON.stringify(foreignKeyCheckResult, null, 2)}`) } - await this.sequelize.query(`RELEASE ${savepointName};`, options); + await this.sequelize.query(`RELEASE ${savepointName};`) } - } catch(error) { + } catch (error) { if (isSQLite(sequelize)) { await this.sequelize.query(`ROLLBACK TO ${savepointName};`) }