Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
// --------------------------------------
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String?
email String @unique
hashedPassword String?
role Role @default(USER)
tokens Token[]
sessions Session[]
company Company? @relation(fields: [companyId], references: [id])
companyId Int?
}
enum Role {
USER
ADMIN
}
model Session {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
expiresAt DateTime?
handle String @unique
hashedSessionToken String?
antiCSRFToken String?
publicData String?
privateData String?
user User? @relation(fields: [userId], references: [id])
userId Int?
}
model Token {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
hashedToken String
type TokenType
expiresAt DateTime
sentTo String
user User @relation(fields: [userId], references: [id])
userId Int
@@unique([hashedToken, type])
}
enum TokenType {
RESET_PASSWORD
}
model Company {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique
users User[]
collections Collection[]
products Product[]
}
model Collection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
company Company @relation(fields: [companyId], references: [id])
companyId Int
products Product[]
image CollectionImage @relation(fields: [imageId], references: [id])
imageId Int
@@unique([name, companyId])
}
model CollectionImage {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
url String
collections Collection[]
}
model Product {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
company Company @relation(fields: [companyId], references: [id])
companyId Int
collections Collection[]
options Option[]
images ProductImage[]
@@unique([name, companyId])
}
model ProductImage {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
url String
// position Int
product Product @relation(fields: [productId], references: [id])
productId Int
}
model Option {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
// position Int
product Product @relation(fields: [productId], references: [id])
productId Int
values OptionValue[]
@@unique([name, productId])
}
model OptionValue {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
parent Option @relation(fields: [parentId], references: [id])
parentId Int
image OptionImage? @relation(fields: [imageId], references: [id])
imageId Int?
configurations Configuration[]
@@unique([name, parentId])
}
model OptionImage {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
url String
options OptionValue[]
}
model Configuration {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
options OptionValue[]
image ConfigurationImage? @relation(fields: [imageId], references: [id])
imageId Int?
}
model ConfigurationImage {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
url String
configurations Configuration[]
}
///
model Catalogue {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// companyId
collections CatalogueCollection[]
products CatalogueProduct[]
options CatalogueOption[]
configurations CatalogueConfiguration[]
}
model CatalogueCollection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
position Int
// collectionId
catalogue Catalogue @relation(fields: [catalogueId], references: [id])
catalogueId Int
}
model CatalogueProduct {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
position Int
price BigInt?
// productId
catalogue Catalogue @relation(fields: [catalogueId], references: [id])
catalogueId Int
}
model CatalogueOption {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
position Int
price BigInt?
// optionId OptionValue
catalogue Catalogue @relation(fields: [catalogueId], references: [id])
catalogueId Int
}
model CatalogueConfiguration {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
enabled Boolean @default(true)
price BigInt?
// configurationId Configuration
catalogue Catalogue @relation(fields: [catalogueId], references: [id])
catalogueId Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment