style(migrations): fix formatting errors

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-11-06 21:48:13 +01:00 committed by Philip Molares
parent 638c2f6740
commit c83eb7ec7e

View file

@ -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};`)
}