Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaId UUID migration #3597

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/migrations/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Please add a record of every database migration that you create to this file. Th
| v2.15.0 | v2.15.0-series-column-unique | Series must have unique names in the same library |
| 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.17.0 | v2.17.0-uuid-replacement | Changes the data type of columns with UUIDv4 to UUID matching the associated model |
98 changes: 98 additions & 0 deletions server/migrations/v2.17.0-uuid-replacement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @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 table columns with data type UUIDv4 to UUID to match associated models.
*
* @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.17.0 migration] UPGRADE BEGIN: 2.17.0-uuid-replacement')

logger.info('[2.17.0 migration] Changing libraryItems.mediaId column to UUID')
await queryInterface.changeColumn('libraryItems', 'mediaId', {
type: 'UUID'
})

logger.info('[2.17.0 migration] Changing feeds.entityId column to UUID')
await queryInterface.changeColumn('feeds', 'entityId', {
type: 'UUID'
})

logger.info('[2.17.0 migration] Changing mediaItemShares.mediaItemId column to UUID')
await queryInterface.changeColumn('mediaItemShares', 'mediaItemId', {
type: 'UUID'
})

logger.info('[2.17.0 migration] Changing playbackSessions.mediaItemId column to UUID')
await queryInterface.changeColumn('playbackSessions', 'mediaItemId', {
type: 'UUID'
})

logger.info('[2.17.0 migration] Changing playlistMediaItems.mediaItemId column to UUID')
await queryInterface.changeColumn('playlistMediaItems', 'mediaItemId', {
type: 'UUID'
})

logger.info('[2.17.0 migration] Changing mediaProgresses.mediaItemId column to UUID')
await queryInterface.changeColumn('mediaProgresses', 'mediaItemId', {
type: 'UUID'
})

// Completed migration
logger.info('[2.17.0 migration] UPGRADE END: 2.17.0-uuid-replacement')
}

/**
* This downward migration script changes table columns data type back to UUIDv4.
*
* @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.17.0 migration] DOWNGRADE BEGIN: 2.17.0-uuid-replacement')

logger.info('[2.17.0 migration] Changing libraryItems.mediaId column to UUIDV4')
await queryInterface.changeColumn('libraryItems', 'mediaId', {
type: 'UUIDV4'
})

logger.info('[2.17.0 migration] Changing feeds.entityId column to UUIDV4')
await queryInterface.changeColumn('feeds', 'entityId', {
type: 'UUIDV4'
})

logger.info('[2.17.0 migration] Changing mediaItemShares.mediaItemId column to UUIDV4')
await queryInterface.changeColumn('mediaItemShares', 'mediaItemId', {
type: 'UUIDV4'
})

logger.info('[2.17.0 migration] Changing playbackSessions.mediaItemId column to UUIDV4')
await queryInterface.changeColumn('playbackSessions', 'mediaItemId', {
type: 'UUIDV4'
})

logger.info('[2.17.0 migration] Changing playlistMediaItems.mediaItemId column to UUIDV4')
await queryInterface.changeColumn('playlistMediaItems', 'mediaItemId', {
type: 'UUIDV4'
})

logger.info('[2.17.0 migration] Changing mediaProgresses.mediaItemId column to UUIDV4')
await queryInterface.changeColumn('mediaProgresses', 'mediaItemId', {
type: 'UUIDV4'
})

// Completed migration
logger.info('[2.17.0 migration] DOWNGRADE END: 2.17.0-uuid-replacement')
}

module.exports = { up, down }
2 changes: 1 addition & 1 deletion server/models/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Feed extends Model {
},
slug: DataTypes.STRING,
entityType: DataTypes.STRING,
entityId: DataTypes.UUIDV4,
entityId: DataTypes.UUID,
entityUpdatedAt: DataTypes.DATE,
serverAddress: DataTypes.STRING,
feedURL: DataTypes.STRING,
Expand Down
2 changes: 1 addition & 1 deletion server/models/LibraryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ class LibraryItem extends Model {
ino: DataTypes.STRING,
path: DataTypes.STRING,
relPath: DataTypes.STRING,
mediaId: DataTypes.UUIDV4,
mediaId: DataTypes.UUID,
mediaType: DataTypes.STRING,
isFile: DataTypes.BOOLEAN,
isMissing: DataTypes.BOOLEAN,
Expand Down
2 changes: 1 addition & 1 deletion server/models/MediaItemShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MediaItemShare extends Model {
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
mediaItemId: DataTypes.UUIDV4,
mediaItemId: DataTypes.UUID,
mediaItemType: DataTypes.STRING,
slug: DataTypes.STRING,
pash: DataTypes.STRING,
Expand Down
2 changes: 1 addition & 1 deletion server/models/MediaProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MediaProgress extends Model {
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
mediaItemId: DataTypes.UUIDV4,
mediaItemId: DataTypes.UUID,
mediaItemType: DataTypes.STRING,
duration: DataTypes.FLOAT,
currentTime: DataTypes.FLOAT,
Expand Down
2 changes: 1 addition & 1 deletion server/models/PlaybackSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class PlaybackSession extends Model {
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
mediaItemId: DataTypes.UUIDV4,
mediaItemId: DataTypes.UUID,
mediaItemType: DataTypes.STRING,
displayTitle: DataTypes.STRING,
displayAuthor: DataTypes.STRING,
Expand Down
2 changes: 1 addition & 1 deletion server/models/PlaylistMediaItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PlaylistMediaItem extends Model {
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
mediaItemId: DataTypes.UUIDV4,
mediaItemId: DataTypes.UUID,
mediaItemType: DataTypes.STRING,
order: DataTypes.INTEGER
},
Expand Down
Loading