mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-01 08:44:40 +02:00
Add db migration management infratructure
This commit is contained in:
parent
0344a63b48
commit
3f93b93d9e
13 changed files with 1385 additions and 172 deletions
|
@ -8,6 +8,8 @@ const Logger = require('./Logger')
|
|||
const dbMigration = require('./utils/migrations/dbMigration')
|
||||
const Auth = require('./Auth')
|
||||
|
||||
const MigrationManager = require('./managers/MigrationManager')
|
||||
|
||||
class Database {
|
||||
constructor() {
|
||||
this.sequelize = null
|
||||
|
@ -168,6 +170,16 @@ class Database {
|
|||
throw new Error('Database connection failed')
|
||||
}
|
||||
|
||||
if (!this.isNew) {
|
||||
try {
|
||||
const migrationManager = new MigrationManager(this.sequelize, global.ConfigPath)
|
||||
await migrationManager.runMigrations(packageJson.version)
|
||||
} catch (error) {
|
||||
Logger.error(`[Database] Failed to run migrations`, error)
|
||||
throw new Error('Database migration failed')
|
||||
}
|
||||
}
|
||||
|
||||
await this.buildModels(force)
|
||||
Logger.info(`[Database] Db initialized with models:`, Object.keys(this.sequelize.models).join(', '))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue