feat(db): update Repository model to forkedFromRepo and forks fields
+ 5
- 1
new file
db/migrations/20220927024819_rework_repository_model_to_add_fork_relationships/migration.sql
@@ -0,0 +1,2 @@
+-- AddForeignKey
+ALTER TABLE "Repository" ADD CONSTRAINT "Repository_forkedFromRepoId_fkey" FOREIGN KEY ("forkedFromRepoId") REFERENCES "Repository"("id") ON DELETE SET NULL ON UPDATE CASCADE;

@@ -1,6 +1,6 @@
 generator client {
   provider        = "prisma-client-js"
-  previewFeatures = ["fullTextSearch","interactiveTransactions","orderByNulls"]
+  previewFeatures = ["fullTextSearch", "interactiveTransactions", "orderByNulls"]
   binaryTargets   = ["native", "linux-musl", "debian-openssl-1.1.x"]
 }
 

...
@@ -51,7 +51,9 @@ model Repository {
   organizationId   String
   visibility       ResourceVisibility @default(PRIVATE)
   forkedFromRepoId String?
+  forkedFromRepo   Repository?        @relation("OneParentRepositoryToManyForkRepository", fields: [forkedFromRepoId], references: [id])
   isFork           Boolean            @default(false)
+  forks            Repository[]       @relation("OneParentRepositoryToManyForkRepository")
   lastPushedAt     DateTime?
   organization     Organization       @relation("ManyRepositoriesToOneOrganization", fields: [organizationId], references: [id])
 }