generator client { provider = "prisma-client" output = "../src/generated/prisma" moduleFormat = "cjs" importFileExtension = "" } datasource db { provider = "mysql" } enum UserStatus { ACTIVE SUSPENDED DISABLED } enum UserType { PUBLIC STAFF } enum StaffStatus { ACTIVE INACTIVE } enum SessionChannel { WECHAT ADMIN } enum AuditResult { SUCCESS FAILURE } enum ServiceCategory { OLD_AGE WOMEN CHILD DISABILITY LIFE_DIFFICULTY OTHER } enum ApplicationApplyMode { SELF FAMILY COMMUNITY VOLUNTEER OTHER } enum ServiceApplicationStatus { SUBMITTED PENDING_CONTACT ASSESSING REJECTED OUT_OF_SCOPE REFERRED ACCEPTED SERVICE_PLANNED IN_SERVICE SERVICE_COMPLETED FOLLOW_UP_PENDING CLOSED CANCELLED SUSPENDED } enum ApplicationSource { WECHAT_MINIPROGRAM ADMIN FOLLOW_UP } enum ConsentType { SERVICE_APPLICATION BENEFICIARY_GUARDIAN VOLUNTEER_APPLICATION } enum ConsentGrantedBy { SELF APPLICANT GUARDIAN } enum BeneficiaryGender { FEMALE MALE OTHER UNDISCLOSED } enum BeneficiaryStatus { ACTIVE INACTIVE ARCHIVED } enum ServiceCasePriority { LOW NORMAL HIGH URGENT } enum ServiceCaseStatus { ASSIGNED IN_SERVICE SERVICE_COMPLETED SUSPENDED CANCELLED } enum CaseAssigneeType { STAFF VOLUNTEER } enum CaseAssigneeRole { OWNER COLLABORATOR } enum ServiceRecordType { HOME_VISIT PHONE_CONTACT ESCORT MATERIAL_SUPPORT ACTIVITY OTHER } enum BeneficiaryConfirmStatus { NOT_REQUESTED CONFIRMED PARTIALLY_CONFIRMED DISPUTED } enum FileStatus { UPLOAD_PENDING AVAILABLE QUARANTINED DELETED } enum FileBusinessType { SERVICE_RECORD PROJECT_COVER ACTIVITY_COVER CONTENT_COVER } enum ContentPostType { ORGANIZATION_INTRO PUBLIC_WELFARE_NEWS SERVICE_STORY NOTICE FAQ } enum ContentPostStatus { DRAFT PENDING_REVIEW PUBLISHED ARCHIVED } enum FinancialDisclosureStatus { DRAFT PUBLISHED ARCHIVED } enum NotificationType { APPLICATION_SUBMITTED APPLICATION_ACCEPTED SERVICE_ARRANGED SERVICE_COMPLETED FOLLOW_UP_PENDING ACTIVITY_REGISTRATION_RESULT } enum NotificationChannel { WECHAT_SUBSCRIPTION } enum NotificationDeliveryStatus { PENDING PROCESSING SENT FAILED DEAD } enum VolunteerStatus { APPLIED APPROVED REJECTED SUSPENDED INACTIVE } enum ProjectStatus { DRAFT PUBLISHED COMPLETED } enum ActivityStatus { DRAFT PUBLISHED REGISTRATION_CLOSED IN_PROGRESS COMPLETED CANCELLED } enum ActivityRegistrationStatus { PENDING APPROVED REJECTED CANCELLED } enum ActivityCheckInStatus { NOT_CHECKED_IN CHECKED_IN ABSENT } enum FollowUpType { SERVICE_COMPLETION KEY_CARE MANUAL } enum FollowUpStatus { PENDING COMPLETED CANCELLED } enum FollowUpResultCode { SATISFIED GENERALLY_SATISFIED UNSATISFIED NEED_MORE_HELP UNREACHABLE OTHER } enum FollowUpSource { AUTO_SERVICE_COMPLETION STAFF_MANUAL KEY_CARE_PLAN } model User { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) status UserStatus @default(ACTIVE) userType UserType @map("user_type") mobileEncrypted String? @map("mobile_encrypted") @db.VarChar(512) mobileHash String? @unique @map("mobile_hash") @db.Char(64) nickname String? @db.VarChar(100) avatarUrl String? @map("avatar_url") @db.VarChar(512) lastLoginAt DateTime? @map("last_login_at") @db.DateTime(3) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) wechatIdentities WechatIdentity[] staffProfile StaffProfile? adminCredential AdminCredential? sessions AuthSession[] userRoles UserRole[] auditLogs AuditLog[] @relation("AuditActor") assignedRoles UserRole[] @relation("UserRoleAssigner") serviceApplications ServiceApplication[] @relation("ApplicationApplicant") applicationStatusChanges ServiceApplicationStatusHistory[] @relation("ApplicationStatusOperator") consents Consent[] createdBeneficiaries BeneficiaryProfile[] @relation("BeneficiaryCreator") updatedBeneficiaries BeneficiaryProfile[] @relation("BeneficiaryUpdater") ownedServiceCases ServiceCase[] @relation("CaseOwner") createdServiceCases ServiceCase[] @relation("CaseCreator") updatedServiceCases ServiceCase[] @relation("CaseUpdater") caseAssignments CaseAssignee[] caseStatusChanges ServiceCaseStatusHistory[] @relation("CaseStatusOperator") createdServiceRecords ServiceRecord[] @relation("ServiceRecordCreator") updatedServiceRecords ServiceRecord[] @relation("ServiceRecordUpdater") uploadedFiles File[] @relation("FileUploader") assignedBeneficiaryTags BeneficiaryTag[] @relation("BeneficiaryTagAssigner") assignedCaseMembers CaseAssignee[] @relation("CaseAssigneeAssigner") revisedServiceRecords ServiceRecordRevision[] @relation("ServiceRecordReviser") ownedFollowUpTasks FollowUpTask[] @relation("FollowUpOwner") createdFollowUpTasks FollowUpTask[] @relation("FollowUpCreator") updatedFollowUpTasks FollowUpTask[] @relation("FollowUpUpdater") followUpStatusChanges FollowUpStatusHistory[] @relation("FollowUpStatusOperator") volunteerProfile Volunteer? reviewedVolunteers Volunteer[] @relation("VolunteerReviewer") createdVolunteers Volunteer[] @relation("VolunteerCreator") updatedVolunteers Volunteer[] @relation("VolunteerUpdater") volunteerStatusChanges VolunteerStatusHistory[] @relation("VolunteerStatusOperator") managedProjects Project[] @relation("ProjectManager") createdProjects Project[] @relation("ProjectCreator") updatedProjects Project[] @relation("ProjectUpdater") projectStatusChanges ProjectStatusHistory[] @relation("ProjectStatusOperator") createdActivities Activity[] @relation("ActivityCreator") updatedActivities Activity[] @relation("ActivityUpdater") activityStatusChanges ActivityStatusHistory[] @relation("ActivityStatusOperator") activityRegistrations ActivityRegistration[] @relation("ActivityRegistrationUser") reviewedRegistrations ActivityRegistration[] @relation("RegistrationReviewer") checkedInRegistrations ActivityRegistration[] @relation("RegistrationCheckInOperator") recordedServiceMinutes ActivityRegistration[] @relation("RegistrationMinutesOperator") registrationChanges ActivityRegistrationHistory[] @relation("RegistrationHistoryOperator") createdContentPosts ContentPost[] @relation("ContentCreator") updatedContentPosts ContentPost[] @relation("ContentUpdater") reviewedContentPosts ContentPost[] @relation("ContentReviewer") contentStatusChanges ContentPostStatusHistory[] @relation("ContentStatusOperator") notifications Notification[] notificationPreferences NotificationPreference[] createdFinancialDisclosures FinancialDisclosure[] @relation("FinancialDisclosureCreator") updatedFinancialDisclosures FinancialDisclosure[] @relation("FinancialDisclosureUpdater") financialDisclosureStatusChanges FinancialDisclosureStatusHistory[] @relation("FinancialDisclosureStatusOperator") @@map("users") } model WechatIdentity { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt userId BigInt @map("user_id") @db.UnsignedBigInt appid String @db.VarChar(64) openidCiphertext String @map("openid_ciphertext") @db.VarChar(512) openidHash String @map("openid_hash") @db.Char(64) unionidCiphertext String? @map("unionid_ciphertext") @db.VarChar(512) unionidHash String? @map("unionid_hash") @db.Char(64) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) @@unique([appid, openidHash], map: "wechat_identities_appid_openid_hash_key") @@index([userId], map: "wechat_identities_user_id_idx") @@map("wechat_identities") } model StaffProfile { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt userId BigInt @unique @map("user_id") @db.UnsignedBigInt employeeNo String? @unique @map("employee_no") @db.VarChar(50) displayName String @map("display_name") @db.VarChar(100) department String? @db.VarChar(100) status StaffStatus @default(ACTIVE) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) @@map("staff_profiles") } model AdminCredential { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt userId BigInt @unique @map("user_id") @db.UnsignedBigInt username String @unique @db.VarChar(64) passwordHash String @map("password_hash") @db.VarChar(255) failedLoginCount Int @default(0) @map("failed_login_count") @db.UnsignedInt lockedUntil DateTime? @map("locked_until") @db.DateTime(3) passwordChangedAt DateTime @default(now()) @map("password_changed_at") @db.DateTime(3) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) @@map("admin_credentials") } model AuthSession { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) userId BigInt @map("user_id") @db.UnsignedBigInt channel SessionChannel tokenHash String @unique @map("token_hash") @db.Char(64) expiresAt DateTime @map("expires_at") @db.DateTime(3) lastUsedAt DateTime? @map("last_used_at") @db.DateTime(3) revokedAt DateTime? @map("revoked_at") @db.DateTime(3) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) @@index([userId, channel, revokedAt, expiresAt], map: "auth_sessions_user_channel_status_idx") @@index([expiresAt], map: "auth_sessions_expires_at_idx") @@map("auth_sessions") } model Role { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) code String @unique @db.VarChar(64) name String @db.VarChar(100) description String? @db.VarChar(255) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) userRoles UserRole[] rolePermissions RolePermission[] @@map("roles") } model Permission { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt code String @unique @db.VarChar(100) name String @db.VarChar(100) description String? @db.VarChar(255) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) rolePermissions RolePermission[] @@map("permissions") } model UserRole { userId BigInt @map("user_id") @db.UnsignedBigInt roleId BigInt @map("role_id") @db.UnsignedBigInt assignedBy BigInt? @map("assigned_by") @db.UnsignedBigInt assignedAt DateTime @default(now()) @map("assigned_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) role Role @relation(fields: [roleId], references: [id], onDelete: Restrict) assigner User? @relation("UserRoleAssigner", fields: [assignedBy], references: [id], onDelete: Restrict) @@id([userId, roleId]) @@index([roleId], map: "user_roles_role_id_idx") @@index([assignedBy], map: "user_roles_assigned_by_idx") @@map("user_roles") } model RolePermission { roleId BigInt @map("role_id") @db.UnsignedBigInt permissionId BigInt @map("permission_id") @db.UnsignedBigInt role Role @relation(fields: [roleId], references: [id], onDelete: Restrict) permission Permission @relation(fields: [permissionId], references: [id], onDelete: Restrict) @@id([roleId, permissionId]) @@index([permissionId], map: "role_permissions_permission_id_idx") @@map("role_permissions") } model AuditLog { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt requestId String @map("request_id") @db.Char(36) actorUserId BigInt? @map("actor_user_id") @db.UnsignedBigInt actorRole String? @map("actor_role") @db.VarChar(64) action String @db.VarChar(100) resourceType String? @map("resource_type") @db.VarChar(100) resourcePublicId String? @map("resource_public_id") @db.VarChar(100) result AuditResult metadataJson Json? @map("metadata_json") ipHash String? @map("ip_hash") @db.Char(64) userAgentSummary String? @map("user_agent_summary") @db.VarChar(255) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) actor User? @relation("AuditActor", fields: [actorUserId], references: [id], onDelete: Restrict) @@index([actorUserId, createdAt], map: "audit_logs_actor_created_at_idx") @@index([resourceType, resourcePublicId, createdAt], map: "audit_logs_resource_created_at_idx") @@index([action, createdAt], map: "audit_logs_action_created_at_idx") @@map("audit_logs") } model Consent { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) userId BigInt? @map("user_id") @db.UnsignedBigInt beneficiaryId BigInt? @map("beneficiary_id") @db.UnsignedBigInt consentType ConsentType @map("consent_type") version String @db.VarChar(32) grantedBy ConsentGrantedBy @map("granted_by") grantedAt DateTime @map("granted_at") @db.DateTime(3) revokedAt DateTime? @map("revoked_at") @db.DateTime(3) evidenceJson Json? @map("evidence_json") ipHash String? @map("ip_hash") @db.Char(64) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) user User? @relation(fields: [userId], references: [id], onDelete: Restrict) beneficiary BeneficiaryProfile? @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) application ServiceApplication? beneficiaryContact BeneficiaryContact? volunteer Volunteer? @@index([userId, consentType, grantedAt], map: "consents_user_type_granted_at_idx") @@index([beneficiaryId, consentType, grantedAt], map: "consents_beneficiary_type_granted_at_idx") @@map("consents") } model ServiceApplication { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) applicationNo String @unique @map("application_no") @db.VarChar(32) applicantUserId BigInt @map("applicant_user_id") @db.UnsignedBigInt beneficiaryId BigInt? @map("beneficiary_id") @db.UnsignedBigInt consentId BigInt @unique @map("consent_id") @db.UnsignedBigInt sourceFollowUpTaskId BigInt? @unique @map("source_follow_up_task_id") @db.UnsignedBigInt parentApplicationId BigInt? @map("parent_application_id") @db.UnsignedBigInt clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) applyMode ApplicationApplyMode @map("apply_mode") serviceCategory ServiceCategory @map("service_category") beneficiaryNameEncrypted String @map("beneficiary_name_encrypted") @db.VarChar(512) contactMobileEncrypted String @map("contact_mobile_encrypted") @db.VarChar(512) contactMobileHash String @map("contact_mobile_hash") @db.Char(64) regionCode String @map("region_code") @db.VarChar(100) descriptionEncrypted String @map("description_encrypted") @db.Text preferredContactTime String? @map("preferred_contact_time") @db.VarChar(100) needsHomeVisit Boolean? @map("needs_home_visit") mobilityDifficulty Boolean? @map("mobility_difficulty") status ServiceApplicationStatus @default(SUBMITTED) source ApplicationSource @default(WECHAT_MINIPROGRAM) submittedAt DateTime @map("submitted_at") @db.DateTime(3) acceptedAt DateTime? @map("accepted_at") @db.DateTime(3) closedAt DateTime? @map("closed_at") @db.DateTime(3) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) applicant User @relation("ApplicationApplicant", fields: [applicantUserId], references: [id], onDelete: Restrict) beneficiary BeneficiaryProfile? @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) consent Consent @relation(fields: [consentId], references: [id], onDelete: Restrict) statusHistory ServiceApplicationStatusHistory[] serviceCase ServiceCase? sourceFollowUpTask FollowUpTask? @relation("FollowUpContinuedApplication", fields: [sourceFollowUpTaskId], references: [id], onDelete: Restrict) parentApplication ServiceApplication? @relation("ContinuedApplications", fields: [parentApplicationId], references: [id], onDelete: Restrict) continuedApplications ServiceApplication[] @relation("ContinuedApplications") @@unique([applicantUserId, clientRequestId], map: "service_applications_applicant_client_request_key") @@index([applicantUserId, submittedAt], map: "service_applications_applicant_submitted_at_idx") @@index([status, submittedAt], map: "service_applications_status_submitted_at_idx") @@index([serviceCategory, submittedAt], map: "service_applications_category_submitted_at_idx") @@index([contactMobileHash], map: "service_applications_contact_mobile_hash_idx") @@index([beneficiaryId, submittedAt], map: "service_applications_beneficiary_submitted_at_idx") @@index([parentApplicationId, submittedAt], map: "service_applications_parent_submitted_at_idx") @@map("service_applications") } model ServiceApplicationStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt applicationId BigInt @map("application_id") @db.UnsignedBigInt fromStatus ServiceApplicationStatus? @map("from_status") toStatus ServiceApplicationStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) application ServiceApplication @relation(fields: [applicationId], references: [id], onDelete: Restrict) operator User @relation("ApplicationStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([applicationId, createdAt], map: "application_status_history_application_created_at_idx") @@index([operatorUserId, createdAt], map: "application_status_history_operator_created_at_idx") @@map("service_application_status_history") } model BeneficiaryProfile { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) displayNameEncrypted String @map("display_name_encrypted") @db.VarChar(512) displayNameHash String @map("display_name_hash") @db.Char(64) gender BeneficiaryGender? birthYear Int? @map("birth_year") @db.UnsignedSmallInt mobileEncrypted String? @map("mobile_encrypted") @db.VarChar(512) mobileHash String? @map("mobile_hash") @db.Char(64) regionCode String @map("region_code") @db.VarChar(100) addressDetailEncrypted String? @map("address_detail_encrypted") @db.VarChar(1024) primaryCategory ServiceCategory @map("primary_category") keyCareFlag Boolean @default(false) @map("key_care_flag") isMinor Boolean @default(false) @map("is_minor") status BeneficiaryStatus @default(ACTIVE) notesEncrypted String? @map("notes_encrypted") @db.Text createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) creator User @relation("BeneficiaryCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("BeneficiaryUpdater", fields: [updatedById], references: [id], onDelete: Restrict) contacts BeneficiaryContact[] beneficiaryTags BeneficiaryTag[] applications ServiceApplication[] serviceCases ServiceCase[] serviceRecords ServiceRecord[] consents Consent[] followUpTasks FollowUpTask[] @@index([displayNameHash], map: "beneficiary_profiles_display_name_hash_idx") @@index([mobileHash], map: "beneficiary_profiles_mobile_hash_idx") @@index([primaryCategory, status, createdAt], map: "beneficiary_profiles_category_status_created_at_idx") @@index([keyCareFlag, status, createdAt], map: "beneficiary_profiles_key_care_status_created_at_idx") @@map("beneficiary_profiles") } model BeneficiaryContact { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) beneficiaryId BigInt @map("beneficiary_id") @db.UnsignedBigInt nameEncrypted String @map("name_encrypted") @db.VarChar(512) relation String @db.VarChar(50) mobileEncrypted String @map("mobile_encrypted") @db.VarChar(512) mobileHash String @map("mobile_hash") @db.Char(64) isGuardian Boolean @default(false) @map("is_guardian") isEmergencyContact Boolean @default(false) @map("is_emergency_contact") consentRecordId BigInt? @unique @map("consent_record_id") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) removedAt DateTime? @map("removed_at") @db.DateTime(3) beneficiary BeneficiaryProfile @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) consentRecord Consent? @relation(fields: [consentRecordId], references: [id], onDelete: Restrict) @@index([beneficiaryId, removedAt, isGuardian], map: "beneficiary_contacts_beneficiary_active_guardian_idx") @@index([mobileHash], map: "beneficiary_contacts_mobile_hash_idx") @@map("beneficiary_contacts") } model Tag { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) code String @unique @db.VarChar(64) name String @db.VarChar(50) description String? @db.VarChar(255) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) beneficiaryTags BeneficiaryTag[] @@map("tags") } model BeneficiaryTag { beneficiaryId BigInt @map("beneficiary_id") @db.UnsignedBigInt tagId BigInt @map("tag_id") @db.UnsignedBigInt assignedById BigInt @map("assigned_by") @db.UnsignedBigInt assignedAt DateTime @default(now()) @map("assigned_at") @db.DateTime(3) beneficiary BeneficiaryProfile @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) tag Tag @relation(fields: [tagId], references: [id], onDelete: Restrict) assigner User @relation("BeneficiaryTagAssigner", fields: [assignedById], references: [id], onDelete: Restrict) @@id([beneficiaryId, tagId]) @@index([tagId], map: "beneficiary_tags_tag_id_idx") @@map("beneficiary_tags") } model ServiceCase { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) caseNo String @unique @map("case_no") @db.VarChar(32) applicationId BigInt @unique @map("application_id") @db.UnsignedBigInt acceptRequestId String @map("accept_request_id") @db.Char(36) acceptRequestFingerprint String @map("accept_request_fingerprint") @db.Char(64) beneficiaryId BigInt @map("beneficiary_id") @db.UnsignedBigInt projectId BigInt? @map("project_id") @db.UnsignedBigInt ownerStaffId BigInt @map("owner_staff_id") @db.UnsignedBigInt category ServiceCategory priority ServiceCasePriority @default(NORMAL) status ServiceCaseStatus @default(ASSIGNED) plannedStartAt DateTime? @map("planned_start_at") @db.DateTime(3) plannedEndAt DateTime? @map("planned_end_at") @db.DateTime(3) serviceLocationEncrypted String? @map("service_location_encrypted") @db.VarChar(1024) summaryEncrypted String @map("summary_encrypted") @db.Text resultSummaryEncrypted String? @map("result_summary_encrypted") @db.Text followUpPlanEncrypted String? @map("follow_up_plan_encrypted") @db.Text completedAt DateTime? @map("completed_at") @db.DateTime(3) completeRequestId String? @unique @map("complete_request_id") @db.Char(36) completeRequestFingerprint String? @map("complete_request_fingerprint") @db.Char(64) createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) application ServiceApplication @relation(fields: [applicationId], references: [id], onDelete: Restrict) beneficiary BeneficiaryProfile @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) project Project? @relation(fields: [projectId], references: [id], onDelete: Restrict) owner User @relation("CaseOwner", fields: [ownerStaffId], references: [id], onDelete: Restrict) creator User @relation("CaseCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("CaseUpdater", fields: [updatedById], references: [id], onDelete: Restrict) assignees CaseAssignee[] statusHistory ServiceCaseStatusHistory[] serviceRecords ServiceRecord[] files File[] followUpTasks FollowUpTask[] @@unique([createdById, acceptRequestId], map: "service_cases_creator_accept_request_key") @@index([ownerStaffId, status, plannedStartAt], map: "service_cases_owner_status_planned_idx") @@index([beneficiaryId, createdAt], map: "service_cases_beneficiary_created_at_idx") @@index([projectId, createdAt], map: "service_cases_project_created_at_idx") @@index([status, createdAt], map: "service_cases_status_created_at_idx") @@map("service_cases") } model CaseAssignee { caseId BigInt @map("case_id") @db.UnsignedBigInt userId BigInt @map("user_id") @db.UnsignedBigInt assigneeType CaseAssigneeType @map("assignee_type") role CaseAssigneeRole assignedById BigInt @map("assigned_by") @db.UnsignedBigInt assignedAt DateTime @default(now()) @map("assigned_at") @db.DateTime(3) removedAt DateTime? @map("removed_at") @db.DateTime(3) serviceCase ServiceCase @relation(fields: [caseId], references: [id], onDelete: Restrict) user User @relation(fields: [userId], references: [id], onDelete: Restrict) assigner User @relation("CaseAssigneeAssigner", fields: [assignedById], references: [id], onDelete: Restrict) @@id([caseId, userId]) @@index([userId, removedAt, assignedAt], map: "case_assignees_user_active_assigned_idx") @@map("case_assignees") } model ServiceCaseStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt caseId BigInt @map("case_id") @db.UnsignedBigInt fromStatus ServiceCaseStatus? @map("from_status") toStatus ServiceCaseStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) serviceCase ServiceCase @relation(fields: [caseId], references: [id], onDelete: Restrict) operator User @relation("CaseStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([caseId, createdAt], map: "case_status_history_case_created_at_idx") @@index([operatorUserId, createdAt], map: "case_status_history_operator_created_at_idx") @@map("service_case_status_history") } model ServiceRecord { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) caseId BigInt @map("case_id") @db.UnsignedBigInt beneficiaryId BigInt @map("beneficiary_id") @db.UnsignedBigInt clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) serviceStartAt DateTime @map("service_start_at") @db.DateTime(3) serviceEndAt DateTime? @map("service_end_at") @db.DateTime(3) serviceType ServiceRecordType @map("service_type") contentEncrypted String @map("content_encrypted") @db.Text resultEncrypted String @map("result_encrypted") @db.Text followUpSuggestionEncrypted String? @map("follow_up_suggestion_encrypted") @db.Text beneficiaryConfirmStatus BeneficiaryConfirmStatus @default(NOT_REQUESTED) @map("beneficiary_confirm_status") createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt revision Int @default(1) @db.UnsignedInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) serviceCase ServiceCase @relation(fields: [caseId], references: [id], onDelete: Restrict) beneficiary BeneficiaryProfile @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) creator User @relation("ServiceRecordCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("ServiceRecordUpdater", fields: [updatedById], references: [id], onDelete: Restrict) attachments ServiceRecordFile[] revisions ServiceRecordRevision[] @@unique([createdById, clientRequestId], map: "service_records_creator_client_request_key") @@index([caseId, serviceStartAt], map: "service_records_case_start_at_idx") @@index([beneficiaryId, serviceStartAt], map: "service_records_beneficiary_start_at_idx") @@map("service_records") } model ServiceRecordRevision { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt serviceRecordId BigInt @map("service_record_id") @db.UnsignedBigInt revision Int @db.UnsignedInt serviceStartAt DateTime @map("service_start_at") @db.DateTime(3) serviceEndAt DateTime? @map("service_end_at") @db.DateTime(3) serviceType ServiceRecordType @map("service_type") contentEncrypted String @map("content_encrypted") @db.Text resultEncrypted String @map("result_encrypted") @db.Text followUpSuggestionEncrypted String? @map("follow_up_suggestion_encrypted") @db.Text beneficiaryConfirmStatus BeneficiaryConfirmStatus @map("beneficiary_confirm_status") revisedById BigInt @map("revised_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) serviceRecord ServiceRecord @relation(fields: [serviceRecordId], references: [id], onDelete: Restrict) reviser User @relation("ServiceRecordReviser", fields: [revisedById], references: [id], onDelete: Restrict) @@unique([serviceRecordId, revision], map: "service_record_revisions_record_revision_key") @@index([revisedById, createdAt], map: "service_record_revisions_reviser_created_at_idx") @@map("service_record_revisions") } model File { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) caseId BigInt? @map("case_id") @db.UnsignedBigInt clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) storageProvider String @map("storage_provider") @db.VarChar(50) bucket String @db.VarChar(255) objectKey String @unique @map("object_key") @db.VarChar(512) originalFilenameEncrypted String @map("original_filename_encrypted") @db.VarChar(1024) mimeType String @map("mime_type") @db.VarChar(100) size BigInt @db.UnsignedBigInt sha256 String? @db.Char(64) businessType FileBusinessType @map("business_type") uploaderUserId BigInt @map("uploader_user_id") @db.UnsignedBigInt status FileStatus @default(UPLOAD_PENDING) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) serviceCase ServiceCase? @relation(fields: [caseId], references: [id], onDelete: Restrict) uploader User @relation("FileUploader", fields: [uploaderUserId], references: [id], onDelete: Restrict) serviceRecords ServiceRecordFile[] projectCover Project? @relation("ProjectCover") activityCover Activity? @relation("ActivityCover") contentCover ContentPost? @relation("ContentCover") @@unique([uploaderUserId, clientRequestId], map: "files_uploader_client_request_key") @@index([caseId, status, createdAt], map: "files_case_status_created_at_idx") @@index([uploaderUserId, status, createdAt], map: "files_uploader_status_created_at_idx") @@map("files") } model ServiceRecordFile { serviceRecordId BigInt @map("service_record_id") @db.UnsignedBigInt fileId BigInt @map("file_id") @db.UnsignedBigInt attachedAt DateTime @default(now()) @map("attached_at") @db.DateTime(3) serviceRecord ServiceRecord @relation(fields: [serviceRecordId], references: [id], onDelete: Restrict) file File @relation(fields: [fileId], references: [id], onDelete: Restrict) @@id([serviceRecordId, fileId]) @@index([fileId], map: "service_record_files_file_id_idx") @@map("service_record_files") } model FollowUpTask { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) followUpNo String @unique @map("follow_up_no") @db.VarChar(32) beneficiaryId BigInt @map("beneficiary_id") @db.UnsignedBigInt caseId BigInt? @map("case_id") @db.UnsignedBigInt ownerStaffId BigInt @map("owner_staff_id") @db.UnsignedBigInt dueAt DateTime @map("due_at") @db.DateTime(3) followUpType FollowUpType @map("follow_up_type") status FollowUpStatus @default(PENDING) source FollowUpSource reasonEncrypted String @map("reason_encrypted") @db.Text resultCode FollowUpResultCode? @map("result_code") resultNoteEncrypted String? @map("result_note_encrypted") @db.Text createRequestId String @map("create_request_id") @db.Char(36) createRequestFingerprint String @map("create_request_fingerprint") @db.Char(64) completeRequestId String? @map("complete_request_id") @db.Char(36) completeRequestFingerprint String? @map("complete_request_fingerprint") @db.Char(64) completedAt DateTime? @map("completed_at") @db.DateTime(3) createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) beneficiary BeneficiaryProfile @relation(fields: [beneficiaryId], references: [id], onDelete: Restrict) serviceCase ServiceCase? @relation(fields: [caseId], references: [id], onDelete: Restrict) owner User @relation("FollowUpOwner", fields: [ownerStaffId], references: [id], onDelete: Restrict) creator User @relation("FollowUpCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("FollowUpUpdater", fields: [updatedById], references: [id], onDelete: Restrict) statusHistory FollowUpStatusHistory[] continuedApplication ServiceApplication? @relation("FollowUpContinuedApplication") @@unique([createdById, createRequestId], map: "follow_up_tasks_creator_request_key") @@index([ownerStaffId, status, dueAt], map: "follow_up_tasks_owner_status_due_at_idx") @@index([status, dueAt], map: "follow_up_tasks_status_due_at_idx") @@index([beneficiaryId, dueAt], map: "follow_up_tasks_beneficiary_due_at_idx") @@index([caseId, createdAt], map: "follow_up_tasks_case_created_at_idx") @@map("follow_up_tasks") } model FollowUpStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt followUpTaskId BigInt @map("follow_up_task_id") @db.UnsignedBigInt fromStatus FollowUpStatus? @map("from_status") toStatus FollowUpStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) followUpTask FollowUpTask @relation(fields: [followUpTaskId], references: [id], onDelete: Restrict) operator User @relation("FollowUpStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([followUpTaskId, createdAt], map: "follow_up_status_history_task_created_at_idx") @@index([operatorUserId, createdAt], map: "follow_up_status_history_operator_created_at_idx") @@map("follow_up_status_history") } model Volunteer { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) userId BigInt @unique @map("user_id") @db.UnsignedBigInt consentId BigInt @unique @map("consent_id") @db.UnsignedBigInt realNameEncrypted String @map("real_name_encrypted") @db.VarChar(512) realNameHash String @map("real_name_hash") @db.Char(64) mobileEncrypted String @map("mobile_encrypted") @db.VarChar(512) mobileHash String @map("mobile_hash") @db.Char(64) regionCode String @map("region_code") @db.VarChar(100) availabilityNoteEncrypted String @map("availability_note_encrypted") @db.Text status VolunteerStatus @default(APPLIED) approvedById BigInt? @map("approved_by") @db.UnsignedBigInt approvedAt DateTime? @map("approved_at") @db.DateTime(3) revision Int @default(1) @db.UnsignedInt createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) consent Consent @relation(fields: [consentId], references: [id], onDelete: Restrict) reviewer User? @relation("VolunteerReviewer", fields: [approvedById], references: [id], onDelete: Restrict) creator User @relation("VolunteerCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("VolunteerUpdater", fields: [updatedById], references: [id], onDelete: Restrict) skills VolunteerSkill[] interests VolunteerInterest[] statusHistory VolunteerStatusHistory[] registrations ActivityRegistration[] @@index([status, createdAt], map: "volunteers_status_created_at_idx") @@index([mobileHash], map: "volunteers_mobile_hash_idx") @@index([regionCode, status], map: "volunteers_region_status_idx") @@map("volunteers") } model VolunteerSkill { volunteerId BigInt @map("volunteer_id") @db.UnsignedBigInt skillCode String @map("skill_code") @db.VarChar(64) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) volunteer Volunteer @relation(fields: [volunteerId], references: [id], onDelete: Restrict) @@id([volunteerId, skillCode]) @@index([skillCode], map: "volunteer_skills_code_idx") @@map("volunteer_skills") } model VolunteerInterest { volunteerId BigInt @map("volunteer_id") @db.UnsignedBigInt category ServiceCategory createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) volunteer Volunteer @relation(fields: [volunteerId], references: [id], onDelete: Restrict) @@id([volunteerId, category]) @@index([category], map: "volunteer_interests_category_idx") @@map("volunteer_interests") } model VolunteerStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt volunteerId BigInt @map("volunteer_id") @db.UnsignedBigInt requestId String @unique @map("request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) fromStatus VolunteerStatus? @map("from_status") toStatus VolunteerStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) noteEncrypted String? @map("note_encrypted") @db.Text createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) volunteer Volunteer @relation(fields: [volunteerId], references: [id], onDelete: Restrict) operator User @relation("VolunteerStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([volunteerId, createdAt], map: "volunteer_status_history_volunteer_created_at_idx") @@index([operatorUserId, createdAt], map: "volunteer_status_history_operator_created_at_idx") @@map("volunteer_status_history") } model Project { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) projectNo String @unique @map("project_no") @db.VarChar(32) clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) name String @db.VarChar(200) category ServiceCategory summary String @db.VarChar(500) content String @db.Text coverFileId BigInt? @unique @map("cover_file_id") @db.UnsignedBigInt managerUserId BigInt @map("manager_user_id") @db.UnsignedBigInt startDate DateTime @map("start_date") @db.Date endDate DateTime @map("end_date") @db.Date targetPeople Int? @map("target_people") @db.UnsignedInt status ProjectStatus @default(DRAFT) isPublic Boolean @default(false) @map("is_public") sortOrder Int @default(0) @map("sort_order") revision Int @default(1) @db.UnsignedInt createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) coverFile File? @relation("ProjectCover", fields: [coverFileId], references: [id], onDelete: Restrict) manager User @relation("ProjectManager", fields: [managerUserId], references: [id], onDelete: Restrict) creator User @relation("ProjectCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("ProjectUpdater", fields: [updatedById], references: [id], onDelete: Restrict) statusHistory ProjectStatusHistory[] activities Activity[] serviceCases ServiceCase[] @@unique([createdById, clientRequestId], map: "projects_creator_request_key") @@index([status, isPublic, sortOrder, createdAt], map: "projects_public_status_sort_idx") @@index([managerUserId, status, createdAt], map: "projects_manager_status_idx") @@map("projects") } model ProjectStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt projectId BigInt @map("project_id") @db.UnsignedBigInt requestId String @unique @map("request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) fromStatus ProjectStatus? @map("from_status") toStatus ProjectStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) project Project @relation(fields: [projectId], references: [id], onDelete: Restrict) operator User @relation("ProjectStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([projectId, createdAt], map: "project_status_history_project_created_at_idx") @@map("project_status_history") } model Activity { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) activityNo String @unique @map("activity_no") @db.VarChar(32) projectId BigInt? @map("project_id") @db.UnsignedBigInt clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) title String @db.VarChar(200) summary String @db.VarChar(500) content String @db.Text coverFileId BigInt? @unique @map("cover_file_id") @db.UnsignedBigInt startAt DateTime @map("start_at") @db.DateTime(3) endAt DateTime @map("end_at") @db.DateTime(3) registrationDeadline DateTime @map("registration_deadline") @db.DateTime(3) locationText String @map("location_text") @db.VarChar(300) capacity Int? @db.UnsignedInt status ActivityStatus @default(DRAFT) publishedAt DateTime? @map("published_at") @db.DateTime(3) revision Int @default(1) @db.UnsignedInt createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) project Project? @relation(fields: [projectId], references: [id], onDelete: Restrict) coverFile File? @relation("ActivityCover", fields: [coverFileId], references: [id], onDelete: Restrict) creator User @relation("ActivityCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("ActivityUpdater", fields: [updatedById], references: [id], onDelete: Restrict) statusHistory ActivityStatusHistory[] registrations ActivityRegistration[] @@unique([createdById, clientRequestId], map: "activities_creator_request_key") @@index([status, startAt], map: "activities_status_start_at_idx") @@index([projectId, startAt], map: "activities_project_start_at_idx") @@map("activities") } model ActivityStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt activityId BigInt @map("activity_id") @db.UnsignedBigInt requestId String @unique @map("request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) fromStatus ActivityStatus? @map("from_status") toStatus ActivityStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) activity Activity @relation(fields: [activityId], references: [id], onDelete: Restrict) operator User @relation("ActivityStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([activityId, createdAt], map: "activity_status_history_activity_created_at_idx") @@map("activity_status_history") } model ActivityRegistration { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) activityId BigInt @map("activity_id") @db.UnsignedBigInt userId BigInt @map("user_id") @db.UnsignedBigInt volunteerId BigInt @map("volunteer_id") @db.UnsignedBigInt clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) status ActivityRegistrationStatus @default(PENDING) checkInStatus ActivityCheckInStatus @default(NOT_CHECKED_IN) @map("check_in_status") registeredAt DateTime @default(now()) @map("registered_at") @db.DateTime(3) reviewedById BigInt? @map("reviewed_by") @db.UnsignedBigInt reviewedAt DateTime? @map("reviewed_at") @db.DateTime(3) reviewNoteEncrypted String? @map("review_note_encrypted") @db.Text checkedInAt DateTime? @map("checked_in_at") @db.DateTime(3) checkedInById BigInt? @map("checked_in_by") @db.UnsignedBigInt serviceMinutes Int? @map("service_minutes") @db.UnsignedInt serviceMinutesRecordedAt DateTime? @map("service_minutes_recorded_at") @db.DateTime(3) serviceMinutesRecordedById BigInt? @map("service_minutes_recorded_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) activity Activity @relation(fields: [activityId], references: [id], onDelete: Restrict) user User @relation("ActivityRegistrationUser", fields: [userId], references: [id], onDelete: Restrict) volunteer Volunteer @relation(fields: [volunteerId], references: [id], onDelete: Restrict) reviewer User? @relation("RegistrationReviewer", fields: [reviewedById], references: [id], onDelete: Restrict) checkInOperator User? @relation("RegistrationCheckInOperator", fields: [checkedInById], references: [id], onDelete: Restrict) serviceMinutesOperator User? @relation("RegistrationMinutesOperator", fields: [serviceMinutesRecordedById], references: [id], onDelete: Restrict) history ActivityRegistrationHistory[] @@unique([activityId, userId], map: "activity_registrations_activity_user_key") @@unique([userId, clientRequestId], map: "activity_registrations_user_request_key") @@index([activityId, status, registeredAt], map: "activity_registrations_activity_status_idx") @@index([volunteerId, registeredAt], map: "activity_registrations_volunteer_registered_idx") @@map("activity_registrations") } model ActivityRegistrationHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt registrationId BigInt @map("registration_id") @db.UnsignedBigInt requestId String @unique @map("request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) fromStatus ActivityRegistrationStatus? @map("from_status") toStatus ActivityRegistrationStatus? @map("to_status") fromCheckInStatus ActivityCheckInStatus? @map("from_check_in_status") toCheckInStatus ActivityCheckInStatus? @map("to_check_in_status") serviceMinutesBefore Int? @map("service_minutes_before") @db.UnsignedInt serviceMinutesAfter Int? @map("service_minutes_after") @db.UnsignedInt operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt actionCode String @map("action_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) registration ActivityRegistration @relation(fields: [registrationId], references: [id], onDelete: Restrict) operator User @relation("RegistrationHistoryOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([registrationId, createdAt], map: "registration_history_registration_created_at_idx") @@map("activity_registration_history") } model ContentPost { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) type ContentPostType title String @db.VarChar(200) summary String @db.VarChar(500) content String @db.Text coverFileId BigInt? @unique @map("cover_file_id") @db.UnsignedBigInt status ContentPostStatus @default(DRAFT) revision Int @default(1) @db.UnsignedInt privacyReviewedAt DateTime? @map("privacy_reviewed_at") @db.DateTime(3) reviewedById BigInt? @map("reviewed_by") @db.UnsignedBigInt reviewedAt DateTime? @map("reviewed_at") @db.DateTime(3) publishedAt DateTime? @map("published_at") @db.DateTime(3) createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) coverFile File? @relation("ContentCover", fields: [coverFileId], references: [id], onDelete: Restrict) creator User @relation("ContentCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("ContentUpdater", fields: [updatedById], references: [id], onDelete: Restrict) reviewer User? @relation("ContentReviewer", fields: [reviewedById], references: [id], onDelete: Restrict) statusHistory ContentPostStatusHistory[] @@unique([createdById, clientRequestId], map: "content_posts_creator_request_key") @@index([status, type, publishedAt], map: "content_posts_status_type_published_idx") @@index([createdById, status, updatedAt], map: "content_posts_creator_status_updated_idx") @@map("content_posts") } model ContentPostStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt contentPostId BigInt @map("content_post_id") @db.UnsignedBigInt requestId String @unique @map("request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) fromStatus ContentPostStatus? @map("from_status") toStatus ContentPostStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt reasonCode String @map("reason_code") @db.VarChar(100) noteEncrypted String? @map("note_encrypted") @db.Text createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) contentPost ContentPost @relation(fields: [contentPostId], references: [id], onDelete: Restrict) operator User @relation("ContentStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([contentPostId, createdAt], map: "content_status_history_post_created_idx") @@index([operatorUserId, createdAt], map: "content_status_history_operator_created_idx") @@map("content_post_status_history") } model FinancialDisclosure { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) clientRequestId String @map("client_request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) title String @db.VarChar(200) summary String? @db.VarChar(500) richText String @map("rich_text") @db.MediumText status FinancialDisclosureStatus @default(DRAFT) isPinned Boolean @default(false) @map("is_pinned") sortOrder Int @default(0) @map("sort_order") revision Int @default(1) @db.UnsignedInt publishedAt DateTime? @map("published_at") @db.DateTime(3) createdById BigInt @map("created_by") @db.UnsignedBigInt updatedById BigInt @map("updated_by") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) creator User @relation("FinancialDisclosureCreator", fields: [createdById], references: [id], onDelete: Restrict) updater User @relation("FinancialDisclosureUpdater", fields: [updatedById], references: [id], onDelete: Restrict) statusHistory FinancialDisclosureStatusHistory[] @@unique([createdById, clientRequestId], map: "financial_disclosures_creator_request_key") @@index([status, isPinned, sortOrder, publishedAt], map: "financial_disclosures_public_list_idx") @@index([updatedAt], map: "financial_disclosures_updated_at_idx") @@map("financial_disclosures") } model FinancialDisclosureStatusHistory { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt financialDisclosureId BigInt @map("financial_disclosure_id") @db.UnsignedBigInt requestId String @unique @map("request_id") @db.Char(36) requestFingerprint String @map("request_fingerprint") @db.Char(64) fromStatus FinancialDisclosureStatus? @map("from_status") toStatus FinancialDisclosureStatus @map("to_status") operatorUserId BigInt @map("operator_user_id") @db.UnsignedBigInt createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) financialDisclosure FinancialDisclosure @relation(fields: [financialDisclosureId], references: [id], onDelete: Restrict) operator User @relation("FinancialDisclosureStatusOperator", fields: [operatorUserId], references: [id], onDelete: Restrict) @@index([financialDisclosureId, createdAt], map: "financial_disclosure_history_document_idx") @@index([operatorUserId, createdAt], map: "financial_disclosure_history_operator_idx") @@map("financial_disclosure_status_history") } model Notification { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) userId BigInt @map("user_id") @db.UnsignedBigInt eventKey String @map("event_key") @db.VarChar(160) type NotificationType title String @db.VarChar(120) body String @db.VarChar(500) resourceType String? @map("resource_type") @db.VarChar(80) resourcePublicId String? @map("resource_public_id") @db.Char(36) readAt DateTime? @map("read_at") @db.DateTime(3) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) deliveries NotificationDelivery[] @@unique([userId, eventKey], map: "notifications_user_event_key") @@index([userId, readAt, createdAt], map: "notifications_user_read_created_idx") @@map("notifications") } model NotificationPreference { userId BigInt @map("user_id") @db.UnsignedBigInt type NotificationType inAppEnabled Boolean @default(true) @map("in_app_enabled") wechatEnabled Boolean @default(false) @map("wechat_enabled") authorizedAt DateTime? @map("authorized_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) user User @relation(fields: [userId], references: [id], onDelete: Restrict) @@id([userId, type]) @@index([type, wechatEnabled], map: "notification_preferences_type_wechat_idx") @@map("notification_preferences") } model NotificationDelivery { id BigInt @id @default(autoincrement()) @db.UnsignedBigInt publicId String @unique @map("public_id") @db.Char(36) notificationId BigInt @map("notification_id") @db.UnsignedBigInt channel NotificationChannel status NotificationDeliveryStatus @default(PENDING) attemptCount Int @default(0) @map("attempt_count") @db.UnsignedInt nextAttemptAt DateTime @default(now()) @map("next_attempt_at") @db.DateTime(3) lastAttemptAt DateTime? @map("last_attempt_at") @db.DateTime(3) providerMessageId String? @map("provider_message_id") @db.VarChar(160) errorCode String? @map("error_code") @db.VarChar(100) createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3) updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3) notification Notification @relation(fields: [notificationId], references: [id], onDelete: Restrict) @@unique([notificationId, channel], map: "notification_deliveries_notification_channel_key") @@index([status, nextAttemptAt], map: "notification_deliveries_status_next_idx") @@map("notification_deliveries") }