Update Dockerfile for sqlite3, update models for cascade delete, fix backup schedule

This commit is contained in:
advplyr 2023-07-09 11:39:15 -05:00
parent 254ba1f089
commit f73a0cce72
20 changed files with 67 additions and 31 deletions

View file

@ -77,7 +77,9 @@ module.exports = (sequelize) => {
})
const { library } = sequelize.models
library.hasMany(Author)
library.hasMany(Author, {
onDelete: 'CASCADE'
})
Author.belongsTo(library)
return Author

View file

@ -32,10 +32,14 @@ module.exports = (sequelize) => {
book.belongsToMany(collection, { through: CollectionBook })
collection.belongsToMany(book, { through: CollectionBook })
book.hasMany(CollectionBook)
book.hasMany(CollectionBook, {
onDelete: 'CASCADE'
})
CollectionBook.belongsTo(book)
collection.hasMany(CollectionBook)
collection.hasMany(CollectionBook, {
onDelete: 'CASCADE'
})
CollectionBook.belongsTo(collection)
return CollectionBook

View file

@ -32,7 +32,9 @@ module.exports = (sequelize) => {
static async getOldDeviceByDeviceId(deviceId) {
const device = await this.findOne({
deviceId
where: {
deviceId
}
})
if (!device) return null
return device.getOldDevice()
@ -105,7 +107,9 @@ module.exports = (sequelize) => {
const { user } = sequelize.models
user.hasMany(Device)
user.hasMany(Device, {
onDelete: 'CASCADE'
})
Device.belongsTo(user)
return Device

View file

@ -73,7 +73,9 @@ module.exports = (sequelize) => {
const { feed } = sequelize.models
feed.hasMany(FeedEpisode)
feed.hasMany(FeedEpisode, {
onDelete: 'CASCADE'
})
FeedEpisode.belongsTo(feed)
return FeedEpisode

View file

@ -39,18 +39,19 @@ module.exports = (sequelize) => {
* @param {object} oldLibrary
* @returns {Library|null}
*/
static createFromOld(oldLibrary) {
static async createFromOld(oldLibrary) {
const library = this.getFromOld(oldLibrary)
library.libraryFolders = oldLibrary.folders.map(folder => {
return {
id: folder.id,
path: folder.fullPath,
libraryId: library.id
path: folder.fullPath
}
})
return this.create(library).catch((error) => {
return this.create(library, {
include: sequelize.models.libraryFolder
}).catch((error) => {
Logger.error(`[Library] Failed to create library ${library.id}`, error)
return null
})

View file

@ -16,7 +16,9 @@ module.exports = (sequelize) => {
})
const { library } = sequelize.models
library.hasMany(LibraryFolder)
library.hasMany(LibraryFolder, {
onDelete: 'CASCADE'
})
LibraryFolder.belongsTo(library)
return LibraryFolder

View file

@ -134,7 +134,9 @@ module.exports = (sequelize) => {
}
})
user.hasMany(MediaProgress)
user.hasMany(MediaProgress, {
onDelete: 'CASCADE'
})
MediaProgress.belongsTo(user)
return MediaProgress

View file

@ -75,7 +75,9 @@ module.exports = (sequelize) => {
}
})
playlist.hasMany(PlaylistMediaItem)
playlist.hasMany(PlaylistMediaItem, {
onDelete: 'CASCADE'
})
PlaylistMediaItem.belongsTo(playlist)
return PlaylistMediaItem

View file

@ -71,7 +71,9 @@ module.exports = (sequelize) => {
})
const { library } = sequelize.models
library.hasMany(Series)
library.hasMany(Series, {
onDelete: 'CASCADE'
})
Series.belongsTo(library)
return Series

View file

@ -89,9 +89,13 @@ module.exports = (sequelize) => {
})
}
static async createRootUser(username, pash, token) {
static async createRootUser(username, pash, auth) {
const userId = uuidv4()
const token = await auth.generateAccessToken({ userId, username })
const newRoot = new oldUser({
id: uuidv4(),
id: userId,
type: 'root',
username,
pash,