Files
CICD/docs/db/schema-changelog.md
SpecialX e7c902e8e1
Some checks failed
CI / build-and-test (push) Failing after 1m31s
CI / deploy (push) Has been skipped
Module Update
2025-12-30 14:42:30 +08:00

40 lines
1.9 KiB
Markdown

# Database Schema Changelog
## v1.1.0 - Exam Structure & Performance Optimization
**Date:** 2025-12-29
**Migration ID:** `0001_flawless_texas_twister`
**Author:** Principal Database Architect
### 1. Summary
This release introduces support for hierarchical exam structures (Sectioning/Grouping) and optimizes database constraint naming for better compatibility with MySQL environments.
### 2. Changes
#### 2.1 Table: `exams`
* **Action**: `ADD COLUMN`
* **Field**: `structure` (JSON)
* **Reason**: To support nested exam layouts (e.g., "Part I: Listening", "Section A").
* *Architecture Note*: This JSON field is strictly for **Presentation Layer** ordering and grouping. The `exam_questions` table remains the **Source of Truth** for relational integrity and scoring logic.
* **Schema Definition**:
```typescript
type ExamStructure = Array<
| { type: 'group', title: string, children: ExamStructure }
| { type: 'question', questionId: string, score: number }
>
```
#### 2.2 Table: `questions_to_knowledge_points`
* **Action**: `RENAME FOREIGN KEY`
* **Details**:
* Old: `questions_to_knowledge_points_question_id_questions_id_fk` -> New: `q_kp_qid_fk`
* Old: `questions_to_knowledge_points_knowledge_point_id_knowledge_points_id_fk` -> New: `q_kp_kpid_fk`
* **Reason**: Previous names exceeded MySQL's 64-character identifier limit, causing potential migration failures in production environments.
### 3. Migration Strategy
* **Up**: Run standard Drizzle migration. The script includes `ALTER TABLE ... DROP FOREIGN KEY` followed by `ADD CONSTRAINT`.
* **Down**: Revert `structure` column. Note that FK names can be kept short as they are implementation details.
### 4. Impact Analysis
* **Performance**: Negligible. JSON parsing is done client-side or at application layer.
* **Data Integrity**: High. Existing data is unaffected. New `structure` field defaults to `NULL`.