🗃️ db: redesign collection schema with manual pivot table to media
This commit is contained in:
@ -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
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `_MediaCollections` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "_MediaCollections" DROP CONSTRAINT "_MediaCollections_A_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "_MediaCollections" DROP CONSTRAINT "_MediaCollections_B_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "_MediaCollections";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "CollectionMedia" (
|
||||
"id" UUID NOT NULL,
|
||||
"collectionId" UUID NOT NULL,
|
||||
"mediaId" UUID NOT NULL,
|
||||
"savedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "CollectionMedia_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "CollectionMedia_collectionId_mediaId_key" ON "CollectionMedia"("collectionId", "mediaId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "CollectionMedia" ADD CONSTRAINT "CollectionMedia_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "collections"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "CollectionMedia" ADD CONSTRAINT "CollectionMedia_mediaId_fkey" FOREIGN KEY ("mediaId") REFERENCES "medias"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@ -52,8 +52,8 @@ model Media {
|
||||
bannerPromotion HeroBanner[] @relation("MediaBannerPromotion")
|
||||
logs MediaLog[] @relation("MediaLogs")
|
||||
episodes Episode[] @relation("MediaEpisodes")
|
||||
collections Collection[] @relation("MediaCollections")
|
||||
reviews MediaReview[] @relation("MediaReviews")
|
||||
inCollections CollectionMedia[] @relation("CollectionMedia")
|
||||
|
||||
@@index([status, onDraft, deletedAt])
|
||||
@@index([mediaType])
|
||||
@ -420,7 +420,6 @@ model Collection {
|
||||
id String @id @db.Uuid
|
||||
name String @db.VarChar(115)
|
||||
slug String @db.VarChar(115)
|
||||
medias Media[] @relation("MediaCollections")
|
||||
owner User @relation("UserCollections", fields: [ownerId], references: [id])
|
||||
ownerId String @db.Uuid
|
||||
accessStatus AccessStatus @default(private)
|
||||
@ -431,10 +430,21 @@ model Collection {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
media_saved CollectionMedia[] @relation("CollectionMedia")
|
||||
@@unique([slug, ownerId])
|
||||
@@map("collections")
|
||||
}
|
||||
|
||||
model CollectionMedia {
|
||||
id String @id @db.Uuid
|
||||
collection Collection @relation("CollectionMedia", fields: [collectionId], references: [id])
|
||||
collectionId String @db.Uuid
|
||||
media Media @relation("CollectionMedia", fields: [mediaId], references: [id])
|
||||
mediaId String @db.Uuid
|
||||
savedAt DateTime @default(now())
|
||||
@@unique([collectionId, mediaId])
|
||||
}
|
||||
|
||||
model WatchHistory {
|
||||
id String @id @db.Uuid
|
||||
episode Episode @relation("EpisodeWatchHistories", fields: [id], references: [id])
|
||||
|
||||
Reference in New Issue
Block a user