Selegic CRM Docs
ServerDatabase

Schema Overview

Core and organization database schemas, models, and relationships.

Core Schema

The core schema (prisma/schema.prisma) contains global models shared across all organizations.

Authentication Models

model User {
  id            String    @id @default(cuid())
  email         String    @unique
  name          String?
  emailVerified DateTime?
  image         String?
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  
  sessions      Session[]
  accounts      AuthAccount[]
  members       Member[]
}

model Session {
  id                   String   @id @default(cuid())
  userId               String
  token                String   @unique
  expiresAt            DateTime
  ipAddress            String?
  userAgent            String?
  activeOrganizationId String?
  
  user                 User     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model AuthAccount {
  id           String  @id @default(cuid())
  userId       String
  accountId    String
  provider     String
  accessToken  String?
  refreshToken String?
  expiresAt    DateTime?
  
  user         User    @relation(fields: [userId], references: [id], onDelete: Cascade)
}

Organization Models

model Organization {
  id          String   @id @default(cuid())
  name        String
  slug        String   @unique
  logoUrl     String?
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  
  members     Member[]
  connections OrgConnection[]
}

model Member {
  id             String       @id @default(cuid())
  userId         String
  organizationId String
  role           MemberRole   @default(MEMBER)
  createdAt      DateTime     @default(now())
  
  user           User         @relation(fields: [userId], references: [id], onDelete: Cascade)
  organization   Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
}

Organization Schema

The org schema (prisma/org.prisma) contains tenant-specific data:

model Entity {
  id          String   @id @default(cuid())
  orgId       String
  name        String
  label       String
  description String?
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  
  fields      Field[]
}

model Field {
  id          String      @id @default(cuid())
  orgId       String
  entityId    String
  name        String
  label       String
  type        FieldType
  required    Boolean     @default(false)
  defaultValue String?
  
  entity      Entity      @relation(fields: [entityId], references: [id], onDelete: Cascade)
}

Relationships

User (no attributes) Session (no attributes) AuthAccount (no attributes) Member (no attributes) Organization (no attributes) Entity (no attributes) Field (no attributes) has has belongs_to has has owns

On this page