Add: migration for mediaId to use UUID instead of UUIDV4

This commit is contained in:
Nicholas Wallace 2024-11-09 13:10:46 -07:00
parent d7e810fc2f
commit 713bdcbc41
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,50 @@
/**
* @typedef MigrationContext
* @property {import('sequelize').QueryInterface} queryInterface - a suquelize QueryInterface object.
* @property {import('../Logger')} logger - a Logger object.
*
* @typedef MigrationOptions
* @property {MigrationContext} context - an object containing the migration context.
*/
/**
* This upward migration script changes the `mediaId` column in the `libraryItems` table to be a UUID and match other tables.
*
* @param {MigrationOptions} options - an object containing the migration context.
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
*/
async function up({ context: { queryInterface, logger } }) {
// Upwards migration script
logger.info('[2.16.3 migration] UPGRADE BEGIN: 2.16.3-uuid-replacement')
// Change mediaId column to using the query interface
logger.info('[2.16.3 migration] Changing mediaId column to UUID')
await queryInterface.changeColumn('libraryItems', 'mediaId', {
type: 'UUID'
})
// Completed migration
logger.info('[2.16.3 migration] UPGRADE END: 2.16.3-uuid-replacement')
}
/**
* This downward migration script changes the `mediaId` column in the `libraryItems` table to be a UUIDV4 again.
*
* @param {MigrationOptions} options - an object containing the migration context.
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
*/
async function down({ context: { queryInterface, logger } }) {
// Downward migration script
logger.info('[2.16.3 migration] DOWNGRADE BEGIN: 2.16.3-uuid-replacement')
// Change mediaId column to using the query interface
logger.info('[2.16.3 migration] Changing mediaId column to UUIDV4')
await queryInterface.changeColumn('libraryItems', 'mediaId', {
type: 'UUIDV4'
})
// Completed migration
logger.info('[2.16.3 migration] DOWNGRADE END: 2.16.3-uuid-replacement')
}
module.exports = { up, down }

View File

@ -1059,7 +1059,7 @@ class LibraryItem extends Model {
ino: DataTypes.STRING, ino: DataTypes.STRING,
path: DataTypes.STRING, path: DataTypes.STRING,
relPath: DataTypes.STRING, relPath: DataTypes.STRING,
mediaId: DataTypes.UUIDV4, mediaId: DataTypes.UUID,
mediaType: DataTypes.STRING, mediaType: DataTypes.STRING,
isFile: DataTypes.BOOLEAN, isFile: DataTypes.BOOLEAN,
isMissing: DataTypes.BOOLEAN, isMissing: DataTypes.BOOLEAN,