manually fix mariadb json fields

This commit is contained in:
lesion 2023-08-08 23:11:40 +02:00
parent f4ca625fea
commit 93bbe5f268
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 33 additions and 1 deletions

View file

@ -6,7 +6,7 @@ const config = require('../../config')
const log = require('../../log')
const SequelizeSlugify = require('sequelize-slugify')
const DB = require('./models')
const semver = require('semver')
const models = {
Announcement: require('./announcement'),
APUser: require('./ap_user'),
@ -104,8 +104,39 @@ const db = {
return true
}
},
async fixMariaDBJSON () {
// manually fix mariadb JSON wrong parse
if (db.sequelize.options.dialect === 'mariadb' && semver.lt('10.5.2', db.sequelize.options.databaseVersion)) {
try {
const ret = await db.sequelize.query('SHOW CREATE TABLE `settings`')
if (!ret[0][0]['Create Table'].toLowerCase().includes('json_valid')){
await db.sequelize.query('alter table settings modify `value` JSON')
await db.sequelize.query('alter table ap_users modify `object` JSON')
await db.sequelize.query('alter table events modify `recurrent` JSON')
await db.sequelize.query('alter table events modify `likes` JSON')
await db.sequelize.query('alter table events modify `boost` JSON')
await db.sequelize.query('alter table events modify `media` JSON')
await db.sequelize.query('alter table events modify `online_locations` JSON')
await db.sequelize.query('alter table filters modify `tags` JSON')
await db.sequelize.query('alter table filters modify `places` JSON')
await db.sequelize.query('alter table instances modify `data` JSON')
await db.sequelize.query('alter table notifications modify `filters` JSON')
await db.sequelize.query('alter table resources modify `data` JSON')
await db.sequelize.query('alter table users modify `settings` JSON')
await db.sequelize.query('alter table users modify `rsa` JSON')
log.info(`MariaDB JSON migrations done`)
} else {
log.debug('MariaDB JSON issue already fixed')
}
} catch (e) {
console.error(e)
}
}
},
async runMigrations() {
const logging = config.status !== 'READY' ? false : log.debug.bind(log)
const umzug = new Umzug({
storage: 'sequelize',
storageOptions: { sequelize: db.sequelize },

View file

@ -30,6 +30,7 @@ const initialize = {
await db.sequelize.authenticate()
log.debug('Running migrations')
await db.runMigrations()
await db.fixMariaDBJSON()
await settingsController.load()
config.status = 'READY'
} else {