From f4bcafe85a8b13ebbeb805fbb9cffb5086c0ba73 Mon Sep 17 00:00:00 2001 From: Mathias Private Laptop Date: Sat, 13 Apr 2024 18:07:53 +0200 Subject: [PATCH] refactor(database): restructure database entities --- apps/api/prisma/schema.prisma | 117 ------------------ apps/api/prisma/subschemas/account.prisma | 9 -- apps/api/prisma/subschemas/actor.prisma | 7 -- apps/api/prisma/subschemas/base.prisma | 17 --- apps/api/prisma/subschemas/language.prisma | 7 -- apps/api/prisma/subschemas/movie.prisma | 12 -- apps/api/prisma/subschemas/movieTitle.prisma | 8 -- apps/api/prisma/subschemas/rating.prisma | 9 -- .../subschemas/streamingAvailability.prisma | 11 -- .../prisma/subschemas/streamingService.prisma | 6 - .../subschemas/subscriptionOffer.prisma | 9 -- apps/api/prisma/subschemas/subtitle.prisma | 8 -- apps/api/prisma/subschemas/user.prisma | 5 - apps/api/prisma/subschemas/watchlist.prisma | 6 - .../database}/prisma.service.ts | 0 apps/api/src/database/schema.prisma | 28 +++++ 16 files changed, 28 insertions(+), 231 deletions(-) delete mode 100644 apps/api/prisma/schema.prisma delete mode 100644 apps/api/prisma/subschemas/account.prisma delete mode 100644 apps/api/prisma/subschemas/actor.prisma delete mode 100644 apps/api/prisma/subschemas/base.prisma delete mode 100644 apps/api/prisma/subschemas/language.prisma delete mode 100644 apps/api/prisma/subschemas/movie.prisma delete mode 100644 apps/api/prisma/subschemas/movieTitle.prisma delete mode 100644 apps/api/prisma/subschemas/rating.prisma delete mode 100644 apps/api/prisma/subschemas/streamingAvailability.prisma delete mode 100644 apps/api/prisma/subschemas/streamingService.prisma delete mode 100644 apps/api/prisma/subschemas/subscriptionOffer.prisma delete mode 100644 apps/api/prisma/subschemas/subtitle.prisma delete mode 100644 apps/api/prisma/subschemas/user.prisma delete mode 100644 apps/api/prisma/subschemas/watchlist.prisma rename apps/api/{prisma => src/database}/prisma.service.ts (100%) create mode 100644 apps/api/src/database/schema.prisma diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma deleted file mode 100644 index 99f2d3b..0000000 --- a/apps/api/prisma/schema.prisma +++ /dev/null @@ -1,117 +0,0 @@ -//🧩Don't Edit this file.✨Generated in Tue Apr 09 2024 21:19:58 GMT+0200 (Central European Summer Time)✨ -model Account { - id Int @id @default(autoincrement()) - streamingService String - username String @unique - password String - user User @relation(fields: [userId], references: [id]) - userId Int - subscriptionOffers SubscriptionOffer[] -} - -model Actor { - actorId Int @id @default(autoincrement()) - firstName String - lastName String - birthDate DateTime? - movies Movie[] @relation("ParticipatesIn") -} - -generator client { - provider = "prisma-client-js" -} - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -model Language { - id Int @id @default(autoincrement()) - name String - streamingAvailabilities StreamingAvailability[] - movieTitles MovieTitle[] - subtitles Subtitle[] -} - -model Movie { - id Int @id @default(autoincrement()) - director String - genre String - duration Int - releaseDate DateTime - movieTitle MovieTitle[] - subtitles Subtitle[] - ratings Rating[] - streamingDetails StreamingAvailability[] - actors Actor[] @relation("ParticipatesIn") -} - -model MovieTitle { - movieTitleId Int @id @default(autoincrement()) - movieId Int - languageId Int - title String - Movie Movie @relation(fields: [movieId], references: [id]) - Language Language @relation(fields: [languageId], references: [id]) -} - -model Rating { - ratingId Int @id @default(autoincrement()) - movieId Int - site String - rating Float - link String? - Movie Movie @relation(fields: [movieId], references: [id]) -} - -model StreamingAvailability { - streamingId Int @id @default(autoincrement()) - movieId Int - currentAvailability Boolean - whenBecomesAvailable DateTime? - whenExpires DateTime? - languages Language[] - deepLink String? - Movie Movie @relation(fields: [movieId], references: [id]) - StreamingService StreamingService[] -} - -model StreamingService { - companyId Int @id @default(autoincrement()) - companyName String - subscriptionOffers SubscriptionOffer[] - streamingAvailabilities StreamingAvailability[] -} - -model SubscriptionOffer { - subscriptionId Int @id @default(autoincrement()) - companyId Int - accountId Int - cost Float - active Boolean - StreamingService StreamingService @relation(fields: [companyId], references: [companyId]) - Account Account @relation(fields: [accountId], references: [id]) -} - -model Subtitle { - languageId Int - movieId Int - Language Language @relation(fields: [languageId], references: [id]) - Movie Movie @relation(fields: [movieId], references: [id]) - - @@id([languageId, movieId]) -} - -model User { - id Int @id @default(autoincrement()) - watchLists Watchlist[] - accounts Account[] -} - -model Watchlist { - watchlistId Int @id @default(autoincrement()) - userId Int - name String - User User @relation(fields: [userId], references: [id]) -} diff --git a/apps/api/prisma/subschemas/account.prisma b/apps/api/prisma/subschemas/account.prisma deleted file mode 100644 index 31e67a3..0000000 --- a/apps/api/prisma/subschemas/account.prisma +++ /dev/null @@ -1,9 +0,0 @@ -model Account { - id Int @id @default(autoincrement()) - streamingService String - username String @unique - password String - user User @relation(fields: [userId], references: [id]) - userId Int - subscriptionOffers SubscriptionOffer[] -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/actor.prisma b/apps/api/prisma/subschemas/actor.prisma deleted file mode 100644 index 67bf520..0000000 --- a/apps/api/prisma/subschemas/actor.prisma +++ /dev/null @@ -1,7 +0,0 @@ -model Actor { - actorId Int @id @default(autoincrement()) - firstName String - lastName String - birthDate DateTime? - movies Movie[] @relation("ParticipatesIn") -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/base.prisma b/apps/api/prisma/subschemas/base.prisma deleted file mode 100644 index d7e1c96..0000000 --- a/apps/api/prisma/subschemas/base.prisma +++ /dev/null @@ -1,17 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////// -///// Auto Commented Out by πŸ…ΏπŸ†πŸ…ΈπŸ†‚πŸ…ΌπŸ…°-πŸ…ΌπŸ†„πŸ…»πŸ†ƒπŸ…ΈπŸ†‚πŸ…²πŸ…·πŸ…΄πŸ…ΌπŸ…° //////// -///// Detected : Datasource and Generator Client //////// -///// You can change this files content is commented or Uncommented Stage. //////// -///// It will take effect after you run npx prisma-multischema //////// -///// Feel free to change Datasource/ Database URL / Provider / Binary Targets //////// -///// DO NOT EDIT in this comment box //////// -///// CHANGE ONLY BELOW THIS LINE. //////// -///////////////////////////////////////////////////////////////////////////////////////// - -//generator client { -//provider = "prisma-client-js" -//} -//datasource db { -//provider = "postgresql" -//url = env("DATABASE_URL") -//} diff --git a/apps/api/prisma/subschemas/language.prisma b/apps/api/prisma/subschemas/language.prisma deleted file mode 100644 index 25ba20c..0000000 --- a/apps/api/prisma/subschemas/language.prisma +++ /dev/null @@ -1,7 +0,0 @@ -model Language { - id Int @id @default(autoincrement()) - name String - streamingAvailabilities StreamingAvailability[] - movieTitles MovieTitle[] - subtitles Subtitle[] -} diff --git a/apps/api/prisma/subschemas/movie.prisma b/apps/api/prisma/subschemas/movie.prisma deleted file mode 100644 index d400f9d..0000000 --- a/apps/api/prisma/subschemas/movie.prisma +++ /dev/null @@ -1,12 +0,0 @@ -model Movie { - id Int @id @default(autoincrement()) - director String - genre String - duration Int - releaseDate DateTime - movieTitle MovieTitle[] - subtitles Subtitle[] - ratings Rating[] - streamingDetails StreamingAvailability[] - actors Actor[] @relation("ParticipatesIn") -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/movieTitle.prisma b/apps/api/prisma/subschemas/movieTitle.prisma deleted file mode 100644 index 3a72bfb..0000000 --- a/apps/api/prisma/subschemas/movieTitle.prisma +++ /dev/null @@ -1,8 +0,0 @@ -model MovieTitle { - movieTitleId Int @id @default(autoincrement()) - movieId Int - languageId Int - title String - Movie Movie @relation(fields: [movieId], references: [id]) - Language Language @relation(fields: [languageId], references: [id]) -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/rating.prisma b/apps/api/prisma/subschemas/rating.prisma deleted file mode 100644 index 2ac810d..0000000 --- a/apps/api/prisma/subschemas/rating.prisma +++ /dev/null @@ -1,9 +0,0 @@ - -model Rating { - ratingId Int @id @default(autoincrement()) - movieId Int - site String - rating Float - link String? - Movie Movie @relation(fields: [movieId], references: [id]) -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/streamingAvailability.prisma b/apps/api/prisma/subschemas/streamingAvailability.prisma deleted file mode 100644 index 40244f1..0000000 --- a/apps/api/prisma/subschemas/streamingAvailability.prisma +++ /dev/null @@ -1,11 +0,0 @@ -model StreamingAvailability { - streamingId Int @id @default(autoincrement()) - movieId Int - currentAvailability Boolean - whenBecomesAvailable DateTime? - whenExpires DateTime? - languages Language[] - deepLink String? - Movie Movie @relation(fields: [movieId], references: [id]) - StreamingService StreamingService[] -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/streamingService.prisma b/apps/api/prisma/subschemas/streamingService.prisma deleted file mode 100644 index daa0c18..0000000 --- a/apps/api/prisma/subschemas/streamingService.prisma +++ /dev/null @@ -1,6 +0,0 @@ -model StreamingService { - companyId Int @id @default(autoincrement()) - companyName String - subscriptionOffers SubscriptionOffer[] - streamingAvailabilities StreamingAvailability[] -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/subscriptionOffer.prisma b/apps/api/prisma/subschemas/subscriptionOffer.prisma deleted file mode 100644 index 7cb4c19..0000000 --- a/apps/api/prisma/subschemas/subscriptionOffer.prisma +++ /dev/null @@ -1,9 +0,0 @@ -model SubscriptionOffer { - subscriptionId Int @id @default(autoincrement()) - companyId Int - accountId Int - cost Float - active Boolean - StreamingService StreamingService @relation(fields: [companyId], references: [companyId]) - Account Account @relation(fields: [accountId], references: [id]) -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/subtitle.prisma b/apps/api/prisma/subschemas/subtitle.prisma deleted file mode 100644 index 9eef298..0000000 --- a/apps/api/prisma/subschemas/subtitle.prisma +++ /dev/null @@ -1,8 +0,0 @@ -model Subtitle { - languageId Int - movieId Int - Language Language @relation(fields: [languageId], references: [id]) - Movie Movie @relation(fields: [movieId], references: [id]) - - @@id([languageId, movieId]) -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/user.prisma b/apps/api/prisma/subschemas/user.prisma deleted file mode 100644 index f9c6a30..0000000 --- a/apps/api/prisma/subschemas/user.prisma +++ /dev/null @@ -1,5 +0,0 @@ -model User { - id Int @id @default(autoincrement()) - watchLists Watchlist[] - accounts Account[] -} \ No newline at end of file diff --git a/apps/api/prisma/subschemas/watchlist.prisma b/apps/api/prisma/subschemas/watchlist.prisma deleted file mode 100644 index a3d3996..0000000 --- a/apps/api/prisma/subschemas/watchlist.prisma +++ /dev/null @@ -1,6 +0,0 @@ -model Watchlist { - watchlistId Int @id @default(autoincrement()) - userId Int - name String - User User @relation(fields: [userId], references: [id]) -} diff --git a/apps/api/prisma/prisma.service.ts b/apps/api/src/database/prisma.service.ts similarity index 100% rename from apps/api/prisma/prisma.service.ts rename to apps/api/src/database/prisma.service.ts diff --git a/apps/api/src/database/schema.prisma b/apps/api/src/database/schema.prisma new file mode 100644 index 0000000..38dfd3c --- /dev/null +++ b/apps/api/src/database/schema.prisma @@ -0,0 +1,28 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +model Movie { + id Int @id @default(autoincrement()) + genre String + director String + duration Int + subtitles String[] + releaseDate DateTime @map("release_date") + + movieTitle MovieTitle[] +} + +model MovieTitle { + movieTitleId Int @id @default(autoincrement()) @map("movie_title_id") + movieId Int @map("movie_id") + Movie Movie @relation(fields: [movieId], references: [id]) + language String + title String +} +