assetflow/prisma/schema.prisma
2023-11-01 20:16:46 +01:00

129 lines
3.4 KiB
Plaintext

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
// https://github.com/pantharshit00/prisma-docs-generator
generator docs {
provider = "node node_modules/prisma-docs-generator"
output = "../docs"
}
// https://github.com/notiz-dev/prisma-dbml-generator
// Viewer: https://dbdiagram.io/d
generator dbml {
provider = "prisma-dbml-generator"
output = "../docs"
outputName = "schema.dbml"
projectName = "AssetFlow"
}
enum itemStatus {
normal
borrowed
stolen
lost
}
// comments and descriptions -> @db.VarChar(2048)
model Item {
id Int @id @unique @default(autoincrement())
SKU String? @unique
amount Int @default(1)
name String
comment String? @db.VarChar(2048)
status itemStatus @default(normal) /// TODO: Would it be better to create a separate model for this as well instead of providing several static statuses to choose from(enum)?
contactInfo contactInfo? @relation(fields: [contactInfoId], references: [id])
contactInfoId Int?
manufacturer String?
category itemCategory? @relation(fields: [categoryId], references: [id])
categoryId Int?
contents Item[] @relation("items") /// Item beinhaltet..
baseItem Item[] @relation("items") /// Item zugehörig zu
storageLocation StorageLocation? @relation(fields: [storageLocationId], references: [id])
storageLocationId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String?
}
model StorageLocation {
id Int @id @default(autoincrement())
name String @unique /// This is our LocationID for external use prefixed with: '%StorageUnit%_'
storageUnit StorageUnit? @relation(fields: [storageUnitId], references: [id])
storageUnitId Int?
Item Item[]
}
/// A StorageUnit is the base and can hold multiple StorageLocations.
model StorageUnit {
id Int @id @default(autoincrement())
name String @unique
contactInfo contactInfo @relation(fields: [contactInfoId], references: [id])
contactInfoId Int
StorageLocation StorageLocation[]
}
model itemCategory {
id Int @id @default(autoincrement())
name String @unique
description String? @db.VarChar(2048)
Item Item[]
}
model contactInfo {
id Int @id @default(autoincrement())
type contactType @default(person)
name String?
lastName String?
street String
houseNumber String
zipCode String
city String
country String
StorageUnit StorageUnit[]
Item Item[]
project project[]
projectAssignedUsers project[] @relation("projectAssignedUsers")
}
model project {
id Int @id @default(autoincrement())
name String @unique
description String? @db.VarChar(2048)
// People
manager contactInfo? @relation(fields: [contactInfoId], references: [id]) // Primary, manager of the project
assignedUsers contactInfo[] @relation("projectAssignedUsers") // Secondary, assigned users to the project, stagehands, etc.
contactInfoId Int?
// When does it start and end
startTime DateTime?
endTime DateTime?
}
/// TODO: Allow multiple types to be used?
enum contactType {
storageUnit
owner
person
customer
company
partner
enemy
}