teableio/teable

View on GitHub
packages/db-main-prisma/prisma/template.prisma

Summary

Maintainability
Test Coverage
generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["native", "debian-openssl-1.1.x"]
  previewFeatures = ["tracing"]
}

datasource db {
  provider = "{{PRISMA_PROVIDER}}"
  url      = env("PRISMA_DATABASE_URL")
}

model Space {
  id               String    @id @default(cuid())
  name             String
  credit           Int?
  deletedTime      DateTime? @map("deleted_time")
  createdTime      DateTime  @default(now()) @map("created_time")
  createdBy        String    @map("created_by")
  lastModifiedBy   String?   @map("last_modified_by")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")

  baseGroup      Base[]

  @@map("space")
}

model PinResource {
  id               String    @id @default(cuid())
  type             String    @map("type")
  resourceId       String    @map("resource_id")
  createdTime      DateTime  @default(now()) @map("created_time")
  createdBy        String    @map("created_by")
  order            Float     @map("order")

  @@index([order])
  @@unique([createdBy, resourceId])
  @@map("pin_resource")
}

model Base {
  id                         String      @id @default(cuid())
  spaceId                    String      @map("space_id")
  name                       String
  order                      Float
  icon                       String?
  schemaPass                 String?     @map("schema_pass")
  deletedTime                DateTime?   @map("deleted_time")
  createdTime                DateTime    @default(now()) @map("created_time")
  createdBy                  String      @map("created_by")
  lastModifiedBy             String?     @map("last_modified_by")
  lastModifiedTime           DateTime?   @updatedAt @map("last_modified_time")
  space          Space                   @relation(fields: [spaceId], references: [id])
  tables         TableMeta[]

  @@index([order])
  @@map("base")
}

model TableMeta {
  id               String    @id
  baseId           String    @map("base_id")
  name             String
  description      String?
  icon             String?
  dbTableName      String    @map("db_table_name")
  version          Int
  order            Float
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  deletedTime      DateTime? @map("deleted_time")
  createdBy        String    @map("created_by")
  lastModifiedBy   String?   @map("last_modified_by")
  base             Base      @relation(fields: [baseId], references: [id])
  fields           Field[]
  views            View[]

  @@index([order])
  @@map("table_meta")
}

model Field {
  id                  String    @id
  name                String
  description         String?
  options             String?
  type                String
  cellValueType       String    @map("cell_value_type")
  isMultipleCellValue Boolean?  @map("is_multiple_cell_value")
  dbFieldType         String    @map("db_field_type")
  dbFieldName         String    @map("db_field_name")
  notNull             Boolean?  @map("not_null")
  unique              Boolean?
  isPrimary           Boolean?  @map("is_primary")
  isComputed          Boolean?  @map("is_computed")
  isLookup            Boolean?  @map("is_lookup")
  isPending           Boolean?  @map("is_pending")
  hasError            Boolean?  @map("has_error")
  // the link field id that a lookup field is linked to
  lookupLinkedFieldId String?   @map("lookup_linked_field_id")
  lookupOptions       String?   @map("lookup_options")
  tableId             String    @map("table_id")
  order               Float
  version             Int
  createdTime         DateTime  @default(now()) @map("created_time")
  lastModifiedTime    DateTime? @updatedAt @map("last_modified_time")
  deletedTime         DateTime? @map("deleted_time")
  createdBy           String    @map("created_by")
  lastModifiedBy      String?   @map("last_modified_by")
  table               TableMeta @relation(fields: [tableId], references: [id])

  @@index([lookupLinkedFieldId])
  @@map("field")
}

model View {
  id               String    @id
  name             String
  description      String?
  tableId          String    @map("table_id")
  type             String
  sort             String?
  filter           String?
  group            String?
  options          String?
  order            Float
  version          Int
  columnMeta       String    @map("column_meta")
  enableShare      Boolean?  @map("enable_share")
  shareId          String?   @map("share_id")
  shareMeta        String?   @map("share_meta")
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  deletedTime      DateTime? @map("deleted_time")
  createdBy        String    @map("created_by")
  lastModifiedBy   String?   @map("last_modified_by")
  table            TableMeta @relation(fields: [tableId], references: [id])

  @@index([order])
  @@map("view")
}

model Ops {
  collection  String
  docId       String   @map("doc_id")
  docType     String   @map("doc_type")
  version     Int
  operation   String
  createdTime DateTime @default(now()) @map("created_time")
  createdBy   String   @map("created_by")

  @@unique([collection, docId, version])
  @@index([collection, createdTime])
  @@map("ops")
}

