mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-09 02:41:35 +00:00
Added User personal audiobook rating
This commit is contained in:
parent
7c3504fe2b
commit
3bfd9f419c
7 changed files with 264 additions and 46 deletions
59
server/migrations/v2.25.3-add-user-book-ratings.js
Normal file
59
server/migrations/v2.25.3-add-user-book-ratings.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
const { DataTypes } = require('sequelize')
|
||||
|
||||
module.exports = {
|
||||
up: async ({ context: queryInterface }) => {
|
||||
const transaction = await queryInterface.sequelize.transaction()
|
||||
try {
|
||||
await queryInterface.createTable(
|
||||
'userBookRatings',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
userId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: { model: 'users', key: 'id' },
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
bookId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: { model: 'books', key: 'id' },
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
rating: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: false
|
||||
},
|
||||
createdAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
},
|
||||
updatedAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
}
|
||||
},
|
||||
{ transaction }
|
||||
)
|
||||
await queryInterface.addConstraint('userBookRatings', {
|
||||
fields: ['userId', 'bookId'],
|
||||
type: 'unique',
|
||||
name: 'user_book_ratings_unique_constraint',
|
||||
transaction
|
||||
})
|
||||
await transaction.commit()
|
||||
} catch (err) {
|
||||
await transaction.rollback()
|
||||
throw err
|
||||
}
|
||||
},
|
||||
down: async ({ context: queryInterface }) => {
|
||||
await queryInterface.dropTable('userBookRatings')
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue