🗃️ db: redesign collection schema with manual pivot table to media

This commit is contained in:
2026-03-29 10:43:20 +07:00
parent 3768ae4c26
commit f1e79945b0
3 changed files with 71 additions and 11 deletions

View File

@ -31,8 +31,8 @@ Table medias {
bannerPromotion hero_banner [not null]
logs media_logs [not null]
episodes episodes [not null]
collections collections [not null]
reviews movie_reviews [not null]
inCollections CollectionMedia [not null]
}
Table media_logs {
@ -370,7 +370,6 @@ Table collections {
id String [pk]
name String [not null]
slug String [not null]
medias medias [not null]
owner users [not null]
ownerId String [not null]
accessStatus AccessStatus [not null, default: 'private']
@ -380,12 +379,26 @@ Table collections {
deletedAt DateTime
createdAt DateTime [default: `now()`, not null]
updatedAt DateTime [default: `now()`, not null]
media_saved CollectionMedia [not null]
indexes {
(slug, ownerId) [unique]
}
}
Table CollectionMedia {
id String [pk]
collection collections [not null]
collectionId String [not null]
media medias [not null]
mediaId String [not null]
savedAt DateTime [default: `now()`, not null]
indexes {
(collectionId, mediaId) [unique]
}
}
Table watch_histories {
id String [pk]
episode episodes [not null]
@ -562,9 +575,9 @@ Table MediaCharacters {
mediasId String [ref: > medias.id]
}
Table MediaCollections {
collectionsId String [ref: > collections.id]
mediasId String [ref: > medias.id]
Table CollectionMedia {
incollectionsId String [ref: > CollectionMedia.id]
media_savedId String [ref: > CollectionMedia.id]
}
Table UserFavoriteGenres {
@ -752,6 +765,10 @@ Ref: user_logs.sessionId > user_sessions.id
Ref: collections.ownerId > users.id
Ref: CollectionMedia.collectionId > collections.id
Ref: CollectionMedia.mediaId > medias.id
Ref: watch_histories.id > episodes.id
Ref: watch_histories.userId > users.id