backend/generate/database/mongo/2025100900000002_role.up.txt

22 lines
704 B
Plaintext
Raw Normal View History

2025-11-14 14:40:56 +00:00
// 1. 唯一索引:角色 UID 必須唯一
2025-11-12 08:17:23 +00:00
db.role.createIndex({"uid": 1}, {unique: true});
2025-11-14 14:40:56 +00:00
// 2. 複合唯一索引:同一個 Client 下角色名稱必須唯一
2025-11-12 08:17:23 +00:00
db.role.createIndex({"client_id": 1, "name": 1}, {unique: true});
2025-11-14 14:40:56 +00:00
// 3. 查詢索引:按 Client ID 查詢
2025-11-12 08:17:23 +00:00
db.role.createIndex({"client_id": 1});
2025-11-14 14:40:56 +00:00
// 4. 查詢索引:按狀態查詢
2025-11-12 08:17:23 +00:00
db.role.createIndex({"status": 1});
2025-11-14 14:40:56 +00:00
// 5. 複合索引:按 Client ID 和狀態查詢(常用組合)
2025-11-12 08:17:23 +00:00
db.role.createIndex({"client_id": 1, "status": 1});
2025-11-14 14:40:56 +00:00
// 6. 時間戳索引:用於排序和時間範圍查詢
2025-11-12 08:17:23 +00:00
db.role.createIndex({"create_time": 1});
2025-11-14 14:40:56 +00:00
// 7. 時間戳索引:用於更新時間排序
2025-11-12 08:17:23 +00:00
db.role.createIndex({"update_time": -1});