Giao diện
@digiforce-nc/plugin-record-history
Plugin lịch sử thay đổi bản ghi — ghi lại mọi thay đổi (create, update, destroy) trên bản ghi với chi tiết giá trị cũ → mới cho từng field.
Plugin này làm gì?
Khi cần biết ai đã sửa gì, khi nào trên một bản ghi, plugin tự động ghi lại mọi thay đổi thông qua DB hooks. Hệ thống sử dụng cơ chế snapshot + diff: chụp snapshot giá trị field trước và sau thay đổi, so sánh để tạo lịch sử chi tiết.
Tính năng chính
| # | Tính năng | Mô tả |
|---|---|---|
| 1 | Auto-tracking | Ghi lại create, update, destroy qua DB hooks |
| 2 | Field-level diff | Chi tiết giá trị cũ → mới cho từng field |
| 3 | User attribution | Ghi nhận user thực hiện thay đổi |
| 4 | Per-collection config | Bật/tắt tracking cho từng Collection và từng field |
| 5 | Relation support | Theo dõi thay đổi trên relation fields |
| 6 | Multi data source | Hỗ trợ tracking across nhiều data source |
| 7 | Async processing | Sử dụng Event Queue để không ảnh hưởng response time |
Database
Plugin sử dụng Database connection riêng (historyDB) cho các bảng lịch sử:
| Bảng | Mô tả |
|---|---|
recordHistories | Lịch sử tổng: uuid, requestId, recordId, collectionName, dataSourceKey, action, userId |
recordFieldHistories | Lịch sử per-field: fieldPath, before, after, options |
recordFieldSnapshots | Snapshot giá trị hiện tại — dùng để tính diff |
recordHistoryCollections | Cấu hình: Collection nào cần tracking |
recordHistoryFields | Cấu hình: Field nào cần tracking trong mỗi Collection |
API endpoints
| Endpoint | Mô tả | Quyền |
|---|---|---|
recordHistories:* | Đọc lịch sử thay đổi | Admin |
recordFieldHistories:* | Đọc chi tiết thay đổi per-field | Admin |
recordHistoryCollections:* | Cấu hình tracking | Admin |
recordHistoryTemplate:get | Lấy template hiển thị | Đã đăng nhập |
Dependencies
| Package | Vai trò |
|---|---|
@digiforce-nc/server | Server framework — DB hooks, EventQueue |
@digiforce-nc/database | Database ORM |
@digiforce-nc/client | Client UI framework |
@digiforce-nc/cache | Cache cho sync-snapshots |