model Snapshots {
  collection String
  docId      String @map("doc_id")
  docType    String @map("doc_type")
  version    Int
  data       String

  @@unique([collection, docId])
  @@map("snapshots")
}

model Reference {
  id          String @id @default(cuid())
  fromFieldId String @map("from_field_id")
  toFieldId   String @map("to_field_id")
  createdTime DateTime @default(now()) @map("created_time")

  @@unique([toFieldId, fromFieldId])
  @@index([fromFieldId])
  @@index([toFieldId])
  @@map("reference")
}

model User {
  id               String    @id @default(cuid())
  name             String
  password         String?
  salt             String?
  phone            String?   @unique
  email            String    @unique
  avatar           String?
  isSystem         Boolean?  @map("is_system")
  isAdmin          Boolean?  @map("is_admin")
  notifyMeta       String?   @map("notify_meta")
  lastSignTime     DateTime? @map("last_sign_time")
  deactivatedTime  DateTime? @map("deactivated_time")
  createdTime      DateTime  @default(now()) @map("created_time")
  deletedTime      DateTime? @map("deleted_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")

  accounts         Account[]
  collaborators    Collaborator[]
  @@map("users")
}

model Account {
  id               String    @id @default(cuid())
  userId           String    @map("user_id")
  type             String
  provider         String
  providerId       String    @map("provider_id")
  createdTime      DateTime  @default(now()) @map("created_time")

  user             User      @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerId])
  @@map("account")
}

model Attachments {
  id             String    @id @default(cuid())
  token          String    @unique
  hash           String
  size           Int
  mimetype       String
  path           String
  width          Int?
  height         Int?
  deletedTime    DateTime? @map("deleted_time")
  createdTime    DateTime  @default(now()) @map("created_time")
  createdBy      String    @map("created_by")
  lastModifiedBy String?   @map("last_modified_by")

  @@map("attachments")
}

model AttachmentsTable {
  id               String    @id @default(cuid())
  attachmentId     String    @map("attachment_id")
  name             String
  token            String
  tableId          String    @map("table_id")
  recordId         String    @map("record_id")
  fieldId          String    @map("field_id")
  createdTime      DateTime  @default(now()) @map("created_time")
  createdBy        String    @map("created_by")
  lastModifiedBy   String?   @map("last_modified_by")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")

  @@map("attachments_table")
}

model Collaborator {
  id               String    @id @default(cuid())
  roleName         String    @map("role_name")
  resourceType     String    @map("resource_type")
  resourceId       String    @map("resource_id")
  userId           String    @map("user_id")
  createdBy        String    @map("created_by")
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  lastModifiedBy   String?   @map("last_modified_by")

  user             User      @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([resourceType, resourceId, userId])
  @@map("collaborator")
}

model Invitation {
  id               String    @id @default(cuid())
  baseId           String?   @map("base_id")
  spaceId          String?   @map("space_id")
  type             String    @map("type")
  role             String
  invitationCode   String    @map("invitation_code")
  expiredTime      DateTime? @map("expired_time")
  createdBy        String    @map("create_by")
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  lastModifiedBy   String?   @map("last_modified_by")
  deletedTime      DateTime? @map("deleted_time")

  @@map("invitation")
}

model InvitationRecord {
  id           String   @id @default(cuid())
  invitationId String   @map("invitation_id")
  baseId       String?  @map("base_id")
  spaceId      String?  @map("space_id")
  type         String   @map("type")
  inviter      String   @map("inviter")
  accepter     String   @map("accepter")
  createdTime  DateTime @default(now()) @map("created_time")

  @@map("invitation_record")
}

model Notification {
  id          String   @id @default(cuid())
  fromUserId  String   @map("from_user_id")
  toUserId    String   @map("to_user_id")
  type        String   @map("type")
  message     String   @map("message")
  urlPath     String?  @map("url_path")
  isRead      Boolean  @default(false) @map("is_read")
  createdTime DateTime @default(now()) @map("created_time")
  createdBy   String   @map("created_by")

  @@index([toUserId, isRead, createdTime])
  @@map("notification")
}

model AccessToken {
  id               String    @id @default(cuid())
  name             String
  description      String?
  userId           String    @map("user_id")
  scopes           String
  spaceIds         String?   @map("space_ids")
  baseIds          String?   @map("base_ids")
  sign             String
  clientId         String?   @map("client_id")
  expiredTime      DateTime  @map("expired_time")
  lastUsedTime     DateTime? @map("last_used_time")
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")

  @@map("access_token")
}

