From 42c036dcf5b1d4c7e8767278894ee3a724083102 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 5 Jul 2024 10:13:32 +0200 Subject: [PATCH] chore: split prisma schema into multiple files --- package.json | 4 +- server/database/main.prisma | 11 ++ server/{database => documents}/schema.prisma | 130 ------------------- server/groups/schema.prisma | 50 +++++++ server/journals/schema.prisma | 47 +++++++ server/user/schema.prisma | 19 +++ 6 files changed, 129 insertions(+), 132 deletions(-) create mode 100644 server/database/main.prisma rename server/{database => documents}/schema.prisma (52%) create mode 100644 server/groups/schema.prisma create mode 100644 server/journals/schema.prisma create mode 100644 server/user/schema.prisma diff --git a/package.json b/package.json index e54c5dd14..c791cd6bd 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "generate:watch": "concurrently \"pnpm:*:generate:watch\"", "prisma:migrate:dev": "prisma migrate dev", "prisma:migrate:dev:create": "prisma migrate dev --create-only", - "prisma:migrate:diff": "prisma migrate diff --exit-code --from-migrations server/database/migrations --to-schema-datamodel server/database/schema.prisma --shadow-database-url", + "prisma:migrate:diff": "prisma migrate diff --exit-code --from-migrations server/database/migrations --to-schema-datamodel server --shadow-database-url", "prisma:migrate:reset": "prisma migrate reset", "prisma:migrate:deploy": "prisma migrate deploy", "prisma:migrate:status": "prisma migrate status", @@ -165,7 +165,7 @@ "vue-tsc": "^2.0.19" }, "prisma": { - "schema": "server/database/schema.prisma", + "schema": "server", "seed": "node --experimental-specifier-resolution=node --loader ts-node/esm ./server/database/runSeed.ts" }, "packageManager": "pnpm@8.15.6", diff --git a/server/database/main.prisma b/server/database/main.prisma new file mode 100644 index 000000000..8dd76ad67 --- /dev/null +++ b/server/database/main.prisma @@ -0,0 +1,11 @@ +// After changing this file, run pnpm prisma:migrate:dev to push the changes to the database + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["prismaSchemaFolder"] +} diff --git a/server/database/schema.prisma b/server/documents/schema.prisma similarity index 52% rename from server/database/schema.prisma rename to server/documents/schema.prisma index 3db87a263..783b43a08 100644 --- a/server/database/schema.prisma +++ b/server/documents/schema.prisma @@ -1,34 +1,3 @@ -// After changing this file, run pnpm prisma:migrate:dev to push the changes to the database - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -generator client { - provider = "prisma-client-js" -} - -model User { - id String @id @default(cuid()) - email String @unique - emailIsVerified Boolean @default(false) - name String? - createdAt DateTime @default(now()) - documents UserDocument[] - groups Group[] - key Key[] // TODO: Rename to keys -} - -model Key { - id String @id @unique - hashed_password String? // TODO: Rename to hashedPassword - user_id String // TODO: Rename to userId - user User @relation(references: [id], fields: [user_id], onDelete: Cascade) - - @@index([user_id]) -} - enum DocumentType { JOURNAL_ARTICLE PROCEEDINGS_ARTICLE @@ -103,54 +72,6 @@ model UserDocument { @@unique([lastModified(sort: Asc), id(sort: Asc)], name: "checkpoint") } -model JournalIssue { - id String @id @default(cuid()) - articles UserDocument[] - journal Journal? @relation(fields: [journalId], references: [id]) - journalId String? - title String? - subtitle String? - titleAddon String? - number String? - name String? - series String? - volume String? -} - -model Journal { - id String @id @default(cuid()) - isCustom Boolean - issues JournalIssue[] - name String - subtitle String? - titleAddon String? - issn String[] - scimagoId BigInt? @unique - country String? - publisher String? - areas String[] - categories String[] - citationInfo JournalCitationInfoYearly[] - hIndex Int? -} - -model JournalCitationInfoYearly { - journalId String - journal Journal @relation(fields: [journalId], references: [id]) - year Int - - docsThisYear Int - docsPrevious3Years Int - citableDocsPrevious3Years Int - citesOutgoing Int - citesOutgoingPerDoc Float - citesIncomingByRecentlyPublished Int - citesIncomingPerDocByRecentlyPublished Float - sjrIndex Float - - @@id([journalId, year]) -} - model UserDocumentOtherField { document UserDocument @relation(fields: [documentId], references: [id], onDelete: Cascade, onUpdate: Cascade) documentId String @@ -198,54 +119,3 @@ model DocumentContributor { @@id([documentId, entityId]) } - -enum GroupHierarchyType { - /// The group's content is independent of its hierarchical position. - INDEPENDENT - - /// The group's content is the intersection of its own content with its supergroups' content. - INTERSECTION - - /// The group's content is the union of its own content with its subgroups' content. - UNION -} - -enum GroupType { - AutomaticKeywordGroup - AutomaticPersonsGroup - ExplicitGroup - LastNameGroup - WordKeywordGroup - RegexKeywordGroup - SearchGroup - TexGroup -} - -model Group { - id String @id @default(cuid()) - users User[] - name String - displayName String - parentId String? - parent Group? @relation("GroupTree", fields: [parentId], references: [id], onDelete: Restrict, onUpdate: Cascade) - children Group[] @relation("GroupTree") - - hierarchyType GroupHierarchyType - color String? - description String? - icon String? - isExpanded Boolean - - // Prisma currently does not support union types / inheritance (https://github.com/prisma/prisma/issues/2505) - // Thus, we assemble all possible fields from all types of groups here - type GroupType - explicitDocuments UserDocument[] - field String? - keywordDelimiter String? - keywordHierarchicalDelimiter String? - authorLastName String? - searchExpression String? - caseSensitive Boolean? - onlySplitWordsAtDelimiter Boolean? - isRegEx Boolean? -} diff --git a/server/groups/schema.prisma b/server/groups/schema.prisma new file mode 100644 index 000000000..51b2c829b --- /dev/null +++ b/server/groups/schema.prisma @@ -0,0 +1,50 @@ +enum GroupHierarchyType { + /// The group's content is independent of its hierarchical position. + INDEPENDENT + + /// The group's content is the intersection of its own content with its supergroups' content. + INTERSECTION + + /// The group's content is the union of its own content with its subgroups' content. + UNION +} + +enum GroupType { + AutomaticKeywordGroup + AutomaticPersonsGroup + ExplicitGroup + LastNameGroup + WordKeywordGroup + RegexKeywordGroup + SearchGroup + TexGroup +} + +model Group { + id String @id @default(cuid()) + users User[] + name String + displayName String + parentId String? + parent Group? @relation("GroupTree", fields: [parentId], references: [id], onDelete: Restrict, onUpdate: Cascade) + children Group[] @relation("GroupTree") + + hierarchyType GroupHierarchyType + color String? + description String? + icon String? + isExpanded Boolean + + // Prisma currently does not support union types / inheritance (https://github.com/prisma/prisma/issues/2505) + // Thus, we assemble all possible fields from all types of groups here + type GroupType + explicitDocuments UserDocument[] + field String? + keywordDelimiter String? + keywordHierarchicalDelimiter String? + authorLastName String? + searchExpression String? + caseSensitive Boolean? + onlySplitWordsAtDelimiter Boolean? + isRegEx Boolean? +} diff --git a/server/journals/schema.prisma b/server/journals/schema.prisma new file mode 100644 index 000000000..3f79d7d7c --- /dev/null +++ b/server/journals/schema.prisma @@ -0,0 +1,47 @@ +model JournalIssue { + id String @id @default(cuid()) + articles UserDocument[] + journal Journal? @relation(fields: [journalId], references: [id]) + journalId String? + title String? + subtitle String? + titleAddon String? + number String? + name String? + series String? + volume String? +} + +model Journal { + id String @id @default(cuid()) + isCustom Boolean + issues JournalIssue[] + name String + subtitle String? + titleAddon String? + issn String[] + scimagoId BigInt? @unique + country String? + publisher String? + areas String[] + categories String[] + citationInfo JournalCitationInfoYearly[] + hIndex Int? +} + +model JournalCitationInfoYearly { + journalId String + journal Journal @relation(fields: [journalId], references: [id]) + year Int + + docsThisYear Int + docsPrevious3Years Int + citableDocsPrevious3Years Int + citesOutgoing Int + citesOutgoingPerDoc Float + citesIncomingByRecentlyPublished Int + citesIncomingPerDocByRecentlyPublished Float + sjrIndex Float + + @@id([journalId, year]) +} diff --git a/server/user/schema.prisma b/server/user/schema.prisma new file mode 100644 index 000000000..d4abe63b1 --- /dev/null +++ b/server/user/schema.prisma @@ -0,0 +1,19 @@ +model User { + id String @id @default(cuid()) + email String @unique + emailIsVerified Boolean @default(false) + name String? + createdAt DateTime @default(now()) + documents UserDocument[] + groups Group[] + key Key[] // TODO: Rename to keys +} + +model Key { + id String @id @unique + hashed_password String? // TODO: Rename to hashedPassword + user_id String // TODO: Rename to userId + user User @relation(references: [id], fields: [user_id], onDelete: Cascade) + + @@index([user_id]) +}