jws-backend/prisma/schema.prisma
2024-06-26 11:22:48 +07:00

669 lines
15 KiB
Text

generator client {
provider = "prisma-client-js"
}
generator kysely {
provider = "prisma-kysely"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Menu {
id String @id @default(uuid())
caption String
captionEN String
menuType String
url String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
parent Menu? @relation(name: "MenuRelation", fields: [parentId], references: [id])
parentId String?
children Menu[] @relation(name: "MenuRelation")
roleMenuPermission RoleMenuPermission[]
userMenuPermission UserMenuPermission[]
userComponent MenuComponent[]
}
model RoleMenuPermission {
id String @id @default(uuid())
userRole String
permission String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model UserMenuPermission {
id String @id @default(uuid())
permission String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
user User @relation(fields: [userId], references: [id])
userId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model MenuComponent {
id String @id @default(uuid())
componentId String
componentTag String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
roleMenuComponentPermission RoleMenuComponentPermission[]
userMennuComponentPermission UserMenuComponentPermission[]
}
model RoleMenuComponentPermission {
id String @id @default(uuid())
userRole String
permission String
menuComponent MenuComponent @relation(fields: [menuComponentId], references: [id])
menuComponentId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model RunningNo {
key String @id @unique
value Int
}
model UserMenuComponentPermission {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id])
menuComponent MenuComponent @relation(fields: [menuComponentId], references: [id])
menuComponentId String
permission String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model Province {
id String @id @default(uuid())
name String
nameEN String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
district District[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
employeeCheckup EmployeeCheckup[]
}
model District {
id String @id @default(uuid())
name String
nameEN String
provinceId String
province Province @relation(fields: [provinceId], references: [id], onDelete: Cascade)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
subDistrict SubDistrict[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
}
model SubDistrict {
id String @id @default(uuid())
name String
nameEN String
zipCode String
district District @relation(fields: [districtId], references: [id], onDelete: Cascade)
districtId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
}
enum Status {
CREATED
ACTIVE
INACTIVE
}
model Branch {
id String @id @default(uuid())
code String
taxNo String
name String
nameEN String
address String
addressEN String
telephoneNo String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
zipCode String
email String
contactName String?
lineId String?
latitude String
longitude String
isHeadOffice Boolean @default(false)
headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id])
headOfficeId String?
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
branch Branch[] @relation(name: "HeadOfficeRelation")
contact BranchContact[]
user BranchUser[]
}
model BranchContact {
id String @id @default(uuid())
telephoneNo String
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model BranchUser {
id String @id @default(uuid())
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
enum UserType {
USER
MESSENGER
DELEGATE
AGENCY
}
model User {
id String @id @default(uuid())
code String?
firstName String
firstNameEN String
lastName String
lastNameEN String
username String
gender String
address String
addressEN String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
zipCode String
email String
telephoneNo String
registrationNo String?
startDate DateTime?
retireDate DateTime?
checkpoint String?
checkpointEN String?
userType UserType
userRole String
discountCondition String?
licenseNo String?
licenseIssueDate DateTime?
licenseExpireDate DateTime?
sourceNationality String?
importNationality String?
trainingPlace String?
responsibleArea String?
birthDate DateTime?
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
branch BranchUser[]
userMenuPermission UserMenuPermission[]
userMenuComponentPermission UserMenuComponentPermission[]
}
enum CustomerType {
CORP
PERS
}
model Customer {
id String @id @default(uuid())
code String
personName String
personNameEN String?
customerType CustomerType
customerName String
customerNameEN String
taxNo String?
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
branch CustomerBranch[]
}
model CustomerBranch {
id String @id @default(uuid())
branchNo Int
code String
legalPersonNo String
name String
nameEN String
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
customerId String
taxNo String?
registerName String
registerDate DateTime
authorizedCapital String
address String
addressEN String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
zipCode String
email String
telephoneNo String
employmentOffice String
bussinessType String
bussinessTypeEN String
jobPosition String
jobPositionEN String
jobDescription String
saleEmployee String
payDate DateTime
wageRate Int
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
employee Employee[]
}
model Employee {
id String @id @default(uuid())
code String
nrcNo String
firstName String
firstNameEN String
lastName String
lastNameEN String
dateOfBirth DateTime
gender String
nationality String
address String?
addressEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
zipCode String
passportType String
passportNumber String
passportIssueDate DateTime
passportExpiryDate DateTime
passportIssuingCountry String
passportIssuingPlace String
previousPassportReference String?
visaType String?
visaNumber String?
visaIssueDate DateTime?
visaExpiryDate DateTime?
visaIssuingPlace String?
visaStayUntilDate DateTime?
tm6Number String?
entryDate DateTime?
workerStatus String?
customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull)
customerBranchId String?
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
employeeCheckup EmployeeCheckup[]
employeeWork EmployeeWork[]
employeeOtherInfo EmployeeOtherInfo[]
}
model EmployeeCheckup {
id String @id @default(uuid())
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
checkupResult String?
checkupType String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
hospitalName String?
remark String?
medicalBenefitScheme String?
insuranceCompany String?
coverageStartDate DateTime?
coverageExpireDate DateTime?
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model EmployeeWork {
id String @id @default(uuid())
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
ownerName String?
positionName String?
jobType String?
workplace String?
workPermitNo String?
workPermitIssuDate DateTime?
workPermitExpireDate DateTime?
workEndDate DateTime?
remark String?
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model EmployeeOtherInfo {
id String @id @default(uuid())
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
citizenId String?
fatherBirthPlace String?
fatherFirstName String?
fatherLastName String?
motherBirthPlace String?
motherFirstName String?
motherLastName String?
fatherFirstNameEN String?
fatherLastNameEN String?
motherFirstNameEN String?
motherLastNameEN String?
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model Service {
id String @id @default(uuid())
code String
name String
detail String
attributes Json?
status Status @default(CREATED)
statusOrder Int @default(0)
work Work[]
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}
model Work {
id String @id @default(uuid())
order Int
name String
attributes Json?
status Status @default(CREATED)
statusOrder Int @default(0)
service Service? @relation(fields: [serviceId], references: [id], onDelete: Cascade)
serviceId String?
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
productOnWork WorkProduct[]
}
model WorkProduct {
order Int
work Work @relation(fields: [workId], references: [id], onDelete: Cascade)
workId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
@@id([workId, productId])
}
model ProductGroup {
id String @id @default(uuid())
code String
name String
detail String
remark String
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
type ProductType[]
}
model ProductType {
id String @id @default(uuid())
code String
name String
detail String
remark String
status Status @default(CREATED)
statusOrder Int @default(0)
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
productGroupId String
product Product[]
}
model Product {
id String @id @default(uuid())
code String
name String
detail String
process Int
price Float
agentPrice Float
serviceCharge Float
status Status @default(CREATED)
statusOrder Int @default(0)
remark String?
productType ProductType? @relation(fields: [productTypeId], references: [id], onDelete: SetNull)
productTypeId String?
workProduct WorkProduct[]
createdBy String?
createdAt DateTime @default(now())
updateBy String?
updatedAt DateTime @updatedAt
}