Skip to content

fix(prisma): resolve schema validation errors blocking setup#5

Open
TUAN130294 wants to merge 1 commit into
nclamvn:mainfrom
TUAN130294:fix/prisma-schema-and-setup-issues
Open

fix(prisma): resolve schema validation errors blocking setup#5
TUAN130294 wants to merge 1 commit into
nclamvn:mainfrom
TUAN130294:fix/prisma-schema-and-setup-issues

Conversation

@TUAN130294

Copy link
Copy Markdown

Summary

Fixes #1, #3 — All npm run setup / make setup commands fail at db:generate step due to Prisma schema validation errors.

Root Causes & Fixes

1. Duplicate enum ImportStatus (HRM-unified)

Two enums with the same name but different values exist in apps/HRM-unified/prisma/schema.prisma:

  • Line 85: ImportStatus with PENDING, PROCESSING, COMPLETED, FAILED, ROLLED_BACK (used by ImportJob)
  • Line 7207: ImportStatus with DRY_RUN, PREVIEWING, EXECUTING, COMPLETED, FAILED, ROLLED_BACK (used by ImportSession)

Fix: Renamed the second enum to ImportSessionStatus since it serves a distinct purpose (data import session lifecycle vs. generic import job status). Updated the ImportSession.status field type accordingly.

2. Missing reverse relations (HRM-unified)

Models KPIPeriod, KPIScore, DisciplinaryRecord, SalaryAdvance, ImportSession, and SystemSetting reference Tenant, User, and Employee but the reverse relation arrays were never added to those parent models.

Fix: Added the missing reverse relation fields to Tenant, User, and Employee models.

3. Missing datasource URL (HRM)

apps/HRM/prisma/schema.prisma datasource block had no url field.

Fix: Added url = env("DATABASE_URL").

4. DATABASE_URL mismatch (.env.example)

.env.example had postgresql://vierp:your-password@localhost:5432/vierp_dev but docker-compose.yml creates DB with user erp, password erp_dev_2026, database erp_dev.

Fix: Updated .env.example to postgresql://erp:erp_dev_2026@localhost:5432/erp_dev.

Verification

Tested npx prisma@5.22.0 validate on all 12 schema files:

✅ apps/Accounting/prisma/schema.prisma
✅ apps/CRM/prisma/schema.prisma
✅ apps/Ecommerce/prisma/schema.prisma
✅ apps/HRM/prisma/schema.prisma
✅ apps/HRM-AI/lacviet-hr-phase5/prisma/schema.prisma
✅ apps/HRM-AI/prisma/schema.prisma
✅ apps/HRM-unified/lacviet-hr-phase5/prisma/schema.prisma
✅ apps/HRM-unified/prisma/schema.prisma
✅ apps/MRP/prisma/schema.prisma
✅ apps/OTB/backend/prisma/schema.prisma
✅ apps/TPM-api/prisma/schema.prisma
✅ apps/TPM-api-nestjs/prisma/schema.prisma

Files Changed

  • apps/HRM-unified/prisma/schema.prisma — enum rename + reverse relations
  • apps/HRM/prisma/schema.prisma — datasource URL
  • .env.example — DATABASE_URL credentials

…, nclamvn#3)

- HRM-unified: rename duplicate ImportStatus enum to ImportSessionStatus
- HRM-unified: add missing reverse relations on Tenant, User, Employee
- HRM: add missing url field in datasource block
- .env.example: fix DATABASE_URL to match docker-compose.yml credentials
- All 12 Prisma schemas now pass validation
@ATNguyenVNN

Copy link
Copy Markdown

Sau khi fix được lỗi này, run dev thì port nào mở lên cũng lỗi 404. bạn có đang gặp tình huống này không?

@vnaisoft-huy

Copy link
Copy Markdown

nó bị 1 lỗi chung là có 2 file app (app/api và src/app )trong source, ai biết xử lý không

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lỗi/Bug] run make setup error db:generate

3 participants