Files
his/.qoder/rules/database.md

49 lines
2.1 KiB
Markdown

---
description: Database and Flyway migration rules for HealthLink-HIS
paths:
- "**/*.sql"
- "**/mapper/*.xml"
- "healthlink-his-server/**/resources/db/migration/**"
---
# Database and Migration Rules
## Iron Law 2: Flyway database migration
- All new tables or new fields require a Flyway migration script
- Path: `healthlink-his-application/src/main/resources/db/migration/`
- Naming: `V{version}__{description}.sql` (double underscore)
## Iron Law 17: Database iron laws
- **Query real database before modification** — confirm table structure, field constraints, indexes
- **No guessing SQL** — check table structure first
- **Verify after SQL modification** — use `EXPLAIN` or actual query to verify syntax
- **Check NOT NULL constraints** — verify `is_nullable` before INSERT/UPDATE
- **Check all related tables** — for JOIN queries, check all related table structures and foreign keys
## Iron Law 18: SQL migration restrictions
- Only `ALTER TABLE ADD COLUMN` allowed
- No `DROP COLUMN` or `RENAME COLUMN`
- New fields can only be appended, not deleted or renamed
## Database connection
- PostgreSQL 15+ at `192.168.110.252:15432`
- Database: `healthlink_his`
- Flyway is enabled in dev and runs on startup
- Migration conflicts will block server startup
## Full chain 6-ring analysis
For bugs/requirements involving database fields, follow the complete chain:
```
Frontend/Page → Controller → Service → Mapper → DB/SQL → Related modules
①Input ②Validate ③Business ④Persist ⑤Storage ⑥Linkage
```
| Ring | Check |
|------|-------|
| ① Input | Frontend has input entry (dialog, table row edit, form) |
| ② Validate | Controller parameter validation, @Valid, permission control |
| ③ Business | Service business logic, transaction boundaries, multiple Service implementation entries |
| ④ Persist | Mapper XML, DTO field mapping, type conversion |
| ⑤ Storage | Database table structure, indexes, NOT NULL constraints |
| ⑥ Linkage | Upstream (orders→nurse station), downstream (printing, billing, reports) synchronization |