Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

6.0 KB
Raw Blame
// DO NOT EDIT THIS FILE!
// This is a copy of your schema.prisma that corresponds to the state of the database
// when all migrations up until this one are applied.
// It's used to generate a Prisma Client for the migration.

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["views", "clientExtensions", "jsonProtocol"]
  // see commands.ts
  output = "client"
}

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

model Team {
  id    String @id @default(uuid())
  users User[]
}

enum UploadStatus {
  UPLOADING
  UPLOADED
}

model File {
  name              String       @id
  format            String
  size              Int
  description       String?
  createdAt         DateTime     @default(now())
  updatedAt         DateTime     @default(now()) @updatedAt
  meta              String       @default("{}")
  status            UploadStatus @default(UPLOADING)
  isDeleted         Boolean      @default(false)
  uploaderProject   Project?     @relation(fields: [uploaderProjectId], references: [id])
  uploaderProjectId String?
  assets            Asset[]
}

model Asset {
  id        String @default(uuid()) // not unique!
  projectId String
  file      File   @relation(fields: [name], references: [name])
  name      String

  @@id([id, projectId])
}

model User {
  id        String    @id @default(uuid())
  email     String?   @unique
  provider  String?
  image     String?
  username  String?
  createdAt DateTime  @default(now())
  team      Team?     @relation(fields: [teamId], references: [id])
  teamId    String?
  projects  Project[]
}

model Project {
  id            String                 @id @default(uuid())
  createdAt     DateTime               @default(now())
  title         String
  domain        String                 @unique
  user          User?                  @relation(fields: [userId], references: [id])
  userId        String?
  build         Build[]
  isDeleted     Boolean                @default(false)
  files         File[]
  projectDomain ProjectDomain[]
  latestBuild   LatestBuildPerProject?

  @@unique([id, isDeleted])
  @@unique([domain, isDeleted])
  @@unique([id, domain])
}

enum PublishStatus {
  PENDING
  PUBLISHED
  FAILED
}

model Build {
  id                String   @unique @default(uuid())
  version           Int      @default(0)
  lastTransactionId String?
  createdAt         DateTime @default(now())
  updatedAt         DateTime @default(now()) @updatedAt
  pages             String

  project   Project @relation(fields: [projectId], references: [id])
  projectId String

  breakpoints           String @default("[]")
  styles                String @default("[]")
  styleSources          String @default("[]")
  styleSourceSelections String @default("[]")
  props                 String @default("[]")
  dataSources           String @default("[]")
  instances             String @default("[]")

  deployment    String?
  publishStatus PublishStatus @default(PENDING)

  @@id([id, projectId])
}

enum AuthorizationRelation {
  viewers
  editors
  builders
  administrators
}

model AuthorizationToken {
  token     String                @default(uuid())
  // No relation to Project, as the Authorization system is not tied to a project
  projectId String
  name      String                @default("")
  relation  AuthorizationRelation @default(viewers)
  createdAt DateTime              @default(now())

  @@id([token, projectId])
}

enum DomainStatus {
  INITIALIZING
  ACTIVE
  ERROR
  PENDING
}

// Domains  + last known status and last known txtRecord
// In the future we can update this table using queue, n8n or temporal workflows.
// As of now updates are done during UI interactions
model Domain {
  id        String   @id @default(uuid())
  domain    String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @default(now()) @updatedAt

  ProjectDomain ProjectDomain[]
  // Last known txtRecord of the domain (to check domain ownership)
  txtRecord     String?
  // create, init, pending, active, error
  status        DomainStatus    @default(INITIALIZING)
  // In case of status="error", this will contain the error message
  error         String?

  projectWithDomain ProjectWithDomain[]
}

model ProjectDomain {
  projectId String
  project   Project  @relation(fields: [projectId], references: [id])
  domainId  String
  domain    Domain   @relation(fields: [domainId], references: [id])
  createdAt DateTime @default(now())
  // Generated txt record to check domain ownership
  txtRecord String   @unique @default(uuid())

  // CNAME record to point to the domain
  cname String

  @@id([projectId, domainId])
  @@index([domainId])
}

view ProjectWithDomain {
  projectId String

  domainId  String
  domain    Domain @relation(fields: [domainId], references: [id])
  txtRecord String

  createdAt DateTime

  // CNAME record to point to the domain
  cname String

  verified Boolean
  // To count statistics per user
  userId   String?

  // We can deploy on per domain basis, here for each project domain we have latest build
  latestBuid LatestBuildPerProjectDomain?

  @@id([projectId, domainId])
}

view LatestBuildPerProjectDomain {
  domainId          String
  buildId           String
  projectId         String
  projectWithDomain ProjectWithDomain @relation(fields: [projectId, domainId], references: [projectId, domainId])

  isLatestBuild Boolean
  publishStatus PublishStatus
  updatedAt     DateTime

  @@id([projectId, domainId])
}

view LatestBuildPerProject {
  buildId String

  projectId String
  domain    String
  project   Project @relation(fields: [projectId, domain], references: [id, domain])

  isLatestBuild Boolean
  publishStatus PublishStatus
  updatedAt     DateTime

  @@id([projectId, domain])
}

// Dashboard
view DashboardProject {
  id          String   @id @default(uuid())
  createdAt   DateTime @default(now())
  title       String
  domain      String
  userId      String?
  isDeleted   Boolean  @default(false)
  isPublished Boolean
}