model Setting {
  instanceId                String    @id @default(cuid()) @map("instance_id")
  disallowSignUp            Boolean?  @map("disallow_sign_up")
  disallowSpaceCreation     Boolean?  @map("disallow_space_creation")
  disallowSpaceInvitation   Boolean?  @map("disallow_space_invitation")

  @@map("setting")
}
model OAuthApp {
  id               String    @id @default(cuid())
  name             String
  logo             String?
  homepage         String
  description      String?
  clientId         String    @unique @map("client_id")
  redirectUris     String?   @map("redirect_uris")
  scopes           String?
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  createdBy        String     @map("created_by")

  @@map("oauth_app")
}

model OAuthAppAuthorized {
  id               String    @id @default(cuid())
  clientId         String    @map("client_id")
  userId           String    @map("user_id")
  authorizedTime   DateTime  @map("authorized_time")

  @@unique([clientId, userId])
  @@map("oauth_app_authorized")
}

model OAuthAppSecret {
  id              String    @id @default(cuid())
  clientId        String    @map("client_id")
  secret          String    @unique
  maskedSecret    String    @map("masked_secret")
  createdTime     DateTime  @default(now()) @map("created_time")
  createdBy       String    @map("created_by")
  lastUsedTime    DateTime? @map("last_used_time")

  @@map("oauth_app_secret")
}

model OAuthAppToken {
  id               String    @id @default(cuid())
  appSecretId      String    @map("app_secret_id")
  refreshTokenSign String    @map("refresh_token_sign")  @unique
  expiredTime      DateTime  @map("expired_time")
  createdTime      DateTime  @default(now()) @map("created_time")
  createdBy        String    @map("created_by")

  @@map("oauth_app_token")
}

model RecordHistory {
  id               String    @id @default(cuid())
  tableId          String    @map("table_id")
  recordId         String    @map("record_id")
  fieldId          String    @map("field_id")
  before           String    @map("before")
  after            String    @map("after")
  createdTime      DateTime  @default(now()) @map("created_time")
  createdBy        String    @map("created_by")

  @@index([tableId, recordId, createdTime])
  @@index([tableId, createdTime])
  @@map("record_history")
}

model Trash {
  id               String    @id @default(cuid())
  resourceType     String    @map("resource_type")
  resourceId       String    @map("resource_id")
  parentId         String?   @map("parent_id")
  deletedTime      DateTime  @default(now()) @map("deleted_time")
  deletedBy        String    @map("deleted_by")

  @@unique([resourceType, resourceId])
  @@map("trash")
}

model Plugin {
  id               String    @id @default(cuid())
  name             String
  description      String?
  detailDesc       String?   @map("detail_desc")
  logo             String
  helpUrl          String?   @map("help_url")
  status           String
  positions        String
  url              String?
  secret           String    @unique
  maskedSecret     String    @map("masked_secret")
  i18n             String?
  pluginUser       String?   @map("plugin_user")
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  createdBy        String    @map("created_by")
  lastModifiedBy   String?   @map("last_modified_by")

  pluginInstall    PluginInstall[]

  @@map("plugin")
}

model PluginInstall {
  id               String    @id @default(cuid())
  pluginId         String    @map("plugin_id")
  baseId           String    @map("base_id")
  name             String
  positionId       String    @map("position_id")
  position         String
  storage          String?
  createdTime      DateTime  @default(now()) @map("created_time")
  createdBy        String    @map("created_by")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  lastModifiedBy   String?   @map("last_modified_by")

  plugin           Plugin    @relation(fields: [pluginId], references: [id], onDelete: Cascade)

  @@map("plugin_install")
}

model Dashboard {
  id               String    @id @default(cuid())
  name             String
  baseId           String    @map("base_id")
  layout           String?
  createdBy        String    @map("created_by")
  createdTime      DateTime  @default(now()) @map("created_time")
  lastModifiedTime DateTime? @updatedAt @map("last_modified_time")
  lastModifiedBy   String?   @map("last_modified_by")

  @@map("dashboard")
}

model Comment {
  id               String     @id @default(cuid())
  tableId          String     @map("table_id")
  recordId         String     @map("record_id")
  quoteId          String?    @map("quote_Id")
  content          String?
  reaction         String?

  deletedTime      DateTime?  @map("deleted_time")
  createdTime      DateTime   @default(now()) @map("created_time")
  createdBy        String     @map("created_by")
  lastModifiedTime DateTime?  @updatedAt @map("last_modified_time")

  @@map("comment")
  @@index([tableId, recordId])
}

model CommentSubscription {
  tableId          String     @map("table_id")
  recordId         String     @map("record_id")
  createdBy        String     @map("created_by")
  createdTime      DateTime   @default(now()) @map("created_time")

  @@unique([tableId, recordId])
  @@index([tableId, recordId])
  @@map("comment_subscription")
}