mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
234 lines
5.9 KiB
Plaintext
234 lines
5.9 KiB
Plaintext
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
|
|
// https://zenstack.dev/docs/guides/check-permission
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
binaryTargets = ["native", "linux-musl-openssl-3.0.x", "debian-openssl-3.0.x"]
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
plugin openapi {
|
|
provider = "@zenstackhq/openapi"
|
|
output = "./src/openapi.yaml"
|
|
}
|
|
|
|
plugin tanstack_query {
|
|
provider = "@zenstackhq/tanstack-query"
|
|
output = "./src/lib/hooks"
|
|
target = "react"
|
|
}
|
|
|
|
|
|
plugin enhancer {
|
|
provider = '@core/enhancer'
|
|
generatePermissionChecker = true
|
|
}
|
|
|
|
abstract model Base {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime? @updatedAt @map("updated_at")
|
|
}
|
|
|
|
model Account extends Base {
|
|
userId String @map("user_id")
|
|
type String
|
|
provider String
|
|
providerAccountId String @map("provider_account_id")
|
|
refresh_token String? @db.Text
|
|
access_token String? @db.Text
|
|
expires_at Int?
|
|
token_type String?
|
|
scope String?
|
|
id_token String? @db.Text
|
|
session_state String?
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([provider, providerAccountId])
|
|
@@map("accounts")
|
|
}
|
|
|
|
model Session extends Base {
|
|
sessionToken String @unique @map("session_token")
|
|
userId String @map("user_id")
|
|
expires DateTime
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@map("sessions")
|
|
}
|
|
|
|
model VerificationToken extends Base {
|
|
identifier String
|
|
token String
|
|
expires DateTime
|
|
|
|
@@unique([identifier, token])
|
|
@@map("verificationtokens")
|
|
}
|
|
|
|
model User extends Base {
|
|
name String?
|
|
email String? @unique @email
|
|
emailVerified DateTime? @map("email_verified")
|
|
image String?
|
|
role Role
|
|
password String? @omit @password
|
|
authMethod String? @map("auth_method")
|
|
deleted Boolean? @default(false)
|
|
accounts Account[]
|
|
sessions Session[]
|
|
organizations UserOrganization[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
enum Role {
|
|
pending
|
|
user
|
|
admin
|
|
}
|
|
|
|
model Organization extends Base {
|
|
slug String @unique
|
|
name String
|
|
|
|
projects Project[]
|
|
users UserOrganization[]
|
|
deleted Boolean? @default(false)
|
|
|
|
// Allow only users who are part of the organization
|
|
@@allow('all', users?[user == auth()])
|
|
|
|
@@map("organizations")
|
|
}
|
|
|
|
model UserOrganization extends Base {
|
|
userId String
|
|
organizationId String
|
|
user User @relation(fields: [userId], references: [id])
|
|
organization Organization @relation(fields: [organizationId], references: [id])
|
|
|
|
@@unique([userId, organizationId])
|
|
@@map("users_organisations")
|
|
}
|
|
|
|
model Project extends Base {
|
|
slug String @unique
|
|
name String
|
|
isArchived Boolean @map("is_archived") @default(false)
|
|
|
|
organizationId String @map("organization_id")
|
|
organization Organization @relation(fields: [organizationId], references: [id])
|
|
|
|
databases Database[]
|
|
|
|
@@map("projects")
|
|
}
|
|
|
|
model Agent extends Base {
|
|
slug String @unique
|
|
name String
|
|
description String?
|
|
lastContact DateTime? @map("last_contact")
|
|
|
|
databases Database[]
|
|
|
|
// Restrict access to users with role "admin"
|
|
@@allow('all', auth().role == "admin")
|
|
|
|
@@map("agents")
|
|
}
|
|
|
|
enum Dbms {
|
|
postgresql
|
|
mysql
|
|
mongodb
|
|
}
|
|
|
|
model Database extends Base {
|
|
name String
|
|
dbms Dbms
|
|
generatedId String @unique
|
|
description String?
|
|
backupPolicy String? @map("backup_policy")
|
|
isWaitingForBackup Boolean? @default(false)
|
|
backupToRestore String?
|
|
|
|
agentId String @map("agent_id")
|
|
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
|
lastContact DateTime? @map("last_contact")
|
|
|
|
backups Backup[]
|
|
restorations Restoration[]
|
|
|
|
projectId String? @map("project_id")
|
|
project Project? @relation(fields: [projectId], references: [id])
|
|
|
|
@@map("databases")
|
|
}
|
|
|
|
enum Status {
|
|
waiting
|
|
ongoing
|
|
failed
|
|
success
|
|
}
|
|
|
|
model Backup extends Base {
|
|
status Status @default(waiting)
|
|
file String?
|
|
|
|
databaseId String @map("database_id")
|
|
database Database @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
|
|
|
restorations Restoration[]
|
|
|
|
@@map("backups")
|
|
}
|
|
|
|
model Restoration extends Base {
|
|
status Status @default(waiting)
|
|
|
|
backupId String @map("backup_id")
|
|
backup Backup @relation(fields: [backupId], references: [id], onDelete: Cascade)
|
|
|
|
databaseId String? @map("database_id")
|
|
database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
|
|
|
@@map("restorations")
|
|
}
|
|
|
|
enum TypeStorage {
|
|
local
|
|
s3
|
|
}
|
|
|
|
model Settings extends Base {
|
|
storage TypeStorage @default(local)
|
|
name String @unique
|
|
s3EndPointUrl String?
|
|
s3AccessKeyId String?
|
|
s3SecretAccessKey String?
|
|
S3BucketName String?
|
|
smtpPassword String?
|
|
smtpFrom String?
|
|
smtpHost String?
|
|
smtpPort String?
|
|
smtpUser String?
|
|
|
|
// Restrict access to users with role "admin"
|
|
@@allow('all', auth().role == "admin")
|
|
|
|
@@map("settings")
|
|
}
|