opencode-metis 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/dist/cli.cjs +63 -0
- package/dist/mcp-server.cjs +51 -0
- package/dist/plugin.cjs +4 -0
- package/dist/worker.cjs +224 -0
- package/opencode/agent/the-analyst/feature-prioritization.md +66 -0
- package/opencode/agent/the-analyst/market-research.md +77 -0
- package/opencode/agent/the-analyst/project-coordination.md +81 -0
- package/opencode/agent/the-analyst/requirements-analysis.md +77 -0
- package/opencode/agent/the-architect/compatibility-review.md +138 -0
- package/opencode/agent/the-architect/complexity-review.md +137 -0
- package/opencode/agent/the-architect/quality-review.md +67 -0
- package/opencode/agent/the-architect/security-review.md +127 -0
- package/opencode/agent/the-architect/system-architecture.md +119 -0
- package/opencode/agent/the-architect/system-documentation.md +83 -0
- package/opencode/agent/the-architect/technology-research.md +85 -0
- package/opencode/agent/the-chief.md +79 -0
- package/opencode/agent/the-designer/accessibility-implementation.md +101 -0
- package/opencode/agent/the-designer/design-foundation.md +74 -0
- package/opencode/agent/the-designer/interaction-architecture.md +75 -0
- package/opencode/agent/the-designer/user-research.md +70 -0
- package/opencode/agent/the-meta-agent.md +155 -0
- package/opencode/agent/the-platform-engineer/ci-cd-pipelines.md +109 -0
- package/opencode/agent/the-platform-engineer/containerization.md +106 -0
- package/opencode/agent/the-platform-engineer/data-architecture.md +81 -0
- package/opencode/agent/the-platform-engineer/dependency-review.md +144 -0
- package/opencode/agent/the-platform-engineer/deployment-automation.md +81 -0
- package/opencode/agent/the-platform-engineer/infrastructure-as-code.md +107 -0
- package/opencode/agent/the-platform-engineer/performance-tuning.md +82 -0
- package/opencode/agent/the-platform-engineer/pipeline-engineering.md +81 -0
- package/opencode/agent/the-platform-engineer/production-monitoring.md +105 -0
- package/opencode/agent/the-qa-engineer/exploratory-testing.md +66 -0
- package/opencode/agent/the-qa-engineer/performance-testing.md +81 -0
- package/opencode/agent/the-qa-engineer/quality-assurance.md +77 -0
- package/opencode/agent/the-qa-engineer/test-execution.md +66 -0
- package/opencode/agent/the-software-engineer/api-development.md +78 -0
- package/opencode/agent/the-software-engineer/component-development.md +79 -0
- package/opencode/agent/the-software-engineer/concurrency-review.md +141 -0
- package/opencode/agent/the-software-engineer/domain-modeling.md +66 -0
- package/opencode/agent/the-software-engineer/performance-optimization.md +113 -0
- package/opencode/command/analyze.md +149 -0
- package/opencode/command/constitution.md +178 -0
- package/opencode/command/debug.md +194 -0
- package/opencode/command/document.md +178 -0
- package/opencode/command/implement.md +225 -0
- package/opencode/command/refactor.md +207 -0
- package/opencode/command/review.md +229 -0
- package/opencode/command/simplify.md +267 -0
- package/opencode/command/specify.md +191 -0
- package/opencode/command/validate.md +224 -0
- package/opencode/skill/accessibility-design/SKILL.md +566 -0
- package/opencode/skill/accessibility-design/checklists/wcag-checklist.md +435 -0
- package/opencode/skill/agent-coordination/SKILL.md +224 -0
- package/opencode/skill/api-contract-design/SKILL.md +550 -0
- package/opencode/skill/api-contract-design/templates/graphql-schema-template.md +818 -0
- package/opencode/skill/api-contract-design/templates/rest-api-template.md +417 -0
- package/opencode/skill/architecture-design/SKILL.md +160 -0
- package/opencode/skill/architecture-design/examples/architecture-examples.md +170 -0
- package/opencode/skill/architecture-design/template.md +749 -0
- package/opencode/skill/architecture-design/validation.md +99 -0
- package/opencode/skill/architecture-selection/SKILL.md +522 -0
- package/opencode/skill/architecture-selection/examples/adrs/001-example-adr.md +71 -0
- package/opencode/skill/architecture-selection/examples/architecture-patterns.md +239 -0
- package/opencode/skill/bug-diagnosis/SKILL.md +235 -0
- package/opencode/skill/code-quality-review/SKILL.md +337 -0
- package/opencode/skill/code-quality-review/examples/anti-patterns.md +629 -0
- package/opencode/skill/code-quality-review/reference.md +322 -0
- package/opencode/skill/code-review/SKILL.md +363 -0
- package/opencode/skill/code-review/reference.md +450 -0
- package/opencode/skill/codebase-analysis/SKILL.md +139 -0
- package/opencode/skill/codebase-navigation/SKILL.md +227 -0
- package/opencode/skill/codebase-navigation/examples/exploration-patterns.md +263 -0
- package/opencode/skill/coding-conventions/SKILL.md +178 -0
- package/opencode/skill/coding-conventions/checklists/accessibility-checklist.md +176 -0
- package/opencode/skill/coding-conventions/checklists/performance-checklist.md +154 -0
- package/opencode/skill/coding-conventions/checklists/security-checklist.md +127 -0
- package/opencode/skill/constitution-validation/SKILL.md +315 -0
- package/opencode/skill/constitution-validation/examples/CONSTITUTION.md +202 -0
- package/opencode/skill/constitution-validation/reference/rule-patterns.md +328 -0
- package/opencode/skill/constitution-validation/template.md +115 -0
- package/opencode/skill/context-preservation/SKILL.md +445 -0
- package/opencode/skill/data-modeling/SKILL.md +385 -0
- package/opencode/skill/data-modeling/templates/schema-design-template.md +268 -0
- package/opencode/skill/deployment-pipeline-design/SKILL.md +579 -0
- package/opencode/skill/deployment-pipeline-design/templates/pipeline-template.md +633 -0
- package/opencode/skill/documentation-extraction/SKILL.md +259 -0
- package/opencode/skill/documentation-sync/SKILL.md +431 -0
- package/opencode/skill/domain-driven-design/SKILL.md +509 -0
- package/opencode/skill/domain-driven-design/examples/ddd-patterns.md +688 -0
- package/opencode/skill/domain-driven-design/reference.md +465 -0
- package/opencode/skill/drift-detection/SKILL.md +383 -0
- package/opencode/skill/drift-detection/reference.md +340 -0
- package/opencode/skill/error-recovery/SKILL.md +162 -0
- package/opencode/skill/error-recovery/examples/error-patterns.md +484 -0
- package/opencode/skill/feature-prioritization/SKILL.md +419 -0
- package/opencode/skill/feature-prioritization/examples/rice-template.md +139 -0
- package/opencode/skill/feature-prioritization/reference.md +256 -0
- package/opencode/skill/git-workflow/SKILL.md +453 -0
- package/opencode/skill/implementation-planning/SKILL.md +215 -0
- package/opencode/skill/implementation-planning/examples/phase-examples.md +217 -0
- package/opencode/skill/implementation-planning/template.md +220 -0
- package/opencode/skill/implementation-planning/validation.md +88 -0
- package/opencode/skill/implementation-verification/SKILL.md +272 -0
- package/opencode/skill/knowledge-capture/SKILL.md +265 -0
- package/opencode/skill/knowledge-capture/reference/knowledge-capture.md +402 -0
- package/opencode/skill/knowledge-capture/reference.md +444 -0
- package/opencode/skill/knowledge-capture/templates/domain-template.md +325 -0
- package/opencode/skill/knowledge-capture/templates/interface-template.md +255 -0
- package/opencode/skill/knowledge-capture/templates/pattern-template.md +144 -0
- package/opencode/skill/observability-design/SKILL.md +291 -0
- package/opencode/skill/observability-design/references/monitoring-patterns.md +461 -0
- package/opencode/skill/pattern-detection/SKILL.md +171 -0
- package/opencode/skill/pattern-detection/examples/common-patterns.md +359 -0
- package/opencode/skill/performance-analysis/SKILL.md +266 -0
- package/opencode/skill/performance-analysis/references/profiling-tools.md +499 -0
- package/opencode/skill/requirements-analysis/SKILL.md +139 -0
- package/opencode/skill/requirements-analysis/examples/good-prd.md +66 -0
- package/opencode/skill/requirements-analysis/template.md +177 -0
- package/opencode/skill/requirements-analysis/validation.md +69 -0
- package/opencode/skill/requirements-elicitation/SKILL.md +518 -0
- package/opencode/skill/requirements-elicitation/examples/interview-questions.md +226 -0
- package/opencode/skill/requirements-elicitation/examples/user-stories.md +414 -0
- package/opencode/skill/safe-refactoring/SKILL.md +312 -0
- package/opencode/skill/safe-refactoring/reference/code-smells.md +347 -0
- package/opencode/skill/security-assessment/SKILL.md +421 -0
- package/opencode/skill/security-assessment/checklists/security-review-checklist.md +285 -0
- package/opencode/skill/specification-management/SKILL.md +143 -0
- package/opencode/skill/specification-management/readme-template.md +32 -0
- package/opencode/skill/specification-management/reference.md +115 -0
- package/opencode/skill/specification-management/spec.py +229 -0
- package/opencode/skill/specification-validation/SKILL.md +397 -0
- package/opencode/skill/specification-validation/reference/3cs-framework.md +306 -0
- package/opencode/skill/specification-validation/reference/ambiguity-detection.md +132 -0
- package/opencode/skill/specification-validation/reference/constitution-validation.md +301 -0
- package/opencode/skill/specification-validation/reference/drift-detection.md +383 -0
- package/opencode/skill/task-delegation/SKILL.md +607 -0
- package/opencode/skill/task-delegation/examples/file-coordination.md +495 -0
- package/opencode/skill/task-delegation/examples/parallel-research.md +337 -0
- package/opencode/skill/task-delegation/examples/sequential-build.md +504 -0
- package/opencode/skill/task-delegation/reference.md +825 -0
- package/opencode/skill/tech-stack-detection/SKILL.md +89 -0
- package/opencode/skill/tech-stack-detection/references/framework-signatures.md +598 -0
- package/opencode/skill/technical-writing/SKILL.md +190 -0
- package/opencode/skill/technical-writing/templates/adr-template.md +205 -0
- package/opencode/skill/technical-writing/templates/system-doc-template.md +380 -0
- package/opencode/skill/test-design/SKILL.md +464 -0
- package/opencode/skill/test-design/examples/test-pyramid.md +724 -0
- package/opencode/skill/testing/SKILL.md +213 -0
- package/opencode/skill/testing/examples/test-pyramid.md +724 -0
- package/opencode/skill/user-insight-synthesis/SKILL.md +576 -0
- package/opencode/skill/user-insight-synthesis/templates/research-plan-template.md +217 -0
- package/opencode/skill/user-research/SKILL.md +508 -0
- package/opencode/skill/user-research/examples/interview-questions.md +265 -0
- package/opencode/skill/user-research/examples/personas.md +267 -0
- package/opencode/skill/vibe-security/SKILL.md +654 -0
- package/package.json +45 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: data-modeling
|
|
3
|
+
description: "Schema design, entity relationships, normalization, and database patterns. Use when designing database schemas, modeling domain entities, deciding between normalized and denormalized structures, choosing between relational and NoSQL approaches, or planning schema migrations."
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: opencode
|
|
6
|
+
metadata:
|
|
7
|
+
category: development
|
|
8
|
+
version: "1.0"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Data Modeling
|
|
12
|
+
|
|
13
|
+
Roleplay as a data modeling specialist designing schemas that encode business rules, enforce integrity, and enable performance optimization.
|
|
14
|
+
|
|
15
|
+
DataModeling {
|
|
16
|
+
Activation {
|
|
17
|
+
When designing new database schemas from domain requirements
|
|
18
|
+
When analyzing existing schemas for optimization opportunities
|
|
19
|
+
When deciding between normalized and denormalized structures
|
|
20
|
+
When choosing appropriate data stores (relational vs NoSQL)
|
|
21
|
+
When planning schema evolution and migration strategies
|
|
22
|
+
When modeling complex entity relationships
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Constraints {
|
|
26
|
+
Data models outlive applications
|
|
27
|
+
A well-designed schema encodes business rules and enforces integrity
|
|
28
|
+
Correct first, then optimize for access patterns
|
|
29
|
+
Maintain data integrity during optimization
|
|
30
|
+
Model the domain first, then optimize for access patterns
|
|
31
|
+
Use surrogate keys for primary keys; natural keys as unique constraints
|
|
32
|
+
Normalize to 3NF for OLTP; denormalize deliberately for read-heavy loads
|
|
33
|
+
Version control all schema changes as migration scripts
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
EntityRelationshipModeling {
|
|
37
|
+
IdentifyingEntities {
|
|
38
|
+
Entities represent distinct business concepts that have identity and lifecycle
|
|
39
|
+
|
|
40
|
+
IdentificationChecklist:
|
|
41
|
+
- Has unique identity across the system
|
|
42
|
+
- Has attributes that describe it
|
|
43
|
+
- Participates in relationships with other entities
|
|
44
|
+
- Has a meaningful lifecycle (created, modified, archived)
|
|
45
|
+
- Would be stored and retrieved independently
|
|
46
|
+
|
|
47
|
+
CommonEntityPatterns:
|
|
48
|
+
- Core domain objects (User, Product, Order)
|
|
49
|
+
- Reference/lookup data (Country, Status, Category)
|
|
50
|
+
- Transactional records (Payment, LogEntry, Event)
|
|
51
|
+
- Associative entities (OrderItem, Enrollment, Permission)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
RelationshipTypes {
|
|
55
|
+
| Type | Notation | Example | Implementation |
|
|
56
|
+
|------|----------|---------|----------------|
|
|
57
|
+
| One-to-One | 1:1 | User - Profile | FK with unique constraint or same table |
|
|
58
|
+
| One-to-Many | 1:N | Customer - Orders | FK on the "many" side |
|
|
59
|
+
| Many-to-Many | M:N | Students - Courses | Junction/bridge table |
|
|
60
|
+
|
|
61
|
+
Considerations:
|
|
62
|
+
- Cardinality: minimum and maximum on each side
|
|
63
|
+
- Optionality: required vs optional participation
|
|
64
|
+
- Direction: unidirectional vs bidirectional navigation
|
|
65
|
+
- Cascade behavior: what happens on delete/update
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
AttributeAnalysis {
|
|
69
|
+
AttributeTypes:
|
|
70
|
+
- Simple: single atomic value (name, price)
|
|
71
|
+
- Composite: structured value (address = street + city + postal)
|
|
72
|
+
- Derived: calculated from other attributes (age from birthdate)
|
|
73
|
+
- Multi-valued: repeating values (phone numbers, tags)
|
|
74
|
+
|
|
75
|
+
KeyTypes:
|
|
76
|
+
- Natural key: business-meaningful identifier (SSN, ISBN)
|
|
77
|
+
- Surrogate key: system-generated identifier (UUID, auto-increment)
|
|
78
|
+
- Composite key: multiple columns forming identity
|
|
79
|
+
- Candidate key: any attribute(s) that could serve as primary key
|
|
80
|
+
|
|
81
|
+
BestPractice: Prefer surrogate keys for primary keys; use natural keys as unique constraints
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Normalization {
|
|
86
|
+
NormalFormsProgression {
|
|
87
|
+
Each normal form builds on the previous
|
|
88
|
+
Normalize until requirements dictate otherwise
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
FirstNormalForm {
|
|
92
|
+
Rule: Eliminate repeating groups; each cell contains atomic values
|
|
93
|
+
|
|
94
|
+
ViolationExample:
|
|
95
|
+
```
|
|
96
|
+
Order(id, customer, items: "widget,gadget,thing")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Resolution:
|
|
100
|
+
```
|
|
101
|
+
Order(id, customer)
|
|
102
|
+
OrderItem(order_id, item_name)
|
|
103
|
+
```
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
SecondNormalForm {
|
|
107
|
+
Rule: Remove partial dependencies on composite keys
|
|
108
|
+
|
|
109
|
+
ViolationExample:
|
|
110
|
+
```
|
|
111
|
+
OrderItem(order_id, product_id, product_name, quantity)
|
|
112
|
+
^-- depends only on product_id
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Resolution:
|
|
116
|
+
```
|
|
117
|
+
OrderItem(order_id, product_id, quantity)
|
|
118
|
+
Product(product_id, product_name)
|
|
119
|
+
```
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
ThirdNormalForm {
|
|
123
|
+
Rule: Remove transitive dependencies; non-key columns depend only on the key
|
|
124
|
+
|
|
125
|
+
ViolationExample:
|
|
126
|
+
```
|
|
127
|
+
Employee(id, department_id, department_name)
|
|
128
|
+
^-- depends on department_id, not employee id
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Resolution:
|
|
132
|
+
```
|
|
133
|
+
Employee(id, department_id)
|
|
134
|
+
Department(id, name)
|
|
135
|
+
```
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
BoyceCoodNormalForm {
|
|
139
|
+
Rule: Every determinant is a candidate key
|
|
140
|
+
|
|
141
|
+
ViolationExample:
|
|
142
|
+
```
|
|
143
|
+
CourseOffering(student, course, instructor)
|
|
144
|
+
-- Constraint: each instructor teaches only one course
|
|
145
|
+
-- instructor -> course (but instructor is not a candidate key)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Resolution:
|
|
149
|
+
```
|
|
150
|
+
InstructorCourse(instructor, course) -- instructor is key
|
|
151
|
+
Enrollment(student, instructor) -- references instructor
|
|
152
|
+
```
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
WhenToStopNormalizing {
|
|
156
|
+
Stop at 3NF for most OLTP systems
|
|
157
|
+
Consider BCNF when:
|
|
158
|
+
- Update anomalies cause data corruption
|
|
159
|
+
- Data integrity is paramount
|
|
160
|
+
- Write frequency is high
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
DenormalizationStrategies {
|
|
165
|
+
Principle: Denormalize intentionally for read performance, not out of laziness
|
|
166
|
+
|
|
167
|
+
CalculatedColumns {
|
|
168
|
+
Store derived values to avoid repeated computation
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
Order
|
|
172
|
+
- subtotal (calculated once on item changes)
|
|
173
|
+
- tax_amount (calculated once)
|
|
174
|
+
- total (calculated once)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
TradeOff: Faster reads, more complex writes, potential consistency issues
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
MaterializedRelationships {
|
|
181
|
+
Embed frequently-accessed related data
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
Post
|
|
185
|
+
- author_id
|
|
186
|
+
- author_name (copied from User.name)
|
|
187
|
+
- author_avatar_url (copied from User.avatar_url)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
TradeOff: Eliminates joins, requires synchronization on source changes
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
AggregationTables {
|
|
194
|
+
Pre-compute summaries for reporting
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
DailySales
|
|
198
|
+
- date
|
|
199
|
+
- product_id
|
|
200
|
+
- units_sold (sum)
|
|
201
|
+
- revenue (sum)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
TradeOff: Fast analytics, storage overhead, stale until refreshed
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
DecisionMatrix {
|
|
208
|
+
| Factor | Normalize | Denormalize |
|
|
209
|
+
|--------|-----------|-------------|
|
|
210
|
+
| Write frequency | High | Low |
|
|
211
|
+
| Read frequency | Low | High |
|
|
212
|
+
| Data consistency | Critical | Eventual OK |
|
|
213
|
+
| Query complexity | Simple | Complex joins |
|
|
214
|
+
| Data size | Small | Large |
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
NoSQLPatterns {
|
|
219
|
+
DocumentStores {
|
|
220
|
+
Target: MongoDB, DynamoDB
|
|
221
|
+
|
|
222
|
+
EmbeddingPattern {
|
|
223
|
+
Embed related data that is read together and has 1:few relationship
|
|
224
|
+
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"order_id": "123",
|
|
228
|
+
"customer": {
|
|
229
|
+
"id": "456",
|
|
230
|
+
"name": "Jane Doe",
|
|
231
|
+
"email": "jane@example.com"
|
|
232
|
+
},
|
|
233
|
+
"items": [
|
|
234
|
+
{"product_id": "A1", "name": "Widget", "quantity": 2}
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
ReferencingPattern {
|
|
241
|
+
Reference related data when it changes independently or is shared
|
|
242
|
+
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"order_id": "123",
|
|
246
|
+
"customer_id": "456",
|
|
247
|
+
"item_ids": ["A1", "B2"]
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
HybridPattern {
|
|
253
|
+
Embed summary data, reference for full details
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"order_id": "123",
|
|
258
|
+
"customer_summary": {
|
|
259
|
+
"id": "456",
|
|
260
|
+
"name": "Jane Doe"
|
|
261
|
+
},
|
|
262
|
+
"items": [
|
|
263
|
+
{"product_id": "A1", "name": "Widget", "quantity": 2}
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
KeyValueStores {
|
|
271
|
+
AccessPatternDesign: Design keys around query patterns
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
USER:{user_id} -> user data
|
|
275
|
+
USER:{user_id}:ORDERS -> list of order ids
|
|
276
|
+
ORDER:{order_id} -> order data
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
CompositeKeys: Combine entity type with identifiers for namespacing
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
WideColumnStores {
|
|
283
|
+
Target: Cassandra, HBase
|
|
284
|
+
|
|
285
|
+
PartitionKeyDesign: Choose partition keys for even distribution and access locality
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
Primary Key: (user_id, order_date)
|
|
289
|
+
^-- partition key (distribution)
|
|
290
|
+
^-- clustering column (ordering)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Avoid:
|
|
294
|
+
- High-cardinality partition keys causing hot spots
|
|
295
|
+
- Large partitions exceeding recommended sizes
|
|
296
|
+
- Scatter-gather queries across partitions
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
GraphDatabases {
|
|
300
|
+
NodeAndRelationshipDesign:
|
|
301
|
+
- Nodes: entities with properties
|
|
302
|
+
- Relationships: named, directed, with properties
|
|
303
|
+
- Labels: categorize nodes for efficient traversal
|
|
304
|
+
|
|
305
|
+
```
|
|
306
|
+
(User)-[:PURCHASED {date, amount}]->(Product)
|
|
307
|
+
(User)-[:FOLLOWS]->(User)
|
|
308
|
+
(Product)-[:BELONGS_TO]->(Category)
|
|
309
|
+
```
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
SchemaEvolutionStrategies {
|
|
314
|
+
AdditiveChanges {
|
|
315
|
+
Safe changes:
|
|
316
|
+
- Add new nullable columns
|
|
317
|
+
- Add new tables
|
|
318
|
+
- Add new indexes
|
|
319
|
+
- Add new optional fields (NoSQL)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
BreakingChanges {
|
|
323
|
+
Require migration:
|
|
324
|
+
- Remove columns/tables
|
|
325
|
+
- Rename columns/tables
|
|
326
|
+
- Change data types
|
|
327
|
+
- Add non-nullable columns without defaults
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
MigrationPatterns {
|
|
331
|
+
ExpandContractPattern {
|
|
332
|
+
1. Add new column alongside old
|
|
333
|
+
2. Backfill new column from old
|
|
334
|
+
3. Update application to use new column
|
|
335
|
+
4. Remove old column
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
BlueGreenSchema {
|
|
339
|
+
1. Create new version of schema
|
|
340
|
+
2. Dual-write to both versions
|
|
341
|
+
3. Migrate reads to new version
|
|
342
|
+
4. Drop old version
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
VersionedDocuments {
|
|
346
|
+
For NoSQL:
|
|
347
|
+
```json
|
|
348
|
+
{
|
|
349
|
+
"_schema_version": 2,
|
|
350
|
+
"name": "Jane",
|
|
351
|
+
"email": "jane@example.com"
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Handle multiple versions in application code during transition
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
BestPractices {
|
|
361
|
+
- Model the domain first, then optimize for access patterns
|
|
362
|
+
- Use surrogate keys for primary keys; natural keys as unique constraints
|
|
363
|
+
- Normalize to 3NF for OLTP; denormalize deliberately for read-heavy loads
|
|
364
|
+
- Document all foreign key relationships and cascade behaviors
|
|
365
|
+
- Version control all schema changes as migration scripts
|
|
366
|
+
- Test migrations on production-like data volumes
|
|
367
|
+
- Consider query patterns when designing NoSQL schemas
|
|
368
|
+
- Plan for schema evolution from day one
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
AntiPatterns {
|
|
372
|
+
- Designing schemas around UI forms instead of domain concepts
|
|
373
|
+
- Using generic columns (field1, field2, field3)
|
|
374
|
+
- Entity-Attribute-Value (EAV) for structured data
|
|
375
|
+
- Storing comma-separated values in single columns
|
|
376
|
+
- Circular foreign key dependencies
|
|
377
|
+
- Missing indexes on foreign key columns
|
|
378
|
+
- Hard-deleting data without soft-delete consideration
|
|
379
|
+
- Ignoring temporal aspects (effective dates, audit trails)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
## References
|
|
384
|
+
|
|
385
|
+
- [templates/schema-design-template.md](templates/schema-design-template.md) - Structured template for schema documentation
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Schema Design Template
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Structured documentation for database schema designs. Use this template when designing new schemas, documenting existing ones, or planning migrations. Ensures consistent coverage of entities, relationships, constraints, and evolution strategy.
|
|
6
|
+
|
|
7
|
+
## Template
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
# Schema: [Schema Name]
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
**Domain:** [Business domain this schema serves]
|
|
15
|
+
**Data Store:** [PostgreSQL | MySQL | MongoDB | DynamoDB | etc.]
|
|
16
|
+
**Primary Access Patterns:** [List main query patterns]
|
|
17
|
+
**Consistency Requirements:** [Strong | Eventual | Mixed]
|
|
18
|
+
|
|
19
|
+
## Entities
|
|
20
|
+
|
|
21
|
+
### [Entity Name]
|
|
22
|
+
|
|
23
|
+
**Purpose:** [What this entity represents in the domain]
|
|
24
|
+
|
|
25
|
+
**Table/Collection:** `[table_name]`
|
|
26
|
+
|
|
27
|
+
| Column | Type | Constraints | Description |
|
|
28
|
+
|--------|------|-------------|-------------|
|
|
29
|
+
| id | UUID | PK | Unique identifier |
|
|
30
|
+
| [column] | [type] | [constraints] | [description] |
|
|
31
|
+
|
|
32
|
+
**Indexes:**
|
|
33
|
+
- `idx_[name]` on ([columns]) - [purpose]
|
|
34
|
+
|
|
35
|
+
**Constraints:**
|
|
36
|
+
- [constraint description]
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
[Repeat for each entity]
|
|
41
|
+
|
|
42
|
+
## Relationships
|
|
43
|
+
|
|
44
|
+
### [Relationship Name]
|
|
45
|
+
|
|
46
|
+
**Type:** [1:1 | 1:N | M:N]
|
|
47
|
+
**From:** [Source Entity]
|
|
48
|
+
**To:** [Target Entity]
|
|
49
|
+
**Implementation:** [FK location or junction table]
|
|
50
|
+
**Cascade Behavior:** [ON DELETE/UPDATE actions]
|
|
51
|
+
**Business Rule:** [Why this relationship exists]
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
[Repeat for each relationship]
|
|
56
|
+
|
|
57
|
+
## Normalization Analysis
|
|
58
|
+
|
|
59
|
+
### Current Normal Form: [1NF | 2NF | 3NF | BCNF]
|
|
60
|
+
|
|
61
|
+
**Deliberate Denormalizations:**
|
|
62
|
+
|
|
63
|
+
| Location | Pattern | Justification |
|
|
64
|
+
|----------|---------|---------------|
|
|
65
|
+
| [table.column] | [calculated | embedded | aggregated] | [performance reason] |
|
|
66
|
+
|
|
67
|
+
## Access Patterns
|
|
68
|
+
|
|
69
|
+
### [Pattern Name]
|
|
70
|
+
|
|
71
|
+
**Query:** [Description of what is being retrieved]
|
|
72
|
+
**Frequency:** [Requests per second / day]
|
|
73
|
+
**Latency Requirement:** [Target response time]
|
|
74
|
+
**Supporting Indexes:** [Index names used]
|
|
75
|
+
|
|
76
|
+
Example Query:
|
|
77
|
+
```sql
|
|
78
|
+
[Sample SQL or query]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
[Repeat for each major access pattern]
|
|
84
|
+
|
|
85
|
+
## Data Lifecycle
|
|
86
|
+
|
|
87
|
+
### Retention Policy
|
|
88
|
+
|
|
89
|
+
| Entity | Retention Period | Archive Strategy | Deletion Strategy |
|
|
90
|
+
|--------|-----------------|------------------|-------------------|
|
|
91
|
+
| [entity] | [period] | [approach] | [soft/hard delete] |
|
|
92
|
+
|
|
93
|
+
### Audit Requirements
|
|
94
|
+
|
|
95
|
+
- [What changes are tracked]
|
|
96
|
+
- [Where audit logs are stored]
|
|
97
|
+
- [Retention of audit data]
|
|
98
|
+
|
|
99
|
+
## Migration Plan
|
|
100
|
+
|
|
101
|
+
### Version: [version number]
|
|
102
|
+
|
|
103
|
+
**Changes from Previous:**
|
|
104
|
+
- [Change 1]
|
|
105
|
+
- [Change 2]
|
|
106
|
+
|
|
107
|
+
**Migration Steps:**
|
|
108
|
+
1. [Step with rollback procedure]
|
|
109
|
+
2. [Step with rollback procedure]
|
|
110
|
+
|
|
111
|
+
**Rollback Procedure:**
|
|
112
|
+
1. [Step to undo migration]
|
|
113
|
+
|
|
114
|
+
**Data Backfill Requirements:**
|
|
115
|
+
- [What data needs to be populated]
|
|
116
|
+
- [Estimated duration]
|
|
117
|
+
|
|
118
|
+
## Performance Considerations
|
|
119
|
+
|
|
120
|
+
### Expected Data Volumes
|
|
121
|
+
|
|
122
|
+
| Entity | Initial | 1 Year | 3 Years |
|
|
123
|
+
|--------|---------|--------|---------|
|
|
124
|
+
| [entity] | [count] | [count] | [count] |
|
|
125
|
+
|
|
126
|
+
### Partitioning Strategy
|
|
127
|
+
|
|
128
|
+
[Describe partitioning approach if applicable]
|
|
129
|
+
|
|
130
|
+
### Caching Strategy
|
|
131
|
+
|
|
132
|
+
[Describe what data is cached and where]
|
|
133
|
+
|
|
134
|
+
## Security
|
|
135
|
+
|
|
136
|
+
### Sensitive Data
|
|
137
|
+
|
|
138
|
+
| Column | Classification | Protection |
|
|
139
|
+
|--------|---------------|------------|
|
|
140
|
+
| [table.column] | [PII | Financial | PHI] | [encryption | masking | access control] |
|
|
141
|
+
|
|
142
|
+
### Access Control
|
|
143
|
+
|
|
144
|
+
[Row-level security, column-level permissions, etc.]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Usage Instructions
|
|
148
|
+
|
|
149
|
+
1. Copy the template above
|
|
150
|
+
2. Fill in each section based on your domain requirements
|
|
151
|
+
3. Remove sections that do not apply to your data store type
|
|
152
|
+
4. Add custom sections for domain-specific concerns
|
|
153
|
+
5. Keep this document in version control alongside migration scripts
|
|
154
|
+
6. Update when schema evolves
|
|
155
|
+
|
|
156
|
+
## Section Guidelines
|
|
157
|
+
|
|
158
|
+
### Entities Section
|
|
159
|
+
- List all entities, even lookup/reference tables
|
|
160
|
+
- Include all columns with accurate types
|
|
161
|
+
- Document all constraints including CHECK constraints
|
|
162
|
+
- Note default values and auto-generation rules
|
|
163
|
+
|
|
164
|
+
### Relationships Section
|
|
165
|
+
- Capture business meaning, not just technical linkage
|
|
166
|
+
- Document cascade behaviors explicitly
|
|
167
|
+
- Note any orphan-prevention strategies
|
|
168
|
+
|
|
169
|
+
### Access Patterns Section
|
|
170
|
+
- Focus on the 80% use cases
|
|
171
|
+
- Include realistic query examples
|
|
172
|
+
- Note if patterns require denormalization
|
|
173
|
+
|
|
174
|
+
### Migration Plan Section
|
|
175
|
+
- Always include rollback procedures
|
|
176
|
+
- Estimate data backfill times
|
|
177
|
+
- Note any downtime requirements
|
|
178
|
+
|
|
179
|
+
## Examples
|
|
180
|
+
|
|
181
|
+
### Simple Entity Definition
|
|
182
|
+
|
|
183
|
+
```markdown
|
|
184
|
+
### User
|
|
185
|
+
|
|
186
|
+
**Purpose:** Registered users of the application
|
|
187
|
+
|
|
188
|
+
**Table:** `users`
|
|
189
|
+
|
|
190
|
+
| Column | Type | Constraints | Description |
|
|
191
|
+
|--------|------|-------------|-------------|
|
|
192
|
+
| id | UUID | PK, DEFAULT gen_random_uuid() | Unique identifier |
|
|
193
|
+
| email | VARCHAR(255) | NOT NULL, UNIQUE | Login email address |
|
|
194
|
+
| password_hash | VARCHAR(255) | NOT NULL | Bcrypt hashed password |
|
|
195
|
+
| display_name | VARCHAR(100) | NOT NULL | Public display name |
|
|
196
|
+
| created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | Account creation time |
|
|
197
|
+
| updated_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | Last modification time |
|
|
198
|
+
| deleted_at | TIMESTAMP | NULL | Soft delete timestamp |
|
|
199
|
+
|
|
200
|
+
**Indexes:**
|
|
201
|
+
- `idx_users_email` on (email) - Login lookup
|
|
202
|
+
- `idx_users_deleted_at` on (deleted_at) WHERE deleted_at IS NULL - Active user queries
|
|
203
|
+
|
|
204
|
+
**Constraints:**
|
|
205
|
+
- Email must be valid format (CHECK constraint or application-level)
|
|
206
|
+
- Display name between 2-100 characters
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Relationship Definition
|
|
210
|
+
|
|
211
|
+
```markdown
|
|
212
|
+
### User Orders
|
|
213
|
+
|
|
214
|
+
**Type:** 1:N
|
|
215
|
+
**From:** User
|
|
216
|
+
**To:** Order
|
|
217
|
+
**Implementation:** `orders.user_id` references `users.id`
|
|
218
|
+
**Cascade Behavior:** ON DELETE RESTRICT (prevent user deletion with orders)
|
|
219
|
+
**Business Rule:** Every order must be placed by a registered user. Users may have zero or more orders.
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### NoSQL Variant
|
|
223
|
+
|
|
224
|
+
```markdown
|
|
225
|
+
### Order (Document)
|
|
226
|
+
|
|
227
|
+
**Purpose:** Customer purchase transactions
|
|
228
|
+
|
|
229
|
+
**Collection:** `orders`
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"_id": "ObjectId",
|
|
234
|
+
"order_number": "string (unique)",
|
|
235
|
+
"customer": {
|
|
236
|
+
"id": "string (reference)",
|
|
237
|
+
"name": "string (embedded snapshot)",
|
|
238
|
+
"email": "string (embedded snapshot)"
|
|
239
|
+
},
|
|
240
|
+
"items": [
|
|
241
|
+
{
|
|
242
|
+
"product_id": "string (reference)",
|
|
243
|
+
"name": "string (embedded)",
|
|
244
|
+
"quantity": "number",
|
|
245
|
+
"unit_price": "decimal"
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
"totals": {
|
|
249
|
+
"subtotal": "decimal",
|
|
250
|
+
"tax": "decimal",
|
|
251
|
+
"total": "decimal"
|
|
252
|
+
},
|
|
253
|
+
"status": "string (enum)",
|
|
254
|
+
"created_at": "date",
|
|
255
|
+
"updated_at": "date"
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Indexes:**
|
|
260
|
+
- `order_number_1` (unique) - Order lookup by number
|
|
261
|
+
- `customer.id_1` - Customer order history
|
|
262
|
+
- `status_1_created_at_-1` - Order status queries
|
|
263
|
+
|
|
264
|
+
**Embedding Rationale:**
|
|
265
|
+
- Customer name/email embedded as snapshot at order time (may differ from current)
|
|
266
|
+
- Items embedded because they belong exclusively to this order
|
|
267
|
+
- Product details embedded because price/name at purchase may differ from current
|
|
268
|
+
```
|