audiobookshelf/server/migrations/v2.25.2-add-book-ratings.js
2025-06-27 11:02:42 +02:00

58 lines
1.5 KiB
JavaScript

const { DataTypes } = require('sequelize')
module.exports = {
up: async ({ context: queryInterface }) => {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.addColumn(
'books',
'rating',
{
type: DataTypes.FLOAT
},
{ transaction }
)
await queryInterface.addColumn(
'books',
'providerRating',
{
type: DataTypes.FLOAT
},
{ transaction }
)
await queryInterface.addColumn(
'books',
'provider',
{
type: DataTypes.STRING
},
{ transaction }
)
await queryInterface.addColumn(
'books',
'providerId',
{
type: DataTypes.STRING
},
{ transaction }
)
await transaction.commit()
} catch (err) {
await transaction.rollback()
throw err
}
},
down: async ({ context: queryInterface }) => {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.removeColumn('books', 'rating', { transaction })
await queryInterface.removeColumn('books', 'providerRating', { transaction })
await queryInterface.removeColumn('books', 'provider', { transaction })
await queryInterface.removeColumn('books', 'providerId', { transaction })
await transaction.commit()
} catch (err) {
await transaction.rollback()
throw err
}
}
}