Bỏ qua, đến nội dung

Database Schema

ER Diagram

Bảng users — chi tiết tất cả field

FieldTypeRàng buộcMặc địnhMô tả
idbigIntPK, autoIncrement, NOT NULLID duy nhất của user
displaynamestringTên hiển thị. Là titleField của collection
usernamestringUNIQUETên đăng nhập. Validator: username: true
emailstringUNIQUEEmail. Validator: email
phonestringUNIQUESố điện thoại
passwordpasswordhidden: trueMật khẩu, hash bằng bcrypt. Không bao giờ trả về qua API (bị desensitize() loại bỏ)
passwordChangeTzbigIntTimestamp (ms) lần đổi password gần nhất. Được set tự động trong hook beforeUpdate
appLangstringMã ngôn ngữ giao diện (vd: vi-VN, en-US)
resetTokenstringUNIQUE, hidden: trueToken dùng cho reset password. Không trả về qua API
systemSettingsjson{}Object JSON lưu cài đặt cá nhân của user
createdAtdateautoThời điểm tạo user (interface createdAt)
updatedAtdateautoThời điểm cập nhật gần nhất (interface updatedAt)
createdByIdbigIntFK → users.id, INDEXautoID người tạo (auto-inject, createOnly)
updatedByIdbigIntFK → users.id, INDEXautoID người cập nhật gần nhất (auto-inject)

Thuộc tính collection

Thuộc tínhGiá trịÝ nghĩa
modelUserModelSử dụng model tùy chỉnh với desensitize()
titleFielddisplaynameField hiển thị khi dùng làm relation label
sortablesortHỗ trợ sắp xếp tùy chỉnh
createdBytrueTự động thêm field createdBy
updatedBytrueTự động thêm field updatedBy
loggingtrueGhi log thay đổi
sharedtrueCollection dùng chung giữa các data source

Field ẩn (hidden)

Hai field có hidden: true sẽ bị desensitize() loại ra khỏi response:

  • password — mật khẩu đã hash
  • resetToken — token reset password

Điều này đảm bảo dù admin gọi users:list hay users:get, các field nhạy cảm không bao giờ xuất hiện trong response.

Mở rộng bảng systemSettings

Plugin sử dụng extendCollection để thêm 2 field boolean vào bảng systemSettings có sẵn:

FieldTypeMặc địnhMô tả
enableEditProfilebooleantrueCho phép user tự sửa profile qua updateProfile. Khi false, server trả 403
enableChangePasswordbooleantrueCho phép user tự đổi mật khẩu. Dùng bởi client để ẩn/hiện form đổi mật khẩu

Hai field này được quản lý qua API users:getSystemSettingsusers:updateSystemSettings.

Auto-inject createdBy/updatedBy cho collection khác

Khi bất kỳ collection nào trong hệ thống được định nghĩa với createdBy: true hoặc updatedBy: true, plugin tự động thêm:

Field injectTypeTargetHành vi
createdByIdcontext (bigInt)Lấy từ state.currentUser.id, chỉ ghi khi tạo (createOnly)
createdBybelongsTousersRelation đến users, foreignKey = createdById, label = displayname
updatedByIdcontext (bigInt)Lấy từ state.currentUser.id, cập nhật mỗi lần sửa
updatedBybelongsTousersRelation đến users, foreignKey = updatedById, label = displayname

Tất cả field inject đều có index: true để tối ưu query.