mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Ensure series-column-unique migration is idempotent
This commit is contained in:
parent
66b290577c
commit
8a7b5cc87d
@ -38,6 +38,7 @@ class MigrationManager {
|
||||
if (!(await fs.pathExists(this.configPath))) throw new Error(`Config path does not exist: ${this.configPath}`)
|
||||
|
||||
this.migrationsDir = path.join(this.configPath, 'migrations')
|
||||
await fs.ensureDir(this.migrationsDir)
|
||||
|
||||
this.serverVersion = this.extractVersionFromTag(serverVersion)
|
||||
if (!this.serverVersion) throw new Error(`Invalid server version: ${serverVersion}. Expected a version tag like v1.2.3.`)
|
||||
@ -222,8 +223,6 @@ class MigrationManager {
|
||||
}
|
||||
|
||||
async copyMigrationsToConfigDir() {
|
||||
await fs.ensureDir(this.migrationsDir) // Ensure the target directory exists
|
||||
|
||||
if (!(await fs.pathExists(this.migrationsSourceDir))) return
|
||||
|
||||
const files = await fs.readdir(this.migrationsSourceDir)
|
||||
|
@ -16,7 +16,15 @@
|
||||
*/
|
||||
async function up({ context: { queryInterface, logger } }) {
|
||||
// Upwards migration script
|
||||
logger.info('UPGRADE BEGIN: 2.13.5-series-column-unique ')
|
||||
logger.info('[2.13.5 migration] UPGRADE BEGIN: 2.13.5-series-column-unique ')
|
||||
|
||||
// Check if the unique index already exists
|
||||
const seriesIndexes = await queryInterface.showIndex('Series')
|
||||
if (seriesIndexes.some((index) => index.name === 'unique_series_name_per_library')) {
|
||||
logger.info('[2.13.5 migration] Unique index on Series.name and Series.libraryId already exists')
|
||||
logger.info('[2.13.5 migration] UPGRADE END: 2.13.5-series-column-unique ')
|
||||
return
|
||||
}
|
||||
|
||||
// The steps taken to deduplicate the series are as follows:
|
||||
// 1. Find all duplicate series in the `Series` table.
|
||||
@ -173,9 +181,9 @@ async function up({ context: { queryInterface, logger } }) {
|
||||
unique: true,
|
||||
name: 'unique_series_name_per_library'
|
||||
})
|
||||
logger.info('Added unique index on Series.name and Series.libraryId')
|
||||
logger.info('[2.13.5 migration] Added unique index on Series.name and Series.libraryId')
|
||||
|
||||
logger.info('UPGRADE END: 2.13.5-series-column-unique ')
|
||||
logger.info('[2.13.5 migration] UPGRADE END: 2.13.5-series-column-unique ')
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,13 +194,13 @@ async function up({ context: { queryInterface, logger } }) {
|
||||
*/
|
||||
async function down({ context: { queryInterface, logger } }) {
|
||||
// Downward migration script
|
||||
logger.info('DOWNGRADE BEGIN: 2.13.5-series-column-unique ')
|
||||
logger.info('[2.13.5 migration] DOWNGRADE BEGIN: 2.13.5-series-column-unique ')
|
||||
|
||||
// Remove the unique index
|
||||
await queryInterface.removeIndex('Series', 'unique_series_name_per_library')
|
||||
logger.info('Removed unique index on Series.name and Series.libraryId')
|
||||
logger.info('[2.13.5 migration] Removed unique index on Series.name and Series.libraryId')
|
||||
|
||||
logger.info('DOWNGRADE END: 2.13.5-series-column-unique ')
|
||||
logger.info('[2.13.5 migration] DOWNGRADE END: 2.13.5-series-column-unique ')
|
||||
}
|
||||
|
||||
module.exports = { up, down }
|
||||
|
Loading…
Reference in New Issue
Block a user