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 // core
const config = require('../config') const config = require('../config')
const logger = require('../logger') const logger = require('../logger')
const {isSQLite} = require("../utils"); const { isSQLite } = require('../utils')
const dbconfig = cloneDeep(config.db) const dbconfig = cloneDeep(config.db)
dbconfig.logging = config.debug dbconfig.logging = config.debug
@ -34,12 +34,17 @@ function stripNullByte (value) {
// eslint-disable-next-line no-control-regex // eslint-disable-next-line no-control-regex
return value ? value.replace(/\u0000/g, '') : value return value ? value.replace(/\u0000/g, '') : value
} }
sequelize.stripNullByte = stripNullByte sequelize.stripNullByte = stripNullByte
function processData (data, _default, process) { function processData (data, _default, process) {
if (data === undefined) return data if (data === undefined) {
else return data === null ? _default : (process ? process(data) : data) return data
} else {
return data === null ? _default : (process ? process(data) : data)
} }
}
sequelize.processData = processData sequelize.processData = processData
const db = {} const db = {}
@ -81,22 +86,22 @@ const umzug = new Umzug({
db.runMigrations = async function runMigrations () { db.runMigrations = async function runMigrations () {
// checks migrations and run them if they are not already applied // checks migrations and run them if they are not already applied
// exit in case of unsuccessful migrations // exit in case of unsuccessful migrations
const savepointName = 'migration'; const savepointName = 'migration'
try { try {
if (isSQLite(sequelize)) { if (isSQLite(sequelize)) {
// Deactivate foreign_keys for sqlite, so that sequelize does not accidentally delete data when recreating tables via cascading delete. // 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 // See https://github.com/hedgedoc/hedgedoc/issues/2809
await sequelize.query('PRAGMA foreign_keys = OFF;') await sequelize.query('PRAGMA foreign_keys = OFF;')
await this.sequelize.query(`SAVEPOINT ${savepointName};`); await this.sequelize.query(`SAVEPOINT ${savepointName};`)
} }
await umzug.up() await umzug.up()
if (isSQLite(sequelize)) { if (isSQLite(sequelize)) {
// Run a foreign keys integrity check // 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) { 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)) { if (isSQLite(sequelize)) {