create new mysql schema file

This commit is contained in:
Francis Cao 2023-01-05 11:13:49 -08:00
parent 5f159ed5ce
commit f10694d07e
2 changed files with 200 additions and 71 deletions

View File

@ -3,101 +3,114 @@ generator client {
}
datasource db {
provider = "mysql"
provider = "postgresql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model account {
id Int @id @default(autoincrement()) @map("user_id") @db.UnsignedInt
username String @unique() @db.VarChar(255)
password String @db.VarChar(60)
isAdmin Boolean @default(false) @map("is_admin")
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
updatedAt DateTime? @default(now()) @map("updated_at") @db.Timestamp(0)
accountUuid String @unique() @map("account_uuid") @db.VarChar(36)
website website[]
model User {
id String @id @unique @map("user_id") @db.Uuid
username String @unique @db.VarChar(255)
password String @db.VarChar(60)
role String @map("role") @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
@@index([accountUuid])
teamUser TeamUser[]
Website Website[]
@@map("user")
}
model event {
id Int @id @default(autoincrement()) @map("event_id") @db.UnsignedInt
websiteId Int @map("website_id") @db.UnsignedInt
sessionId Int @map("session_id") @db.UnsignedInt
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
url String @db.VarChar(500)
eventName String @map("event_name") @db.VarChar(50)
eventUuid String @unique() @map("event_uuid") @db.VarChar(36)
session session @relation(fields: [sessionId], references: [id])
website website @relation(fields: [websiteId], references: [id])
eventData eventData?
model Session {
id String @id @unique @map("session_id") @db.Uuid
websiteId String @map("website_id") @db.Uuid
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
@@index([createdAt])
@@index([sessionId])
@@index([websiteId])
@@index([eventUuid])
@@map("session")
}
model eventData {
id Int @id @default(autoincrement()) @map("event_data_id") @db.UnsignedInt
eventId Int @unique @map("event_id") @db.UnsignedInt
eventData Json @map("event_data")
event event @relation(fields: [eventId], references: [id])
model Website {
id String @id @unique @map("website_id") @db.Uuid
name String @db.VarChar(100)
domain String? @db.VarChar(500)
shareId String? @unique @map("share_id") @db.VarChar(50)
revId Int @default(0) @map("rev_id") @db.Integer
userId String? @map("user_id") @db.Uuid
teamId String? @map("team_id") @db.Uuid
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
@@map("event_data")
team Team? @relation(fields: [teamId], references: [id])
user User? @relation(fields: [userId], references: [id])
@@index([teamId])
@@index([userId])
@@index([createdAt])
@@index([shareId])
@@map("website")
}
model pageview {
id Int @id @default(autoincrement()) @map("view_id") @db.UnsignedInt
websiteId Int @map("website_id") @db.UnsignedInt
sessionId Int @map("session_id") @db.UnsignedInt
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
model WebsiteEvent {
id String @id() @map("event_id") @db.Uuid
websiteId String @map("website_id") @db.Uuid
sessionId String @map("session_id") @db.Uuid
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
url String @db.VarChar(500)
referrer String? @db.VarChar(500)
session session @relation(fields: [sessionId], references: [id])
website website @relation(fields: [websiteId], references: [id])
eventType Int @default(1) @map("event_type") @db.Integer
eventName String? @map("event_name") @db.VarChar(50)
eventData Json? @map("event_data")
@@index([createdAt])
@@index([sessionId])
@@index([websiteId])
@@index([websiteId, createdAt])
@@index([websiteId])
@@index([websiteId, sessionId, createdAt])
@@map("website_event")
}
model session {
id Int @id @default(autoincrement()) @map("session_id") @db.UnsignedInt
sessionUuid String @unique() @map("session_uuid") @db.VarChar(36)
websiteId Int @map("website_id") @db.UnsignedInt
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
website website @relation(fields: [websiteId], references: [id])
event event[]
pageview pageview[]
model Team {
id String @id() @unique() @map("team_id") @db.Uuid
name String @db.VarChar(50)
userId String @map("user_id") @db.Uuid
accessCode String? @unique @map("access_code") @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
@@index([createdAt])
@@index([websiteId])
@@index([sessionUuid])
}
model website {
id Int @id @default(autoincrement()) @map("website_id") @db.UnsignedInt
websiteUuid String @unique() @map("website_uuid") @db.VarChar(36)
userId Int @map("user_id") @db.UnsignedInt
name String @db.VarChar(100)
domain String? @db.VarChar(500)
shareId String? @unique() @map("share_id") @db.VarChar(64)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
account account @relation(fields: [userId], references: [id])
event event[]
pageview pageview[]
session session[]
teamUsers TeamUser[]
Website Website[]
@@index([userId])
@@index([websiteUuid])
@@index([accessCode])
@@map("team")
}
model TeamUser {
id String @id() @unique() @map("team_user_id") @db.Uuid
teamId String @map("team_id") @db.Uuid
userId String @map("user_id") @db.Uuid
role String @map("role") @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
team Team @relation(fields: [teamId], references: [id])
user User @relation(fields: [userId], references: [id])
@@index([teamId])
@@index([userId])
@@map("team_user")
}

116
db/mysql/schema_old.prisma Normal file
View File

@ -0,0 +1,116 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model User {
id String @id @unique @map("user_id") @db.VarChar(36)
username String @unique @db.VarChar(255)
password String @db.VarChar(60)
role String @map("role") @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(0)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(0)
teamUser TeamUser[]
Website Website[]
@@map("user")
}
model Session {
id String @id @unique @map("session_id") @db.VarChar(36)
websiteId String @map("website_id") @db.VarChar(36)
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(0)
@@index([createdAt])
@@index([websiteId])
@@map("session")
}
model Website {
id String @id @unique @map("website_id") @db.VarChar(36)
name String @db.VarChar(100)
domain String? @db.VarChar(500)
shareId String? @unique @map("share_id") @db.VarChar(50)
revId Int @default(0) @map("rev_id") @db.UnsignedInt
userId String? @map("user_id") @db.VarChar(36)
teamId String? @map("team_id") @db.VarChar(36)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(0)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(0)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(0)
team Team? @relation(fields: [teamId], references: [id])
user User? @relation(fields: [userId], references: [id])
@@index([teamId])
@@index([userId])
@@index([createdAt])
@@index([shareId])
@@map("website")
}
model WebsiteEvent {
id String @id() @map("event_id") @db.VarChar(36)
websiteId String @map("website_id") @db.VarChar(36)
sessionId String @map("session_id") @db.VarChar(36)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(0)
url String @db.VarChar(500)
referrer String? @db.VarChar(500)
eventType Int @default(1) @map("event_type") @db.UnsignedInt
eventName String? @map("event_name") @db.VarChar(50)
eventData Json? @map("event_data")
@@index([createdAt])
@@index([sessionId])
@@index([websiteId])
@@index([websiteId, createdAt])
@@index([websiteId, sessionId, createdAt])
@@map("website_event")
}
model Team {
id String @id() @unique() @map("team_id") @db.VarChar(36)
name String @db.VarChar(50)
userId String @map("user_id") @db.VarChar(36)
accessCode String? @unique @map("access_code") @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(0)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(0)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(0)
teamUsers TeamUser[]
Website Website[]
@@index([userId])
@@index([accessCode])
@@map("team")
}
model TeamUser {
id String @id() @unique() @map("team_user_id") @db.VarChar(36)
teamId String @map("team_id") @db.VarChar(36)
userId String @map("user_id") @db.VarChar(36)
role String @map("role") @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(0)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(0)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(0)
team Team @relation(fields: [teamId], references: [id])
user User @relation(fields: [userId], references: [id])
@@index([teamId])
@@index([userId])
@@map("team_user")
}