mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Change migration to v2.17.4
This commit is contained in:
parent
8c3ba67583
commit
9917f2d358
@ -8,4 +8,4 @@ Please add a record of every database migration that you create to this file. Th
|
|||||||
| v2.15.1 | v2.15.1-reindex-nocase | Fix potential db corruption issues due to bad sqlite extension introduced in v2.12.0 |
|
| v2.15.1 | v2.15.1-reindex-nocase | Fix potential db corruption issues due to bad sqlite extension introduced in v2.12.0 |
|
||||||
| v2.15.2 | v2.15.2-index-creation | Creates author, series, and podcast episode indexes |
|
| v2.15.2 | v2.15.2-index-creation | Creates author, series, and podcast episode indexes |
|
||||||
| v2.17.0 | v2.17.0-uuid-replacement | Changes the data type of columns with UUIDv4 to UUID matching the associated model |
|
| v2.17.0 | v2.17.0-uuid-replacement | Changes the data type of columns with UUIDv4 to UUID matching the associated model |
|
||||||
| v2.17.3 | v2.17.3-use-subfolder-for-oidc-redirect-uris | Save subfolder to OIDC redirect URIs to support existing installations |
|
| v2.17.4 | v2.17.4-use-subfolder-for-oidc-redirect-uris | Save subfolder to OIDC redirect URIs to support existing installations |
|
||||||
|
@ -18,18 +18,18 @@
|
|||||||
*/
|
*/
|
||||||
async function up({ context: { queryInterface, logger } }) {
|
async function up({ context: { queryInterface, logger } }) {
|
||||||
// Upwards migration script
|
// Upwards migration script
|
||||||
logger.info('[2.17.3 migration] UPGRADE BEGIN: 2.17.3-use-subfolder-for-oidc-redirect-uris')
|
logger.info('[2.17.4 migration] UPGRADE BEGIN: 2.17.4-use-subfolder-for-oidc-redirect-uris')
|
||||||
|
|
||||||
const serverSettings = await getServerSettings(queryInterface, logger)
|
const serverSettings = await getServerSettings(queryInterface, logger)
|
||||||
if (serverSettings.authActiveAuthMethods?.includes('openid')) {
|
if (serverSettings.authActiveAuthMethods?.includes('openid')) {
|
||||||
logger.info('[2.17.3 migration] OIDC is enabled, adding authOpenIDSubfolderForRedirectURLs to server settings')
|
logger.info('[2.17.4 migration] OIDC is enabled, adding authOpenIDSubfolderForRedirectURLs to server settings')
|
||||||
serverSettings.authOpenIDSubfolderForRedirectURLs = ''
|
serverSettings.authOpenIDSubfolderForRedirectURLs = ''
|
||||||
await updateServerSettings(queryInterface, logger, serverSettings)
|
await updateServerSettings(queryInterface, logger, serverSettings)
|
||||||
} else {
|
} else {
|
||||||
logger.info('[2.17.3 migration] OIDC is not enabled, no action required')
|
logger.info('[2.17.4 migration] OIDC is not enabled, no action required')
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('[2.17.3 migration] UPGRADE END: 2.17.3-use-subfolder-for-oidc-redirect-uris')
|
logger.info('[2.17.4 migration] UPGRADE END: 2.17.4-use-subfolder-for-oidc-redirect-uris')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,25 +40,25 @@ async function up({ context: { queryInterface, logger } }) {
|
|||||||
*/
|
*/
|
||||||
async function down({ context: { queryInterface, logger } }) {
|
async function down({ context: { queryInterface, logger } }) {
|
||||||
// Downward migration script
|
// Downward migration script
|
||||||
logger.info('[2.17.3 migration] DOWNGRADE BEGIN: 2.17.3-use-subfolder-for-oidc-redirect-uris ')
|
logger.info('[2.17.4 migration] DOWNGRADE BEGIN: 2.17.4-use-subfolder-for-oidc-redirect-uris ')
|
||||||
|
|
||||||
// Remove the OIDC subfolder option from the server settings
|
// Remove the OIDC subfolder option from the server settings
|
||||||
const serverSettings = await getServerSettings(queryInterface, logger)
|
const serverSettings = await getServerSettings(queryInterface, logger)
|
||||||
if (serverSettings.authOpenIDSubfolderForRedirectURLs !== undefined) {
|
if (serverSettings.authOpenIDSubfolderForRedirectURLs !== undefined) {
|
||||||
logger.info('[2.17.3 migration] Removing authOpenIDSubfolderForRedirectURLs from server settings')
|
logger.info('[2.17.4 migration] Removing authOpenIDSubfolderForRedirectURLs from server settings')
|
||||||
delete serverSettings.authOpenIDSubfolderForRedirectURLs
|
delete serverSettings.authOpenIDSubfolderForRedirectURLs
|
||||||
await updateServerSettings(queryInterface, logger, serverSettings)
|
await updateServerSettings(queryInterface, logger, serverSettings)
|
||||||
} else {
|
} else {
|
||||||
logger.info('[2.17.3 migration] authOpenIDSubfolderForRedirectURLs not found in server settings, no action required')
|
logger.info('[2.17.4 migration] authOpenIDSubfolderForRedirectURLs not found in server settings, no action required')
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('[2.17.3 migration] DOWNGRADE END: 2.17.3-use-subfolder-for-oidc-redirect-uris ')
|
logger.info('[2.17.4 migration] DOWNGRADE END: 2.17.4-use-subfolder-for-oidc-redirect-uris ')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getServerSettings(queryInterface, logger) {
|
async function getServerSettings(queryInterface, logger) {
|
||||||
const result = await queryInterface.sequelize.query('SELECT value FROM settings WHERE key = "server-settings";')
|
const result = await queryInterface.sequelize.query('SELECT value FROM settings WHERE key = "server-settings";')
|
||||||
if (!result[0].length) {
|
if (!result[0].length) {
|
||||||
logger.error('[2.17.3 migration] Server settings not found')
|
logger.error('[2.17.4 migration] Server settings not found')
|
||||||
throw new Error('Server settings not found')
|
throw new Error('Server settings not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ async function getServerSettings(queryInterface, logger) {
|
|||||||
try {
|
try {
|
||||||
serverSettings = JSON.parse(result[0][0].value)
|
serverSettings = JSON.parse(result[0][0].value)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[2.17.3 migration] Error parsing server settings:', error)
|
logger.error('[2.17.4 migration] Error parsing server settings:', error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const { up, down } = require('../../../server/migrations/v2.17.3-use-subfolder-for-oidc-redirect-uris')
|
const { up, down } = require('../../../server/migrations/v2.17.4-use-subfolder-for-oidc-redirect-uris')
|
||||||
const { Sequelize } = require('sequelize')
|
const { Sequelize } = require('sequelize')
|
||||||
const Logger = require('../../../server/Logger')
|
const Logger = require('../../../server/Logger')
|
||||||
|
|
||||||
describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
describe('Migration v2.17.4-use-subfolder-for-oidc-redirect-uris', () => {
|
||||||
let queryInterface, logger, context
|
let queryInterface, logger, context
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -27,8 +27,8 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
|
|
||||||
await up({ context })
|
await up({ context })
|
||||||
|
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] UPGRADE BEGIN: 2.17.3-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] UPGRADE BEGIN: 2.17.4-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] OIDC is enabled, adding authOpenIDSubfolderForRedirectURLs to server settings')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] OIDC is enabled, adding authOpenIDSubfolderForRedirectURLs to server settings')).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledTwice).to.be.true
|
expect(queryInterface.sequelize.query.calledTwice).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
||||||
expect(
|
expect(
|
||||||
@ -38,7 +38,7 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
).to.be.true
|
).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] UPGRADE END: 2.17.3-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] UPGRADE END: 2.17.4-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not add authOpenIDSubfolderForRedirectURLs if OIDC is not enabled', async () => {
|
it('should not add authOpenIDSubfolderForRedirectURLs if OIDC is not enabled', async () => {
|
||||||
@ -46,11 +46,11 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
|
|
||||||
await up({ context })
|
await up({ context })
|
||||||
|
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] UPGRADE BEGIN: 2.17.3-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] UPGRADE BEGIN: 2.17.4-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] OIDC is not enabled, no action required')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] OIDC is not enabled, no action required')).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] UPGRADE END: 2.17.3-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] UPGRADE END: 2.17.4-use-subfolder-for-oidc-redirect-uris')).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an error if server settings cannot be parsed', async () => {
|
it('should throw an error if server settings cannot be parsed', async () => {
|
||||||
@ -61,7 +61,7 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
||||||
expect(logger.error.calledWith('[2.17.3 migration] Error parsing server settings:')).to.be.true
|
expect(logger.error.calledWith('[2.17.4 migration] Error parsing server settings:')).to.be.true
|
||||||
expect(error).to.be.instanceOf(Error)
|
expect(error).to.be.instanceOf(Error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -74,7 +74,7 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
||||||
expect(logger.error.calledWith('[2.17.3 migration] Server settings not found')).to.be.true
|
expect(logger.error.calledWith('[2.17.4 migration] Server settings not found')).to.be.true
|
||||||
expect(error).to.be.instanceOf(Error)
|
expect(error).to.be.instanceOf(Error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -87,8 +87,8 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
|
|
||||||
await down({ context })
|
await down({ context })
|
||||||
|
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] DOWNGRADE BEGIN: 2.17.3-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] DOWNGRADE BEGIN: 2.17.4-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] Removing authOpenIDSubfolderForRedirectURLs from server settings')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] Removing authOpenIDSubfolderForRedirectURLs from server settings')).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledTwice).to.be.true
|
expect(queryInterface.sequelize.query.calledTwice).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
||||||
expect(
|
expect(
|
||||||
@ -98,7 +98,7 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
).to.be.true
|
).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] DOWNGRADE END: 2.17.3-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] DOWNGRADE END: 2.17.4-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not remove authOpenIDSubfolderForRedirectURLs if it does not exist', async () => {
|
it('should not remove authOpenIDSubfolderForRedirectURLs if it does not exist', async () => {
|
||||||
@ -106,11 +106,11 @@ describe('Migration v2.17.3-use-subfolder-for-oidc-redirect-uris', () => {
|
|||||||
|
|
||||||
await down({ context })
|
await down({ context })
|
||||||
|
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] DOWNGRADE BEGIN: 2.17.3-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] DOWNGRADE BEGIN: 2.17.4-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] authOpenIDSubfolderForRedirectURLs not found in server settings, no action required')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] authOpenIDSubfolderForRedirectURLs not found in server settings, no action required')).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
expect(queryInterface.sequelize.query.calledOnce).to.be.true
|
||||||
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
expect(queryInterface.sequelize.query.calledWith('SELECT value FROM settings WHERE key = "server-settings";')).to.be.true
|
||||||
expect(logger.info.calledWith('[2.17.3 migration] DOWNGRADE END: 2.17.3-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
expect(logger.info.calledWith('[2.17.4 migration] DOWNGRADE END: 2.17.4-use-subfolder-for-oidc-redirect-uris ')).to.be.true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user