diff --git a/package.json b/package.json index 88b2ccec5..b6740f6c5 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", @@ -161,7 +161,7 @@ "vue-tsc": "2.0.24" }, "prisma": { - "schema": "server/database/schema.prisma", + "schema": "server", "seed": "node --experimental-specifier-resolution=node --loader ts-node/esm ./server/database/runSeed.ts" }, "packageManager": "pnpm@9.6.0", 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]) +}