Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

57.8 KB
Raw Blame
generator client {
  provider = "prisma-client-js"
  runtime  = "nodejs"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Organization {
  id                  String               @id @default(uuid())
  name                String
  description         String?
  apiKey              String?
  paymentId           String?
  streakSince         DateTime?
  createdAt           DateTime             @default(now())
  updatedAt           DateTime             @updatedAt
  deletedAt           DateTime?
  allowTrial          Boolean              @default(false)
  isTrailing          Boolean              @default(false)
  shortlink           ShortLinkPreference  @default(ASK)
  autoPost            AutoPost[]
  Comments            Comments[]
  credits             Credits[]
  clippings           Clipping[]
  customers           Customer[]
  errors              Errors[]
  github              GitHub[]
  Integration         Integration[]
  media               Media[]
  buyerOrganization   MessagesGroup[]
  notifications       Notifications[]
  plugs               Plugs[]
  post                Post[]               @relation("organization")
  submittedPost       Post[]               @relation("submittedForOrg")
  sets                Sets[]
  signatures          Signatures[]
  subscription        Subscription?
  tags                Tags[]
  thirdParty          ThirdParty[]
  usedCodes           UsedCodes[]
  users               UserOrganization[]
  webhooks            Webhooks[]
  oauthApp            OAuthApp[]
  oauthAuthorizations OAuthAuthorization[]

  @@index([apiKey])
  @@index([streakSince])
  @@index([paymentId])
  @@index([deletedAt])
}

model Tags {
  id           String       @id @default(uuid())
  name         String
  color        String
  orgId        String
  deletedAt    DateTime?
  createdAt    DateTime     @default(now())
  updatedAt    DateTime     @updatedAt
  organization Organization @relation(fields: [orgId], references: [id])
  posts        TagsPosts[]

  @@index([orgId])
  @@index([deletedAt])
}

model TagsPosts {
  postId    String
  tagId     String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  post      Post     @relation(fields: [postId], references: [id])
  tag       Tags     @relation(fields: [tagId], references: [id])

  @@id([postId, tagId])
  @@unique([postId, tagId])
}

model User {
  id                    String               @id @default(uuid())
  email                 String
  password              String?
  providerName          Provider
  name                  String?
  lastName              String?
  isSuperAdmin          Boolean              @default(false)
  bio                   String?
  audience              Int                  @default(0)
  pictureId             String?
  providerId            String?
  timezone              Int
  timezoneName          String?
  createdAt             DateTime             @default(now())
  updatedAt             DateTime             @updatedAt
  lastReadNotifications DateTime             @default(now())
  inviteId              String?
  activated             Boolean              @default(true)
  account               String?
  connectedAccount      Boolean              @default(false)
  lastOnline            DateTime             @default(now())
  ip                    String?
  agent                 String?
  deletedAt             DateTime?
  comments              Comments[]
  items                 ItemUser[]
  groupBuyer            MessagesGroup[]      @relation("groupBuyer")
  groupSeller           MessagesGroup[]      @relation("groupSeller")
  orderBuyer            Orders[]             @relation("orderBuyer")
  orderSeller           Orders[]             @relation("orderSeller")
  payoutProblems        PayoutProblems[]
  agencies              SocialMediaAgency?
  picture               Media?               @relation(fields: [pictureId], references: [id])
  organizations         UserOrganization[]
  sendSuccessEmails     Boolean              @default(true)
  sendFailureEmails     Boolean              @default(true)
  sendStreakEmails      Boolean              @default(true)
  oauthAuthorizations   OAuthAuthorization[]

  @@unique([email, providerName])
  @@index([lastReadNotifications])
  @@index([inviteId])
  @@index([account])
  @@index([lastOnline])
  @@index([pictureId])
  @@index([deletedAt])
}

model UsedCodes {
  id           String       @id @default(uuid())
  code         String
  orgId        String
  createdAt    DateTime     @default(now())
  updatedAt    DateTime     @updatedAt
  organization Organization @relation(fields: [orgId], references: [id])

  @@index([code])
}

model UserOrganization {
  id             String       @id @default(uuid())
  userId         String
  organizationId String
  disabled       Boolean      @default(false)
  role           Role         @default(USER)
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  organization   Organization @relation(fields: [organizationId], references: [id])
  user           User         @relation(fields: [userId], references: [id])

  @@unique([userId, organizationId])
  @@index([organizationId])
  @@index([disabled])
}

model GitHub {
  id             String       @id @default(uuid())
  login          String?
  name           String?
  token          String
  jobId          String?
  organizationId String
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@index([login])
  @@index([organizationId])
}

model Trending {
  id           String   @id @default(uuid())
  trendingList String
  language     String?  @unique
  hash         String
  date         DateTime
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt

  @@index([hash])
}

model TrendingLog {
  id       String   @id @default(uuid())
  language String?
  date     DateTime
}

model ItemUser {
  id     String @id @default(uuid())
  userId String
  key    String
  user   User   @relation(fields: [userId], references: [id])

  @@unique([userId, key])
  @@index([userId])
  @@index([key])
}

model Star {
  id         String   @id @default(uuid())
  stars      Int
  totalStars Int
  forks      Int
  totalForks Int
  login      String
  date       DateTime @default(now()) @db.Date
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  @@unique([login, date])
}

model Media {
  id                 String              @id @default(uuid())
  name               String
  originalName       String?
  path               String
  organizationId     String
  createdAt          DateTime            @default(now())
  updatedAt          DateTime            @updatedAt
  deletedAt          DateTime?
  fileSize           Int                 @default(0)
  type               String              @default("image")
  thumbnail          String?
  alt                String?
  thumbnailTimestamp Int?
  status             String              @default("ready")
  processingError    String?
  organization       Organization        @relation(fields: [organizationId], references: [id])
  agencies           SocialMediaAgency[]
  userPicture        User[]
  oauthApps          OAuthApp[]

  @@index([name])
  @@index([organizationId])
  @@index([type])
}

model SocialMediaAgency {
  id               String                   @id @default(uuid())
  userId           String                   @unique
  name             String
  logoId           String?
  website          String?
  slug             String?
  facebook         String?
  instagram        String?
  twitter          String?
  linkedIn         String?
  youtube          String?
  tiktok           String?
  otherSocialMedia String?
  shortDescription String
  description      String
  approved         Boolean                  @default(false)
  createdAt        DateTime                 @default(now())
  updatedAt        DateTime                 @updatedAt
  deletedAt        DateTime?
  logo             Media?                   @relation(fields: [logoId], references: [id])
  user             User                     @relation(fields: [userId], references: [id])
  niches           SocialMediaAgencyNiche[]

  @@index([userId])
  @@index([deletedAt])
  @@index([id])
}

model SocialMediaAgencyNiche {
  agencyId String
  niche    String
  agency   SocialMediaAgency @relation(fields: [agencyId], references: [id])

  @@id([agencyId, niche])
}

model Credits {
  id             String       @id @default(uuid())
  organizationId String
  credits        Int
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  type           String       @default("ai_images")
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@index([organizationId])
  @@index([createdAt])
}

model Clipping {
  id             String         @id @default(uuid())
  organizationId String
  url            String
  status         String         @default("analysing")
  error          String?
  title          String?
  thumbnail      String?
  duration       Int?
  maxClips       Int            @default(5)
  fit            String         @default("blur")
  integrations   String
  creditsId      String?
  deletedAt      DateTime?
  createdAt      DateTime       @default(now())
  updatedAt      DateTime       @updatedAt
  organization   Organization   @relation(fields: [organizationId], references: [id])
  clips          ClippingClip[]

  @@index([organizationId])
  @@index([deletedAt])
}

model ClippingClip {
  id         String    @id @default(uuid())
  clippingId String
  title      String
  content    String
  start      Float
  end        Float
  trimStart  Int?
  status     String    @default("pending")
  error      String?
  mediaId    String?
  path       String?
  thumbnail  String?
  draftedAt  DateTime?
  createdAt  DateTime  @default(now())
  updatedAt  DateTime  @updatedAt
  clipping   Clipping  @relation(fields: [clippingId], references: [id])

  @@index([clippingId])
}

model Subscription {
  id               String           @id @default(cuid())
  organizationId   String           @unique
  subscriptionTier SubscriptionTier
  provider         String           @default("stripe")
  identifier       String?
  cancelAt         DateTime?
  period           Period
  totalChannels    Int
  isLifetime       Boolean          @default(false)
  createdAt        DateTime         @default(now())
  updatedAt        DateTime         @updatedAt
  deletedAt        DateTime?
  organization     Organization     @relation(fields: [organizationId], references: [id])

  @@index([organizationId])
  @@index([deletedAt])
}

model Customer {
  id           String        @id @default(uuid())
  name         String
  orgId        String
  createdAt    DateTime      @default(now())
  updatedAt    DateTime      @updatedAt
  deletedAt    DateTime?
  organization Organization  @relation(fields: [orgId], references: [id])
  integrations Integration[]

  @@unique([orgId, name, deletedAt])
}

model Integration {
  id                    String                 @id @default(cuid())
  internalId            String
  organizationId        String
  name                  String
  customName            String?
  picture               String?
  providerIdentifier    String
  type                  String
  token                 String
  disabled              Boolean                @default(false)
  tokenExpiration       DateTime?
  refreshToken          String?
  profile               String?
  deletedAt             DateTime?
  createdAt             DateTime               @default(now())
  updatedAt             DateTime?              @updatedAt
  inBetweenSteps        Boolean                @default(false)
  refreshNeeded         Boolean                @default(false)
  postingTimes          String                 @default("[{\"time\":120}, {\"time\":400}, {\"time\":700}]")
  customInstanceDetails String?
  customerId            String?
  rootInternalId        String?
  additionalSettings    String?                @default("[]")
  exisingPlugData       ExisingPlugData[]
  customer              Customer?              @relation(fields: [customerId], references: [id])
  organization          Organization           @relation(fields: [organizationId], references: [id])
  webhooks              IntegrationsWebhooks[]
  orderItems            OrderItems[]
  plugs                 Plugs[]
  posts                 Post[]

  @@unique([organizationId, internalId])
  @@index([rootInternalId])
  @@index([organizationId])
  @@index([providerIdentifier])
  @@index([updatedAt])
  @@index([createdAt])
  @@index([deletedAt])
  @@index([customerId])
  @@index([inBetweenSteps])
  @@index([refreshNeeded])
  @@index([disabled])
}

model Signatures {
  id             String       @id @default(uuid())
  organizationId String
  content        String
  autoAdd        Boolean
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  deletedAt      DateTime?
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@index([createdAt])
  @@index([organizationId])
  @@index([deletedAt])
}

model Comments {
  id             String       @id @default(uuid())
  content        String
  organizationId String
  postId         String
  userId         String?
  displayName    String?
  parentId       String?
  anchorStart    Int?
  anchorEnd      Int?
  anchorQuote    String?
  resolvedAt     DateTime?
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  deletedAt      DateTime?
  organization   Organization @relation(fields: [organizationId], references: [id])
  post           Post         @relation(fields: [postId], references: [id])
  user           User?        @relation(fields: [userId], references: [id])
  parent         Comments?    @relation("CommentReplies", fields: [parentId], references: [id])
  replies        Comments[]   @relation("CommentReplies")

  @@index([createdAt])
  @@index([organizationId])
  @@index([userId])
  @@index([postId])
  @@index([parentId])
  @@index([resolvedAt])
  @@index([deletedAt])
}

model Post {
  id                         String                    @id @default(cuid())
  state                      State                     @default(QUEUE)
  publishDate                DateTime
  organizationId             String
  integrationId              String
  content                    String
  delay                      Int                       @default(0)
  group                      String
  batchId                    String?
  title                      String?
  description                String?
  parentPostId               String?
  releaseId                  String?
  releaseURL                 String?
  settings                   String?
  image                      String?
  submittedForOrderId        String?
  submittedForOrganizationId String?
  approvedSubmitForOrder     APPROVED_SUBMIT_FOR_ORDER @default(NO)
  creationMethod             CreationMethod            @default(UNKNOWN)
  lastMessageId              String?
  intervalInDays             Int?
  error                      String?
  createdAt                  DateTime                  @default(now())
  updatedAt                  DateTime                  @updatedAt
  deletedAt                  DateTime?
  comments                   Comments[]
  errors                     Errors[]
  payoutProblems             PayoutProblems[]
  integration                Integration               @relation(fields: [integrationId], references: [id])
  lastMessage                Messages?                 @relation(fields: [lastMessageId], references: [id])
  organization               Organization              @relation("organization", fields: [organizationId], references: [id])
  parentPost                 Post?                     @relation("parentPostId", fields: [parentPostId], references: [id])
  childrenPost               Post[]                    @relation("parentPostId")
  submittedForOrder          Orders?                   @relation(fields: [submittedForOrderId], references: [id])
  submittedForOrganization   Organization?             @relation("submittedForOrg", fields: [submittedForOrganizationId], references: [id])
  tags                       TagsPosts[]

  @@index([group])
  @@index([batchId])
  @@index([deletedAt])
  @@index([publishDate])
  @@index([state])
  @@index([organizationId])
  @@index([parentPostId])
  @@index([submittedForOrderId])
  @@index([intervalInDays])
  @@index([approvedSubmitForOrder])
  @@index([creationMethod])
  @@index([lastMessageId])
  @@index([createdAt])
  @@index([updatedAt])
  @@index([releaseURL])
  @@index([integrationId])
}

model Notifications {
  id             String       @id @default(uuid())
  organizationId String
  content        String
  link           String?
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  deletedAt      DateTime?
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@index([createdAt])
  @@index([organizationId])
  @@index([deletedAt])
}

model MessagesGroup {
  id                  String       @id @default(uuid())
  buyerOrganizationId String
  buyerId             String
  sellerId            String
  createdAt           DateTime     @default(now())
  updatedAt           DateTime     @updatedAt
  messages            Messages[]
  buyer               User         @relation("groupBuyer", fields: [buyerId], references: [id])
  buyerOrganization   Organization @relation(fields: [buyerOrganizationId], references: [id])
  seller              User         @relation("groupSeller", fields: [sellerId], references: [id])
  orders              Orders[]

  @@unique([buyerId, sellerId])
  @@index([createdAt])
  @@index([updatedAt])
  @@index([buyerOrganizationId])
}

model PayoutProblems {
  id        String   @id @default(uuid())
  status    String
  orderId   String
  userId    String
  postId    String?
  amount    Int
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  order     Orders   @relation(fields: [orderId], references: [id])
  post      Post?    @relation(fields: [postId], references: [id])
  user      User     @relation(fields: [userId], references: [id])
}

model Orders {
  id             String           @id @default(uuid())
  buyerId        String
  sellerId       String
  status         OrderStatus
  messageGroupId String
  captureId      String?
  createdAt      DateTime         @default(now())
  updatedAt      DateTime         @updatedAt
  ordersItems    OrderItems[]
  buyer          User             @relation("orderBuyer", fields: [buyerId], references: [id])
  messageGroup   MessagesGroup    @relation(fields: [messageGroupId], references: [id])
  seller         User             @relation("orderSeller", fields: [sellerId], references: [id])
  payoutProblems PayoutProblems[]
  posts          Post[]

  @@index([buyerId])
  @@index([sellerId])
  @@index([updatedAt])
  @@index([createdAt])
  @@index([messageGroupId])
}

model OrderItems {
  id            String      @id @default(uuid())
  orderId       String
  integrationId String
  quantity      Int
  price         Int
  integration   Integration @relation(fields: [integrationId], references: [id])
  order         Orders      @relation(fields: [orderId], references: [id])

  @@index([orderId])
  @@index([integrationId])
}

model Messages {
  id        String        @id @default(uuid())
  from      From
  content   String?
  groupId   String
  special   String?
  createdAt DateTime      @default(now())
  updatedAt DateTime      @updatedAt
  deletedAt DateTime?
  group     MessagesGroup @relation(fields: [groupId], references: [id])
  posts     Post[]

  @@index([groupId])
  @@index([createdAt])
  @@index([deletedAt])
}

model Plugs {
  id             String       @id @default(uuid())
  organizationId String
  plugFunction   String
  data           String
  integrationId  String
  activated      Boolean      @default(true)
  integration    Integration  @relation(fields: [integrationId], references: [id])
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@unique([plugFunction, integrationId])
  @@index([organizationId])
}

model ExisingPlugData {
  id            String      @id @default(uuid())
  integrationId String
  methodName    String
  value         String
  integration   Integration @relation(fields: [integrationId], references: [id])

  @@unique([integrationId, methodName, value])
}

model PopularPosts {
  id        String   @id @default(uuid())
  category  String
  topic     String
  content   String
  hook      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model IntegrationsWebhooks {
  integrationId String
  webhookId     String
  integration   Integration @relation(fields: [integrationId], references: [id])
  webhook       Webhooks    @relation(fields: [webhookId], references: [id])

  @@id([integrationId, webhookId])
  @@unique([integrationId, webhookId])
  @@index([integrationId])
  @@index([webhookId])
}

model Webhooks {
  id             String                 @id @default(uuid())
  name           String
  organizationId String
  url            String
  deletedAt      DateTime?
  createdAt      DateTime               @default(now())
  updatedAt      DateTime               @updatedAt
  integrations   IntegrationsWebhooks[]
  organization   Organization           @relation(fields: [organizationId], references: [id])

  @@index([organizationId])
  @@index([deletedAt])
}

model AutoPost {
  id              String       @id @default(uuid())
  organizationId  String
  title           String
  content         String?
  onSlot          Boolean
  syncLast        Boolean
  url             String
  lastUrl         String
  active          Boolean
  addPicture      Boolean
  generateContent Boolean
  integrations    String
  deletedAt       DateTime?
  createdAt       DateTime     @default(now())
  updatedAt       DateTime     @updatedAt
  organization    Organization @relation(fields: [organizationId], references: [id])

  @@index([deletedAt])
}

model Sets {
  id             String       @id @default(uuid())
  organizationId String
  name           String
  content        String
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@index([organizationId])
}

model ThirdParty {
  id             String       @id @default(uuid())
  organizationId String
  identifier     String
  name           String
  internalId     String
  apiKey         String
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  deletedAt      DateTime?
  organization   Organization @relation(fields: [organizationId], references: [id])

  @@unique([organizationId, internalId])
  @@index([organizationId])
  @@index([deletedAt])
}

model Errors {
  id             String       @id @default(uuid())
  message        String
  platform       String
  organizationId String
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  postId         String
  body           String       @default("{}")
  organization   Organization @relation(fields: [organizationId], references: [id])
  post           Post         @relation(fields: [postId], references: [id])

  @@index([organizationId])
  @@index([createdAt])
}

model Mentions {
  name      String
  username  String
  platform  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  image     String

  @@id([name, username, platform, image])
  @@index([createdAt])
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model mastra_ai_spans {
  traceId               String
  spanId                String
  parentSpanId          String?
  name                  String
  scope                 Json?
  spanType              String
  attributes            Json?
  metadata              Json?
  links                 Json?
  input                 Json?
  output                Json?
  error                 Json?
  startedAt             DateTime  @db.Timestamp(6)
  endedAt               DateTime? @db.Timestamp(6)
  createdAt             DateTime  @db.Timestamp(6)
  updatedAt             DateTime? @db.Timestamp(6)
  isEvent               Boolean
  startedAtZ            DateTime? @default(now()) @db.Timestamptz(6)
  endedAtZ              DateTime? @default(now()) @db.Timestamptz(6)
  createdAtZ            DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ            DateTime? @default(now()) @db.Timestamptz(6)
  entityType            String?
  entityId              String?
  entityName            String?
  parentEntityType      String?
  parentEntityId        String?
  parentEntityName      String?
  rootEntityType        String?
  rootEntityId          String?
  rootEntityName        String?
  userId                String?
  organizationId        String?
  resourceId            String?
  runId                 String?
  sessionId             String?
  threadId              String?
  requestId             String?
  environment           String?
  serviceName           String?
  experimentId          String?
  source                String?
  tags                  Json?
  requestContext        Json?
  entityVersionId       String?
  parentEntityVersionId String?
  rootEntityVersionId   String?

  @@id([traceId, spanId], map: "public_mastra_ai_spans_traceid_spanid_pk")
  @@index([name], map: "public_mastra_ai_spans_name_idx")
  @@index([parentSpanId, startedAt(sort: Desc)], map: "public_mastra_ai_spans_parentspanid_startedat_idx")
  @@index([spanType, startedAt(sort: Desc)], map: "public_mastra_ai_spans_spantype_startedat_idx")
  @@index([traceId, startedAt(sort: Desc)], map: "public_mastra_ai_spans_traceid_startedat_idx")
  @@index([entityType, entityId], map: "mastra_ai_spans_entitytype_entityid_idx")
  @@index([entityType, entityName], map: "mastra_ai_spans_entitytype_entityname_idx")
  @@index([metadata], map: "mastra_ai_spans_metadata_gin_idx", type: Gin)
  @@index([name])
  @@index([organizationId, userId], map: "mastra_ai_spans_orgid_userid_idx")
  @@index([parentSpanId, startedAt(sort: Desc)], map: "mastra_ai_spans_parentspanid_startedat_idx")
  @@index([spanType, startedAt(sort: Desc)], map: "mastra_ai_spans_spantype_startedat_idx")
  @@index([tags], map: "mastra_ai_spans_tags_gin_idx", type: Gin)
  @@index([traceId, startedAt(sort: Desc)], map: "mastra_ai_spans_traceid_startedat_idx")
  @@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model mastra_evals {
  input         String
  output        String
  result        Json
  agent_name    String
  metric_name   String
  instructions  String
  test_info     Json?
  global_run_id String
  run_id        String
  created_at    DateTime  @db.Timestamp(6)
  createdAt     DateTime? @db.Timestamp(6)
  created_atZ   DateTime? @default(now()) @db.Timestamptz(6)
  createdAtZ    DateTime? @default(now()) @db.Timestamptz(6)

  @@index([agent_name, created_at(sort: Desc)], map: "public_mastra_evals_agent_name_created_at_idx")
  @@ignore
}

model mastra_messages {
  id         String    @id
  thread_id  String
  content    String
  role       String
  type       String
  createdAt  DateTime  @db.Timestamp(6)
  resourceId String?
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@index([thread_id, createdAt(sort: Desc)], map: "public_mastra_messages_thread_id_createdat_idx")
  @@index([thread_id, createdAt(sort: Desc)], map: "mastra_messages_thread_id_createdat_idx")
}

model mastra_resources {
  id            String    @id
  workingMemory String?
  metadata      Json?
  createdAt     DateTime  @db.Timestamp(6)
  updatedAt     DateTime  @db.Timestamp(6)
  createdAtZ    DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ    DateTime? @default(now()) @db.Timestamptz(6)
}

model mastra_scorers {
  id                   String    @id
  scorerId             String
  traceId              String?
  runId                String
  scorer               Json
  preprocessStepResult Json?
  extractStepResult    Json?
  analyzeStepResult    Json?
  score                Float
  reason               String?
  metadata             Json?
  preprocessPrompt     String?
  extractPrompt        String?
  generateScorePrompt  String?
  generateReasonPrompt String?
  analyzePrompt        String?
  reasonPrompt         String?
  input                Json
  output               Json
  additionalContext    Json?
  runtimeContext       Json?
  entityType           String?
  entity               Json?
  entityId             String?
  source               String
  resourceId           String?
  threadId             String?
  createdAt            DateTime  @db.Timestamp(6)
  updatedAt            DateTime  @db.Timestamp(6)
  createdAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  spanId               String?
  requestContext       Json?
  organizationId       String?
  projectId            String?
  batchId              String?
  datasetId            String?
  datasetItemId        String?

  @@index([traceId, spanId, createdAt(sort: Desc)], map: "public_mastra_scores_trace_id_span_id_created_at_idx")
  @@index([traceId, spanId, createdAt(sort: Desc)], map: "mastra_scores_trace_id_span_id_created_at_idx")
}

model mastra_threads {
  id         String    @id
  resourceId String
  title      String
  metadata   String?
  createdAt  DateTime  @db.Timestamp(6)
  updatedAt  DateTime  @db.Timestamp(6)
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@index([resourceId, createdAt(sort: Desc)], map: "public_mastra_threads_resourceid_createdat_idx")
  @@index([resourceId, createdAt(sort: Desc)], map: "mastra_threads_resourceid_createdat_idx")
}

model mastra_traces {
  id           String    @id
  parentSpanId String?
  name         String
  traceId      String
  scope        String
  kind         Int
  attributes   Json?
  status       Json?
  events       Json?
  links        Json?
  other        String?
  startTime    BigInt
  endTime      BigInt
  createdAt    DateTime  @db.Timestamp(6)
  createdAtZ   DateTime? @default(now()) @db.Timestamptz(6)

  @@index([name, startTime(sort: Desc)], map: "public_mastra_traces_name_starttime_idx")
}

model mastra_workflow_snapshot {
  workflow_name String
  run_id        String
  resourceId    String?
  snapshot      String
  createdAt     DateTime  @db.Timestamp(6)
  updatedAt     DateTime  @db.Timestamp(6)
  createdAtZ    DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ    DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([workflow_name, run_id], map: "public_mastra_workflow_snapshot_workflow_name_run_id_key")
  @@index([workflow_name, createdAt(sort: Desc)], map: "mastra_workflow_snapshot_name_createdat_idx")
}

model mastra_agent_versions {
  id                   String    @id
  agentId              String
  versionNumber        Int
  name                 String
  description          String?
  instructions         String
  model                Json
  tools                Json?
  defaultOptions       Json?
  workflows            Json?
  agents               Json?
  integrationTools     Json?
  inputProcessors      Json?
  outputProcessors     Json?
  memory               Json?
  scorers              Json?
  mcpClients           Json?
  requestContextSchema Json?
  workspace            Json?
  skills               Json?
  skillsFormat         String?
  changedFields        Json?
  changeMessage        String?
  createdAt            DateTime  @db.Timestamp(6)
  createdAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  durable              Json?
  browser              Json?
  toolProviders        Json?
}

model mastra_agents {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  metadata        Json?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  visibility      String?
  favoriteCount   Int?
}

model mastra_background_tasks {
  id              String    @id
  tool_call_id    String
  tool_name       String
  agent_id        String
  run_id          String
  thread_id       String?
  resource_id     String?
  status          String
  args            Json
  result          Json?
  error           Json?
  suspend_payload Json?
  retry_count     Int
  max_retries     Int
  timeout_ms      Int
  createdAt       DateTime  @db.Timestamp(6)
  startedAt       DateTime? @db.Timestamp(6)
  suspendedAt     DateTime? @db.Timestamp(6)
  completedAt     DateTime? @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  startedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  suspendedAtZ    DateTime? @default(now()) @db.Timestamptz(6)
  completedAtZ    DateTime? @default(now()) @db.Timestamptz(6)

  @@index([agent_id, status], map: "mastra_bg_tasks_agent_status_idx")
  @@index([status, createdAt], map: "mastra_bg_tasks_status_created_at_idx")
  @@index([thread_id, createdAt], map: "mastra_bg_tasks_thread_idx")
  @@index([tool_call_id], map: "mastra_bg_tasks_tool_call_idx")
}

model mastra_channel_config {
  platform   String    @id
  data       Json
  updatedAt  DateTime  @db.Timestamp(6)
  updatedAtZ DateTime? @default(now()) @db.Timestamptz(6)
}

model mastra_channel_installations {
  id         String    @id
  platform   String
  agentId    String
  status     String
  webhookId  String?   @unique(map: "idx_channel_installations_webhook")
  data       Json
  configHash String?
  error      String?
  createdAt  DateTime  @db.Timestamp(6)
  updatedAt  DateTime  @db.Timestamp(6)
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@index([platform, agentId], map: "idx_channel_installations_platform_agent")
}

model mastra_dataset_items {
  id                 String
  datasetId          String
  datasetVersion     Int
  validTo            Int?
  isDeleted          Boolean
  input              Json
  groundTruth        Json?
  requestContext     Json?
  metadata           Json?
  source             Json?
  createdAt          DateTime  @db.Timestamp(6)
  updatedAt          DateTime  @db.Timestamp(6)
  createdAtZ         DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ         DateTime? @default(now()) @db.Timestamptz(6)
  expectedTrajectory Json?
  organizationId     String?
  projectId          String?
  toolMocks          Json?
  unmockedToolPolicy String?
  scorerIds          Json?
  externalId         String?

  @@id([id, datasetVersion])
  @@index([datasetId, validTo], map: "idx_dataset_items_dataset_validto")
  @@index([datasetId, validTo, isDeleted], map: "idx_dataset_items_dataset_validto_deleted")
  @@index([datasetId, datasetVersion], map: "idx_dataset_items_dataset_version")
  @@index([datasetId, externalId, datasetVersion], map: "idx_dataset_items_external_id_history")
  @@index([organizationId, projectId], map: "idx_dataset_items_org_project")
}

model mastra_dataset_versions {
  id         String    @id
  datasetId  String
  version    Int
  createdAt  DateTime  @db.Timestamp(6)
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([datasetId, version], map: "idx_dataset_versions_dataset_version_unique")
  @@index([datasetId, version], map: "idx_dataset_versions_dataset_version")
}

model mastra_datasets {
  id                   String    @id
  name                 String
  description          String?
  metadata             Json?
  inputSchema          Json?
  groundTruthSchema    Json?
  requestContextSchema Json?
  tags                 Json?
  targetType           String?
  targetIds            Json?
  scorerIds            Json?
  version              Int
  createdAt            DateTime  @db.Timestamp(6)
  updatedAt            DateTime  @db.Timestamp(6)
  createdAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  organizationId       String?
  projectId            String?
  candidateKey         String?
  candidateId          String?

  @@index([candidateKey, candidateId], map: "idx_datasets_candidate")
  @@index([organizationId, projectId], map: "idx_datasets_org_project")
}

model mastra_experiment_results {
  id                 String    @id
  experimentId       String
  itemId             String
  itemDatasetVersion Int?
  input              Json
  output             Json?
  groundTruth        Json?
  error              Json?
  startedAt          DateTime  @db.Timestamp(6)
  completedAt        DateTime  @db.Timestamp(6)
  retryCount         Int
  traceId            String?
  status             String?
  tags               Json?
  createdAt          DateTime  @db.Timestamp(6)
  startedAtZ         DateTime? @default(now()) @db.Timestamptz(6)
  completedAtZ       DateTime? @default(now()) @db.Timestamptz(6)
  createdAtZ         DateTime? @default(now()) @db.Timestamptz(6)
  comment            String?
  toolMockReport     Json?
  metadata           Json?
  organizationId     String?
  projectId          String?
  attempt            Int?

  @@unique([experimentId, itemId, attempt], map: "idx_experiment_results_exp_item_attempt")
  @@index([experimentId], map: "idx_experiment_results_experimentid")
  @@index([organizationId, projectId], map: "idx_experiment_results_org_project")
  @@index([tags], map: "idx_experiment_results_tags_gin", type: Gin)
}

model mastra_experiments {
  id                String    @id
  name              String?
  description       String?
  metadata          Json?
  datasetId         String?
  datasetVersion    Int?
  targetType        String
  targetId          String
  status            String
  totalItems        Int
  succeededCount    Int
  failedCount       Int
  skippedCount      Int
  startedAt         DateTime? @db.Timestamp(6)
  completedAt       DateTime? @db.Timestamp(6)
  agentVersion      String?
  createdAt         DateTime  @db.Timestamp(6)
  updatedAt         DateTime  @db.Timestamp(6)
  startedAtZ        DateTime? @default(now()) @db.Timestamptz(6)
  completedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  createdAtZ        DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ        DateTime? @default(now()) @db.Timestamptz(6)
  organizationId    String?
  projectId         String?
  provenance        Json?
  runnerAttestation Json?
  experimentSetId   String?
  comparisonId      String?
  variantId         String?
  trialIndex        Int?
  scorerIds         Json?

  @@index([datasetId], map: "idx_experiments_datasetid")
  @@index([experimentSetId, comparisonId, variantId, trialIndex], map: "idx_experiments_grouping")
  @@index([organizationId, projectId], map: "idx_experiments_org_project")
}

model mastra_favorites {
  userId     String
  entityType String
  entityId   String
  createdAt  DateTime  @db.Timestamp(6)
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@id([userId, entityType, entityId])
  @@index([entityType, entityId], map: "idx_favorites_entity")
}

model mastra_knowledge_activity {
  id             String    @id
  action         String
  recordType     String
  recordId       String
  scope          Json
  scopeKey       String
  sourceThreadId String?
  createdAt      DateTime  @db.Timestamp(6)
  createdAtZ     DateTime? @default(now()) @db.Timestamptz(6)

  @@index([id(sort: Desc)], map: "idx_knowledge_activity_latest")
}

model mastra_knowledge_cursors {
  sourceThreadId  String
  agent           String
  lastKnowledgeId String
  updatedAt       DateTime  @db.Timestamp(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)

  @@id([sourceThreadId, agent])
}

model mastra_knowledge_mentions {
  sourceType String
  sourceId   String
  recordId   String

  @@id([sourceType, sourceId, recordId])
  @@index([recordId, sourceType, sourceId], map: "idx_knowledge_mentions_record")
}

model mastra_knowledge_nodes {
  id            String    @id
  type          String
  name          String
  canonicalName String
  kind          String?
  content       String?
  description   String?
  scope         Json
  scopeKey      String
  version       Int
  mergedInto    String?
  createdAt     DateTime  @db.Timestamp(6)
  updatedAt     DateTime  @db.Timestamp(6)
  createdAtZ    DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ    DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([type, scopeKey, canonicalName], map: "idx_knowledge_nodes_identity")
  @@index([scopeKey, type], map: "idx_knowledge_nodes_scope")
}

model mastra_knowledge_records {
  id             String    @id
  node           String
  text           String
  scope          Json
  scopeKey       String
  sourceThreadId String
  capturedAt     DateTime  @db.Timestamp(6)
  when           DateTime? @db.Timestamp(6)
  maxScope       String?
  metadata       Json?
  deletedAt      DateTime? @db.Timestamp(6)
  deletedBy      String?
  capturedAtZ    DateTime? @default(now()) @db.Timestamptz(6)
  whenZ          DateTime? @default(now()) @db.Timestamptz(6)
  deletedAtZ     DateTime? @default(now()) @db.Timestamptz(6)

  @@index([node, id(sort: Desc)], map: "idx_knowledge_records_node_latest")
  @@index([sourceThreadId, id(sort: Desc)], map: "idx_knowledge_records_thread_latest")
}

model mastra_knowledge_semantic_outbox {
  id             String    @id
  idempotencyKey String    @unique(map: "idx_knowledge_outbox_idempotency")
  documentId     String
  documentType   String
  operation      String
  scope          Json
  scopeKey       String
  status         String
  attempts       Int
  availableAt    DateTime  @db.Timestamp(6)
  claimedAt      DateTime? @db.Timestamp(6)
  claimedBy      String?
  createdAt      DateTime  @db.Timestamp(6)
  completedAt    DateTime? @db.Timestamp(6)
  availableAtZ   DateTime? @default(now()) @db.Timestamptz(6)
  claimedAtZ     DateTime? @default(now()) @db.Timestamptz(6)
  createdAtZ     DateTime? @default(now()) @db.Timestamptz(6)
  completedAtZ   DateTime? @default(now()) @db.Timestamptz(6)

  @@index([status, availableAt, createdAt], map: "idx_knowledge_outbox_claim")
}

model mastra_mcp_client_versions {
  id            String    @id
  mcpClientId   String
  versionNumber Int
  name          String
  description   String?
  servers       Json
  changedFields Json?
  changeMessage String?
  createdAt     DateTime  @db.Timestamp(6)
  createdAtZ    DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([mcpClientId, versionNumber], map: "idx_mcp_client_versions_client_version")
}

model mastra_mcp_clients {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  metadata        Json?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
}

model mastra_mcp_server_versions {
  id               String    @id
  mcpServerId      String
  versionNumber    Int
  name             String
  version          String
  description      String?
  instructions     String?
  repository       Json?
  releaseDate      String?
  isLatest         Boolean?
  packageCanonical String?
  tools            Json?
  agents           Json?
  workflows        Json?
  changedFields    Json?
  changeMessage    String?
  createdAt        DateTime  @db.Timestamp(6)
  createdAtZ       DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([mcpServerId, versionNumber], map: "idx_mcp_server_versions_server_version")
}

model mastra_mcp_servers {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  metadata        Json?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model mastra_notifications {
  id                     String
  threadId               String
  source                 String
  kind                   String
  priority               String
  status                 String
  summary                String
  payload                Json?
  resourceId             String?
  agentId                String?
  sourceId               String?
  dedupeKey              String?
  coalesceKey            String?
  coalescedCount         Int
  attributes             Json?
  createdAt              DateTime  @db.Timestamp(6)
  updatedAt              DateTime  @db.Timestamp(6)
  deliveredAt            DateTime? @db.Timestamp(6)
  seenAt                 DateTime? @db.Timestamp(6)
  dismissedAt            DateTime? @db.Timestamp(6)
  archivedAt             DateTime? @db.Timestamp(6)
  discardedAt            DateTime? @db.Timestamp(6)
  deliverAt              DateTime? @db.Timestamp(6)
  summaryAt              DateTime? @db.Timestamp(6)
  deliveryReason         String?
  deliveryAttempts       Int
  lastDeliveryAttemptAt  DateTime? @db.Timestamp(6)
  lastDeliveryError      String?
  deliveredSignalId      String?
  summarySignalId        String?
  metadata               Json?
  createdAtZ             DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ             DateTime? @default(now()) @db.Timestamptz(6)
  deliveredAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  seenAtZ                DateTime? @default(now()) @db.Timestamptz(6)
  dismissedAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  archivedAtZ            DateTime? @default(now()) @db.Timestamptz(6)
  discardedAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  deliverAtZ             DateTime? @default(now()) @db.Timestamptz(6)
  summaryAtZ             DateTime? @default(now()) @db.Timestamptz(6)
  lastDeliveryAttemptAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@index([threadId, source, kind, status, agentId, resourceId, dedupeKey, coalesceKey], map: "idx_notifications_coalescing")
  @@index([status, deliverAt, summaryAt], map: "idx_notifications_due")
  @@index([threadId, status, updatedAt], map: "idx_notifications_thread_status_updated")
  @@ignore
}

model mastra_observational_memory {
  id                              String    @id
  lookupKey                       String
  scope                           String
  resourceId                      String?
  threadId                        String?
  activeObservations              String
  activeObservationsPendingUpdate String?
  originType                      String
  config                          String
  generationCount                 Int
  lastObservedAt                  DateTime? @db.Timestamp(6)
  lastReflectionAt                DateTime? @db.Timestamp(6)
  pendingMessageTokens            Int
  totalTokensObserved             Int
  observationTokenCount           Int
  isObserving                     Boolean
  isReflecting                    Boolean
  observedMessageIds              Json?
  observedTimezone                String?
  bufferedObservations            String?
  bufferedObservationTokens       Int?
  bufferedMessageIds              Json?
  bufferedReflection              String?
  bufferedReflectionTokens        Int?
  bufferedReflectionInputTokens   Int?
  reflectedObservationLineCount   Int?
  bufferedObservationChunks       Json?
  isBufferingObservation          Boolean
  isBufferingReflection           Boolean
  lastBufferedAtTokens            Int
  lastBufferedAtTime              DateTime? @db.Timestamp(6)
  metadata                        Json?
  createdAt                       DateTime  @db.Timestamp(6)
  updatedAt                       DateTime  @db.Timestamp(6)
  lastObservedAtZ                 DateTime? @default(now()) @db.Timestamptz(6)
  lastReflectionAtZ               DateTime? @default(now()) @db.Timestamptz(6)
  lastBufferedAtTimeZ             DateTime? @default(now()) @db.Timestamptz(6)
  createdAtZ                      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ                      DateTime? @default(now()) @db.Timestamptz(6)

  @@index([lookupKey], map: "idx_om_lookup_key")
}

model mastra_prompt_block_versions {
  id                   String    @id
  blockId              String
  versionNumber        Int
  name                 String
  description          String?
  content              String
  rules                Json?
  requestContextSchema Json?
  changedFields        Json?
  changeMessage        String?
  createdAt            DateTime  @db.Timestamp(6)
  createdAtZ           DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([blockId, versionNumber], map: "idx_prompt_block_versions_block_version")
}

model mastra_prompt_blocks {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  metadata        Json?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
}

model mastra_schedule_triggers {
  id                String  @id
  schedule_id       String
  run_id            String?
  scheduled_fire_at BigInt
  actual_fire_at    BigInt
  outcome           String
  error             String?
  trigger_kind      String
  parent_trigger_id String?
  metadata          Json?

  @@index([schedule_id, actual_fire_at(sort: Desc)], map: "idx_mastra_schedule_triggers_schedule_fire")
}

model mastra_schedules {
  id           String  @id
  target       Json
  cron         String
  timezone     String?
  status       String
  next_fire_at BigInt
  last_fire_at BigInt?
  last_run_id  String?
  created_at   BigInt
  updated_at   BigInt
  metadata     Json?
  owner_type   String?
  owner_id     String?

  @@index([status, next_fire_at], map: "idx_mastra_schedules_status_next_fire")
}

model mastra_scorer_definition_versions {
  id                 String    @id
  scorerDefinitionId String
  versionNumber      Int
  name               String
  description        String?
  type               String
  model              Json?
  instructions       String?
  scoreRange         Json?
  presetConfig       Json?
  defaultSampling    Json?
  changedFields      Json?
  changeMessage      String?
  createdAt          DateTime  @db.Timestamp(6)
  createdAtZ         DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([scorerDefinitionId, versionNumber], map: "idx_scorer_definition_versions_def_version")
}

model mastra_scorer_definitions {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  metadata        Json?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  organizationId  String?
  projectId       String?
}

model mastra_skill_blobs {
  hash       String    @id
  content    String
  size       Int
  mimeType   String?
  createdAt  DateTime  @db.Timestamp(6)
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)
}

model mastra_skill_versions {
  id            String    @id
  skillId       String
  versionNumber Int
  name          String
  description   String
  instructions  String
  license       String?
  compatibility Json?
  source        Json?
  references    Json?
  scripts       Json?
  assets        Json?
  metadata      Json?
  tree          Json?
  changedFields Json?
  changeMessage String?
  createdAt     DateTime  @db.Timestamp(6)
  createdAtZ    DateTime? @default(now()) @db.Timestamptz(6)
  files         Json?

  @@unique([skillId, versionNumber], map: "idx_skill_versions_skill_version")
}

model mastra_skills {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  visibility      String?
  favoriteCount   Int?
}

model mastra_thread_state {
  threadId   String
  type       String
  value      Json
  createdAt  DateTime  @db.Timestamp(6)
  updatedAt  DateTime  @db.Timestamp(6)
  createdAtZ DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ DateTime? @default(now()) @db.Timestamptz(6)

  @@id([threadId, type])
}

model mastra_tool_provider_connections {
  authorId     String
  providerId   String
  connectionId String
  toolkit      String
  label        String?
  scope        String
  createdAt    DateTime  @db.Timestamp(6)
  updatedAt    DateTime  @db.Timestamp(6)
  createdAtZ   DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ   DateTime? @default(now()) @db.Timestamptz(6)

  @@id([authorId, providerId, connectionId])
  @@index([authorId, providerId, toolkit], map: "idx_tool_provider_connections_author")
}

model mastra_workflow_definitions {
  id                   String    @id
  description          String?
  metadata             Json?
  inputSchema          Json
  outputSchema         Json
  stateSchema          Json?
  requestContextSchema Json?
  graph                Json
  schedule             Json?
  status               String
  source               String
  authorId             String?
  createdAt            DateTime  @db.Timestamp(6)
  updatedAt            DateTime  @db.Timestamp(6)
  createdAtZ           DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ           DateTime? @default(now()) @db.Timestamptz(6)

  @@index([status], map: "idx_workflow_definitions_status")
}

model mastra_workspace_versions {
  id               String    @id
  workspaceId      String
  versionNumber    Int
  name             String
  description      String?
  filesystem       Json?
  sandbox          Json?
  mounts           Json?
  search           Json?
  skills           Json?
  tools            Json?
  autoSync         Boolean?
  operationTimeout Int?
  changedFields    Json?
  changeMessage    String?
  createdAt        DateTime  @db.Timestamp(6)
  createdAtZ       DateTime? @default(now()) @db.Timestamptz(6)

  @@unique([workspaceId, versionNumber], map: "idx_workspace_versions_workspace_version")
}

model mastra_workspaces {
  id              String    @id
  status          String
  activeVersionId String?
  authorId        String?
  metadata        Json?
  createdAt       DateTime  @db.Timestamp(6)
  updatedAt       DateTime  @db.Timestamp(6)
  createdAtZ      DateTime? @default(now()) @db.Timestamptz(6)
  updatedAtZ      DateTime? @default(now()) @db.Timestamptz(6)
}

model OAuthApp {
  id                       String                         @id @default(uuid())
  organizationId           String?
  name                     String
  description              String?
  pictureId                String?
  redirectUrl              String
  redirectUris             String?
  clientId                 String                         @unique
  clientSecret             String?
  dynamic                  Boolean                        @default(false)
  tokenEndpointAuthMethod  String?
  createdAt                DateTime                       @default(now())
  updatedAt                DateTime                       @updatedAt
  deletedAt                DateTime?
  organization             Organization?                  @relation(fields: [organizationId], references: [id])
  picture                  Media?                         @relation(fields: [pictureId], references: [id])
  authorizations           OAuthAuthorization[]
  selfHostedAuthorizations OAuthSelfHostedAuthorization[]

  @@unique([organizationId, deletedAt])
  @@index([clientId])
  @@index([organizationId])
  @@index([deletedAt])
  @@index([dynamic])
}

model OAuthAuthorization {
  id                  String       @id @default(uuid())
  oauthAppId          String
  userId              String
  organizationId      String
  accessToken         String?
  authorizationCode   String?
  codeExpiresAt       DateTime?
  codeChallenge       String?
  codeChallengeMethod String?
  redirectUri         String?
  revokedAt           DateTime?
  createdAt           DateTime     @default(now())
  updatedAt           DateTime     @updatedAt
  oauthApp            OAuthApp     @relation(fields: [oauthAppId], references: [id])
  user                User         @relation(fields: [userId], references: [id])
  organization        Organization @relation(fields: [organizationId], references: [id])

  @@unique([oauthAppId, userId, organizationId])
  @@index([accessToken])
  @@index([authorizationCode])
  @@index([oauthAppId])
  @@index([userId])
  @@index([organizationId])
  @@index([revokedAt])
}

model OAuthSelfHostedAuthorization {
  id                  String    @id @default(uuid())
  oauthAppId          String
  mcpUrl              String
  apiKey              String
  email               String?
  accessToken         String?
  authorizationCode   String?
  codeExpiresAt       DateTime?
  codeChallenge       String?
  codeChallengeMethod String?
  redirectUri         String?
  revokedAt           DateTime?
  createdAt           DateTime  @default(now())
  updatedAt           DateTime  @updatedAt
  oauthApp            OAuthApp  @relation(fields: [oauthAppId], references: [id])

  @@index([accessToken])
  @@index([authorizationCode])
  @@index([oauthAppId])
}

enum OrderStatus {
  PENDING
  ACCEPTED
  CANCELED
  COMPLETED
}

enum From {
  BUYER
  SELLER
}

enum State {
  QUEUE
  PUBLISHED
  ERROR
  DRAFT
}

enum SubscriptionTier {
  STANDARD
  PRO
  TEAM
  ULTIMATE
}

enum Period {
  MONTHLY
  YEARLY
}

enum Provider {
  LOCAL
  GITHUB
  GOOGLE
  APPLE
  FARCASTER
  WALLET
  GENERIC
}

enum Role {
  SUPERADMIN
  ADMIN
  USER
}

enum APPROVED_SUBMIT_FOR_ORDER {
  NO
  WAITING_CONFIRMATION
  YES
}

enum CreationMethod {
  UNKNOWN
  WEB
  MCP
  API
  AUTOPOST
  CLI
}

enum ShortLinkPreference {
  ASK
  YES
  NO
}

enum AnnouncementColor {
  INFO
  WARNING
  ERROR
}

model Announcement {
  id          String            @id @default(uuid())
  title       String
  description String
  color       AnnouncementColor @default(INFO)
  createdAt   DateTime          @default(now())
}