🗃️ 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]
|
bannerPromotion hero_banner [not null]
|
||||||
logs media_logs [not null]
|
logs media_logs [not null]
|
||||||
episodes episodes [not null]
|
episodes episodes [not null]
|
||||||
collections collections [not null]
|
|
||||||
reviews movie_reviews [not null]
|
reviews movie_reviews [not null]
|
||||||
|
inCollections CollectionMedia [not null]
|
||||||
}
|
}
|
||||||
|
|
||||||
Table media_logs {
|
Table media_logs {
|
||||||
@ -370,7 +370,6 @@ Table collections {
|
|||||||
id String [pk]
|
id String [pk]
|
||||||
name String [not null]
|
name String [not null]
|
||||||
slug String [not null]
|
slug String [not null]
|
||||||
medias medias [not null]
|
|
||||||
owner users [not null]
|
owner users [not null]
|
||||||
ownerId String [not null]
|
ownerId String [not null]
|
||||||
accessStatus AccessStatus [not null, default: 'private']
|
accessStatus AccessStatus [not null, default: 'private']
|
||||||
@ -380,12 +379,26 @@ Table collections {
|
|||||||
deletedAt DateTime
|
deletedAt DateTime
|
||||||
createdAt DateTime [default: `now()`, not null]
|
createdAt DateTime [default: `now()`, not null]
|
||||||
updatedAt DateTime [default: `now()`, not null]
|
updatedAt DateTime [default: `now()`, not null]
|
||||||
|
media_saved CollectionMedia [not null]
|
||||||
|
|
||||||
indexes {
|
indexes {
|
||||||
(slug, ownerId) [unique]
|
(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 {
|
Table watch_histories {
|
||||||
id String [pk]
|
id String [pk]
|
||||||
episode episodes [not null]
|
episode episodes [not null]
|
||||||
@ -562,9 +575,9 @@ Table MediaCharacters {
|
|||||||
mediasId String [ref: > medias.id]
|
mediasId String [ref: > medias.id]
|
||||||
}
|
}
|
||||||
|
|
||||||
Table MediaCollections {
|
Table CollectionMedia {
|
||||||
collectionsId String [ref: > collections.id]
|
incollectionsId String [ref: > CollectionMedia.id]
|
||||||
mediasId String [ref: > medias.id]
|
media_savedId String [ref: > CollectionMedia.id]
|
||||||
}
|
}
|
||||||
|
|
||||||
Table UserFavoriteGenres {
|
Table UserFavoriteGenres {
|
||||||
@ -752,6 +765,10 @@ Ref: user_logs.sessionId > user_sessions.id
|
|||||||
|
|
||||||
Ref: collections.ownerId > users.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.id > episodes.id
|
||||||
|
|
||||||
Ref: watch_histories.userId > users.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")
|
bannerPromotion HeroBanner[] @relation("MediaBannerPromotion")
|
||||||
logs MediaLog[] @relation("MediaLogs")
|
logs MediaLog[] @relation("MediaLogs")
|
||||||
episodes Episode[] @relation("MediaEpisodes")
|
episodes Episode[] @relation("MediaEpisodes")
|
||||||
collections Collection[] @relation("MediaCollections")
|
|
||||||
reviews MediaReview[] @relation("MediaReviews")
|
reviews MediaReview[] @relation("MediaReviews")
|
||||||
|
inCollections CollectionMedia[] @relation("CollectionMedia")
|
||||||
|
|
||||||
@@index([status, onDraft, deletedAt])
|
@@index([status, onDraft, deletedAt])
|
||||||
@@index([mediaType])
|
@@index([mediaType])
|
||||||
@ -420,7 +420,6 @@ model Collection {
|
|||||||
id String @id @db.Uuid
|
id String @id @db.Uuid
|
||||||
name String @db.VarChar(115)
|
name String @db.VarChar(115)
|
||||||
slug String @db.VarChar(115)
|
slug String @db.VarChar(115)
|
||||||
medias Media[] @relation("MediaCollections")
|
|
||||||
owner User @relation("UserCollections", fields: [ownerId], references: [id])
|
owner User @relation("UserCollections", fields: [ownerId], references: [id])
|
||||||
ownerId String @db.Uuid
|
ownerId String @db.Uuid
|
||||||
accessStatus AccessStatus @default(private)
|
accessStatus AccessStatus @default(private)
|
||||||
@ -431,10 +430,21 @@ model Collection {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
|
media_saved CollectionMedia[] @relation("CollectionMedia")
|
||||||
@@unique([slug, ownerId])
|
@@unique([slug, ownerId])
|
||||||
@@map("collections")
|
@@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 {
|
model WatchHistory {
|
||||||
id String @id @db.Uuid
|
id String @id @db.Uuid
|
||||||
episode Episode @relation("EpisodeWatchHistories", fields: [id], references: [id])
|
episode Episode @relation("EpisodeWatchHistories", fields: [id], references: [id])
|
||||||
|
|||||||
Reference in New Issue
Block a user