mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -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
|
// 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,24 +86,24 @@ 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)) {
|
||||||
await this.sequelize.query(`ROLLBACK TO ${savepointName};`)
|
await this.sequelize.query(`ROLLBACK TO ${savepointName};`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue