Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split prisma schema into multiple files #2452

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": "[email protected]",
Expand Down
11 changes: 11 additions & 0 deletions server/database/main.prisma
Original file line number Diff line number Diff line change
@@ -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"]
}
130 changes: 0 additions & 130 deletions server/database/schema.prisma → server/documents/schema.prisma
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
}
50 changes: 50 additions & 0 deletions server/groups/schema.prisma
Original file line number Diff line number Diff line change
@@ -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?
}
47 changes: 47 additions & 0 deletions server/journals/schema.prisma
Original file line number Diff line number Diff line change
@@ -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])
}
19 changes: 19 additions & 0 deletions server/user/schema.prisma
Original file line number Diff line number Diff line change
@@ -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])
}
Loading