0cd1047b10
Run Tests / test (pull_request) Successful in 30s
repo 內 35/38 份既有 spec 都是舊版歸檔流程留下的原始 delta 內容(`## ADDED Requirements`,缺標題與 Purpose),openspec CLI 現版本嚴格驗證 (--strict)會報錯或警告。逐一補上: - 缺標題/Purpose 的 30 份:加上 `# <name> Specification` 標題 + 依內容 撰寫的 Purpose 段落,`## ADDED Requirements` 改回 `## Requirements` - compose-cloud-baseline、scheduler-container:已有標題與 Requirements,只補 Purpose 包裝 - provider-verification:已有標題與 Purpose,只需把 `## ADDED Requirements` 改回 `## Requirements` - admin-user-management、notification-email:各有一條 requirement 缺 SHALL/MUST 關鍵字(純敘述句或表格),補上規範用語,內容不變 `openspec validate --specs --strict`:38/38 全過(原本 4/38)。純文件 補齊,未變更任何 requirement 的實質內容或行為描述。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011LpcY9b7y9x4fusHBTXciQ
38 lines
1.4 KiB
Markdown
38 lines
1.4 KiB
Markdown
# db-index-optimization Specification
|
|
|
|
## Purpose
|
|
|
|
定義為加速常用查詢(未讀通知計數、教練課程列表)而新增的資料庫複合索引與單欄索引,避免這些高頻查詢隨資料量成長退化為 full table scan。
|
|
|
|
## Requirements
|
|
|
|
### Requirement: Notifications 表補複合索引
|
|
|
|
`notifications` 表 SHALL 新增 `[notifiable_type, notifiable_id, read_at]` 複合索引,以加速 `unreadNotifications()` 查詢。
|
|
|
|
#### Scenario: Migration 執行成功
|
|
|
|
- **WHEN** 執行 `php artisan migrate`
|
|
- **THEN** `notifications` 表上存在 `notifications_notifiable_read_at_index` 複合索引,`EXPLAIN` 結果不再為 full table scan
|
|
|
|
#### Scenario: 未讀通知查詢走索引
|
|
|
|
- **WHEN** 系統執行 `Notification::where('notifiable_type', User::class)->where('notifiable_id', $userId)->whereNull('read_at')->get()`
|
|
- **THEN** MySQL `EXPLAIN` 顯示使用複合索引,`type` 為 `ref` 而非 `ALL`
|
|
|
|
---
|
|
|
|
### Requirement: DivingOffers 表補 provider_id 索引
|
|
|
|
`diving_offers` 表 SHALL 新增 `provider_id` 單欄索引,以加速 Provider 課程列表查詢。
|
|
|
|
#### Scenario: Migration 執行成功
|
|
|
|
- **WHEN** 執行 `php artisan migrate`
|
|
- **THEN** `diving_offers` 表上存在 `provider_id` 索引
|
|
|
|
#### Scenario: Provider 課程列表查詢走索引
|
|
|
|
- **WHEN** 系統執行 `DivingOffer::where('provider_id', $providerId)->get()`
|
|
- **THEN** MySQL `EXPLAIN` 顯示使用 `provider_id` 索引,`type` 為 `ref`
|