Task: Backend Schema v1.6.0 Migration
Status: ✅ Completed
Priority: P1 (High - Breaking Changes)
Estimated Effort: 3-5 days
Dependencies: Schema v1.6.0 already created
Owner: Backend Team
📋 Overview
อัพเดท Backend Entities และ DTOs ให้ตรงกับ Schema v1.6.0 ที่มีการ Refactor โครงสร้างตาราง
🎯 Objectives
📝 Schema Changes Summary
Breaking Changes ⚠️
| Table |
Change |
Impact |
correspondence_recipients |
FK → correspondences(id) |
Update relation |
rfa_items |
rfarev_correspondence_id → rfa_revision_id |
Rename column |
Column Changes
| Table |
Old |
New |
Notes |
correspondence_revisions |
title |
subject |
Rename |
correspondence_revisions |
- |
body, remarks |
Add columns |
rfa_revisions |
title |
subject |
Rename |
rfa_revisions |
correspondence_id |
- |
Remove |
rfa_revisions |
- |
body, remarks, due_date |
Add columns |
Architecture Changes
| Table |
Change |
rfas |
Shared PK with correspondences (no AUTO_INCREMENT) |
rfas |
id references correspondences(id) |
🛠️ Implementation Steps
1. Update CorrespondenceRevision Entity
2. Update CorrespondenceRecipient Entity
3. Update RFA Entity (Shared PK Pattern)
4. Update RfaRevision Entity
5. Update RfaItem Entity
6. Update DTOs
🗂️ Files to Modify
Entities
| File |
Status |
Changes |
correspondence.entity.ts |
✅ |
Minor: add recipients relation |
correspondence-revision.entity.ts |
✅ |
Rename title→subject, add body/remarks |
correspondence-recipient.entity.ts |
✅ |
FK change to correspondence |
rfa.entity.ts |
✅ |
Shared PK pattern |
rfa-revision.entity.ts |
✅ |
Remove correspondenceId, add body/remarks |
rfa-item.entity.ts |
✅ |
Rename column |
DTOs
| File |
Status |
Changes |
create-correspondence-revision.dto.ts |
✅ |
title→subject, add body/remarks |
update-correspondence-revision.dto.ts |
✅ |
Same |
create-rfa-revision.dto.ts |
✅ |
title→subject, add fields |
update-rfa-revision.dto.ts |
✅ |
Same |
create-rfa-item.dto.ts |
✅ |
Column rename |
Services
| File |
Status |
Changes |
correspondence.service.ts |
✅ |
Update queries for new relations |
rfa.service.ts |
✅ |
Handle Shared PK creation |
✅ Verification
Unit Tests
Integration Tests
- Create new Correspondence → verify subject field saved
- Create new RFA → verify Shared PK pattern works
- Verify recipients linked to correspondence (not revision)
- Verify RFA items linked via rfa_revision_id
📚 Related Documents
🚨 Risks & Mitigation
| Risk |
Impact |
Mitigation |
| Breaking frontend |
High |
Update frontend types simultaneously |
| Data migration |
Medium |
Schema already handles FK changes |
| Test failures |
Low |
Update tests with new field names |
📌 Notes
- Schema v1.6.0 SQL files already exist in
specs/07-database/
- This task focuses on backend code changes only
- Frontend will need separate task for DTO/type updates
- Consider feature flag for gradual rollout