mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
style(migrations): fix formatting errors
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
638c2f6740
commit
c83eb7ec7e
1 changed files with 14 additions and 9 deletions
|
@ -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};`)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue