@tinkcarlos/skillora 0.2.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/.claude/skills/.temp-skill-index.md +245 -0
- package/.claude/skills/SKILL.md +264 -0
- package/.claude/skills/api-scaffolding/SKILL.md +431 -0
- package/.claude/skills/api-scaffolding/agents/backend-architect.md +282 -0
- package/.claude/skills/api-scaffolding/agents/django-pro.md +144 -0
- package/.claude/skills/api-scaffolding/agents/fastapi-pro.md +156 -0
- package/.claude/skills/api-scaffolding/agents/graphql-architect.md +146 -0
- package/.claude/skills/api-scaffolding/skills/fastapi-templates/SKILL.md +171 -0
- package/.claude/skills/api-testing-observability/SKILL.md +583 -0
- package/.claude/skills/api-testing-observability/agents/api-documenter.md +146 -0
- package/.claude/skills/api-testing-observability/commands/api-mock.md +1320 -0
- package/.claude/skills/brainstorming/SKILL.md +283 -0
- package/.claude/skills/bug-fixing/SKILL.md +382 -0
- package/.claude/skills/bug-fixing/references/backend-guide.md +132 -0
- package/.claude/skills/bug-fixing/references/bug-guide.md +354 -0
- package/.claude/skills/bug-fixing/references/bug-record-template.md +134 -0
- package/.claude/skills/bug-fixing/references/bug-records.md +88 -0
- package/.claude/skills/bug-fixing/references/code-review-gate.md +81 -0
- package/.claude/skills/bug-fixing/references/common-bugs.md +140 -0
- package/.claude/skills/bug-fixing/references/complete-workflow.md +361 -0
- package/.claude/skills/bug-fixing/references/config-driven-fixes.md +136 -0
- package/.claude/skills/bug-fixing/references/context-isolation-protocol.md +268 -0
- package/.claude/skills/bug-fixing/references/cross-surface-regression.md +120 -0
- package/.claude/skills/bug-fixing/references/database-investigation.md +129 -0
- package/.claude/skills/bug-fixing/references/dependency-and-integrity-protocol.md +369 -0
- package/.claude/skills/bug-fixing/references/fix-completeness-checklist.md +239 -0
- package/.claude/skills/bug-fixing/references/frontend-guide.md +219 -0
- package/.claude/skills/bug-fixing/references/fullstack-joint-guide.md +123 -0
- package/.claude/skills/bug-fixing/references/functional-breakage.md +117 -0
- package/.claude/skills/bug-fixing/references/ide-lint-errors-guide.md +176 -0
- package/.claude/skills/bug-fixing/references/impact-analysis.md +511 -0
- package/.claude/skills/bug-fixing/references/investigation-checklist.md +263 -0
- package/.claude/skills/bug-fixing/references/knowledge-extraction-guide.md +531 -0
- package/.claude/skills/bug-fixing/references/knowledge-workflow.md +212 -0
- package/.claude/skills/bug-fixing/references/post-edit-quality-gate.md +30 -0
- package/.claude/skills/bug-fixing/references/python-env-and-testing.md +126 -0
- package/.claude/skills/bug-fixing/references/rca-guide.md +428 -0
- package/.claude/skills/bug-fixing/references/similar-bug-patterns.md +113 -0
- package/.claude/skills/bug-fixing/references/skill-delegation-guide.md +350 -0
- package/.claude/skills/bug-fixing/references/skill-orchestration.md +155 -0
- package/.claude/skills/bug-fixing/references/testing-strategy.md +350 -0
- package/.claude/skills/bug-fixing/references/tooling-build-scripts.md +162 -0
- package/.claude/skills/bug-fixing/references/user-input-validation.md +77 -0
- package/.claude/skills/bug-fixing/references/ux-patterns.md +158 -0
- package/.claude/skills/bug-fixing/references/windows-terminal-hygiene.md +106 -0
- package/.claude/skills/bug-fixing/references/zero-regression-matrix.md +239 -0
- package/.claude/skills/bug-fixing/references/zero-risk-protocol.md +102 -0
- package/.claude/skills/bug-fixing/scripts/format_code.py +611 -0
- package/.claude/skills/bug-fixing/scripts/generate_report_template.py +74 -0
- package/.claude/skills/bug-fixing/scripts/lint_check.py +816 -0
- package/.claude/skills/bug-fixing/scripts/requirements.txt +36 -0
- package/.claude/skills/cicd-pipeline/SKILL.md +300 -0
- package/.claude/skills/code-review/SKILL.md +535 -0
- package/.claude/skills/code-review/references/anti-pattern-scan.md +102 -0
- package/.claude/skills/code-review/references/automated-analysis.md +456 -0
- package/.claude/skills/code-review/references/backend-common-issues.md +589 -0
- package/.claude/skills/code-review/references/backend-expert-guide.md +415 -0
- package/.claude/skills/code-review/references/backend-review.md +868 -0
- package/.claude/skills/code-review/references/batch-processing-strategy.md +198 -0
- package/.claude/skills/code-review/references/call-chain-analysis-protocol.md +166 -0
- package/.claude/skills/code-review/references/common-patterns.md +321 -0
- package/.claude/skills/code-review/references/configuration-review.md +425 -0
- package/.claude/skills/code-review/references/control-flow-completeness.md +114 -0
- package/.claude/skills/code-review/references/database-review.md +298 -0
- package/.claude/skills/code-review/references/dependency-and-integrity-protocol.md +313 -0
- package/.claude/skills/code-review/references/external-standards.md +51 -0
- package/.claude/skills/code-review/references/feature-review.md +329 -0
- package/.claude/skills/code-review/references/file-review-template.md +326 -0
- package/.claude/skills/code-review/references/frontend-advanced.md +654 -0
- package/.claude/skills/code-review/references/frontend-common-issues.md +482 -0
- package/.claude/skills/code-review/references/frontend-expert-guide.md +342 -0
- package/.claude/skills/code-review/references/frontend-review.md +783 -0
- package/.claude/skills/code-review/references/fullstack-consistency.md +418 -0
- package/.claude/skills/code-review/references/fullstack-review.md +477 -0
- package/.claude/skills/code-review/references/functional-completeness.md +386 -0
- package/.claude/skills/code-review/references/hidden-bugs-detection.md +473 -0
- package/.claude/skills/code-review/references/ide-lint-errors-guide.md +173 -0
- package/.claude/skills/code-review/references/infrastructure-review.md +453 -0
- package/.claude/skills/code-review/references/iteration-review.md +264 -0
- package/.claude/skills/code-review/references/job-review.md +335 -0
- package/.claude/skills/code-review/references/layered-checklist-protocol.md +157 -0
- package/.claude/skills/code-review/references/logic-completeness.md +535 -0
- package/.claude/skills/code-review/references/mandatory-checklist.md +288 -0
- package/.claude/skills/code-review/references/multi-language-guide.md +800 -0
- package/.claude/skills/code-review/references/new-project-review.md +226 -0
- package/.claude/skills/code-review/references/non-code-files-review.md +451 -0
- package/.claude/skills/code-review/references/overlooked-issues.md +657 -0
- package/.claude/skills/code-review/references/platform-specific-review.md +195 -0
- package/.claude/skills/code-review/references/precision-analysis-protocol.md +260 -0
- package/.claude/skills/code-review/references/python-patterns.md +494 -0
- package/.claude/skills/code-review/references/rca-techniques.md +362 -0
- package/.claude/skills/code-review/references/report-template.md +430 -0
- package/.claude/skills/code-review/references/resource-limits-and-degradation.md +137 -0
- package/.claude/skills/code-review/references/review-dimensions.md +311 -0
- package/.claude/skills/code-review/references/review-guide.md +202 -0
- package/.claude/skills/code-review/references/review-knowledge-workflow.md +257 -0
- package/.claude/skills/code-review/references/review-progress-tracker-protocol.md +172 -0
- package/.claude/skills/code-review/references/review-record-template.md +195 -0
- package/.claude/skills/code-review/references/skill-orchestration.md +143 -0
- package/.claude/skills/code-review/references/ui-ux-review.md +470 -0
- package/.claude/skills/containerization/SKILL.md +313 -0
- package/.claude/skills/database-migrations/agents/database-admin.md +142 -0
- package/.claude/skills/database-migrations/agents/database-optimizer.md +144 -0
- package/.claude/skills/database-migrations/commands/migration-observability.md +408 -0
- package/.claude/skills/database-migrations/commands/sql-migrations.md +492 -0
- package/.claude/skills/finishing-a-development-branch/SKILL.md +319 -0
- package/.claude/skills/frontend-design/LICENSE.txt +177 -0
- package/.claude/skills/frontend-design/SKILL.md +587 -0
- package/.claude/skills/frontend-design/references/color-consistency.md +487 -0
- package/.claude/skills/frontend-design/references/color-palettes-full.md +657 -0
- package/.claude/skills/frontend-design/references/design-system-generator.md +285 -0
- package/.claude/skills/frontend-design/references/font-pairings-full.md +705 -0
- package/.claude/skills/frontend-design/references/industry-anti-patterns.md +281 -0
- package/.claude/skills/frontend-design/references/layout-anti-patterns.md +582 -0
- package/.claude/skills/frontend-design/references/motion-patterns.md +659 -0
- package/.claude/skills/frontend-design/references/pre-delivery-checklist.md +153 -0
- package/.claude/skills/frontend-design/references/responsive-design.md +555 -0
- package/.claude/skills/frontend-design/references/style-modification-rules.md +335 -0
- package/.claude/skills/frontend-design/references/ui-styles-full.md +383 -0
- package/.claude/skills/frontend-design/references/ui-styles-rating.md +191 -0
- package/.claude/skills/frontend-design/references/ux-guidelines.md +640 -0
- package/.claude/skills/fullstack-developer/SKILL.md +512 -0
- package/.claude/skills/fullstack-developer/references/api-contract-guide.md +312 -0
- package/.claude/skills/fullstack-developer/references/api-response-patterns.md +223 -0
- package/.claude/skills/fullstack-developer/references/async-patterns.md +220 -0
- package/.claude/skills/fullstack-developer/references/bug-prevention.md +914 -0
- package/.claude/skills/fullstack-developer/references/code-quality-checklist.md +271 -0
- package/.claude/skills/fullstack-developer/references/complete-development-workflow.md +278 -0
- package/.claude/skills/fullstack-developer/references/context-isolation-protocol.md +256 -0
- package/.claude/skills/fullstack-developer/references/database-migration.md +331 -0
- package/.claude/skills/fullstack-developer/references/dependency-and-integrity-protocol.md +390 -0
- package/.claude/skills/fullstack-developer/references/development-phases.md +333 -0
- package/.claude/skills/fullstack-developer/references/expert-guide.md +214 -0
- package/.claude/skills/fullstack-developer/references/file-import-patterns.md +114 -0
- package/.claude/skills/fullstack-developer/references/graceful-degradation-patterns.md +78 -0
- package/.claude/skills/fullstack-developer/references/ide-lint-errors-guide.md +183 -0
- package/.claude/skills/fullstack-developer/references/integration-testing.md +301 -0
- package/.claude/skills/fullstack-developer/references/mock-api-patterns.md +307 -0
- package/.claude/skills/fullstack-developer/references/phase-gate-template.md +249 -0
- package/.claude/skills/fullstack-developer/references/post-edit-quality-gate.md +30 -0
- package/.claude/skills/fullstack-developer/references/python-engineering.md +79 -0
- package/.claude/skills/fullstack-developer/references/skill-orchestration.md +214 -0
- package/.claude/skills/fullstack-developer/references/skill-router-table.md +304 -0
- package/.claude/skills/fullstack-developer/references/state-sync.md +217 -0
- package/.claude/skills/fullstack-developer/references/ui-testing-checklist.md +292 -0
- package/.claude/skills/fullstack-developer/scripts/format_code.py +611 -0
- package/.claude/skills/fullstack-developer/scripts/lint_check.py +816 -0
- package/.claude/skills/fullstack-developer/scripts/requirements.txt +36 -0
- package/.claude/skills/performance-optimization/SKILL.md +250 -0
- package/.claude/skills/product-requirements/SKILL.md +357 -0
- package/.claude/skills/product-requirements/references/acceptance-criteria.md +335 -0
- package/.claude/skills/product-requirements/references/answer-first-questioning-protocol.md +299 -0
- package/.claude/skills/product-requirements/references/competitive-analysis-guide.md +183 -0
- package/.claude/skills/product-requirements/references/document-accuracy-protocol.md +253 -0
- package/.claude/skills/product-requirements/references/document-management-protocol.md +278 -0
- package/.claude/skills/product-requirements/references/external-standards.md +62 -0
- package/.claude/skills/product-requirements/references/feature-spec-template.md +359 -0
- package/.claude/skills/product-requirements/references/knowledge-acquisition-protocol.md +251 -0
- package/.claude/skills/product-requirements/references/plan-execution-protocol.md +334 -0
- package/.claude/skills/product-requirements/references/plan-generation-protocol.md +264 -0
- package/.claude/skills/product-requirements/references/prioritization-frameworks.md +80 -0
- package/.claude/skills/product-requirements/references/requirement-decomposition-protocol.md +291 -0
- package/.claude/skills/product-requirements/references/user-story-examples.md +297 -0
- package/.claude/skills/product-requirements/references/workflow-templates.md +266 -0
- package/.claude/skills/react-best-practices/SKILL.md +198 -0
- package/.claude/skills/react-best-practices/references/advanced-patterns.md +94 -0
- package/.claude/skills/react-best-practices/references/bundle-optimization.md +182 -0
- package/.claude/skills/react-best-practices/references/client-data-fetching.md +112 -0
- package/.claude/skills/react-best-practices/references/complete-guide.md +2249 -0
- package/.claude/skills/react-best-practices/references/eliminating-waterfalls.md +169 -0
- package/.claude/skills/react-best-practices/references/javascript-performance.md +256 -0
- package/.claude/skills/react-best-practices/references/rendering-performance.md +230 -0
- package/.claude/skills/react-best-practices/references/rerender-optimization.md +214 -0
- package/.claude/skills/react-best-practices/references/server-performance.md +182 -0
- package/.claude/skills/security-audit/SKILL.md +226 -0
- package/.claude/skills/shared-references/advanced-debugging-techniques.md +186 -0
- package/.claude/skills/shared-references/code-quality-checklist.md +218 -0
- package/.claude/skills/shared-references/code-review-efficiency-guide.md +125 -0
- package/.claude/skills/shared-references/mcp-dependency-compatibility-protocol.md +276 -0
- package/.claude/skills/shared-references/skill-call-graph.md +230 -0
- package/.claude/skills/shared-references/skill-orchestration-protocol.md +281 -0
- package/.claude/skills/shared-references/subagent-dispatch-templates.md +199 -0
- package/.claude/skills/skill-expert-skills/LICENSE.txt +204 -0
- package/.claude/skills/skill-expert-skills/QUICK_NAVIGATION.md +374 -0
- package/.claude/skills/skill-expert-skills/SKILL.md +247 -0
- package/.claude/skills/skill-expert-skills/docs/_index.md +91 -0
- package/.claude/skills/skill-expert-skills/references/deep-research-methodology.md +389 -0
- package/.claude/skills/skill-expert-skills/references/docs-generation-workflow.md +398 -0
- package/.claude/skills/skill-expert-skills/references/domain-expertise-protocol.md +343 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/_index.md +54 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/backend-expertise.md +517 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/bug-fixing-expertise.md +363 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/code-review-expertise.md +392 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/frontend-expertise.md +410 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge-template.md +503 -0
- package/.claude/skills/skill-expert-skills/references/examples.md +782 -0
- package/.claude/skills/skill-expert-skills/references/integration-examples.md +655 -0
- package/.claude/skills/skill-expert-skills/references/knowledge-validation-checklist.md +246 -0
- package/.claude/skills/skill-expert-skills/references/latest-knowledge-acquisition.md +461 -0
- package/.claude/skills/skill-expert-skills/references/mcp-tools-guide.md +439 -0
- package/.claude/skills/skill-expert-skills/references/official-best-practices.md +616 -0
- package/.claude/skills/skill-expert-skills/references/patterns.md +218 -0
- package/.claude/skills/skill-expert-skills/references/plugin-skills-guide.md +432 -0
- package/.claude/skills/skill-expert-skills/references/requirement-elicitation-protocol.md +290 -0
- package/.claude/skills/skill-expert-skills/references/skill-creator-SKILL.md +353 -0
- package/.claude/skills/skill-expert-skills/references/skill-templates.md +583 -0
- package/.claude/skills/skill-expert-skills/references/skills-knowledge-base.md +561 -0
- package/.claude/skills/skill-expert-skills/references/tools-guide.md +379 -0
- package/.claude/skills/skill-expert-skills/references/troubleshooting.md +378 -0
- package/.claude/skills/skill-expert-skills/references/universality-guide.md +205 -0
- package/.claude/skills/skill-expert-skills/references/writing-style-guide.md +466 -0
- package/.claude/skills/skill-expert-skills/scripts/__pycache__/quick_validate.cpython-313.pyc +0 -0
- package/.claude/skills/skill-expert-skills/scripts/__pycache__/universal_validate.cpython-313.pyc +0 -0
- package/.claude/skills/skill-expert-skills/scripts/analyze_trigger.py +425 -0
- package/.claude/skills/skill-expert-skills/scripts/diff_with_official.py +188 -0
- package/.claude/skills/skill-expert-skills/scripts/init_skill.py +349 -0
- package/.claude/skills/skill-expert-skills/scripts/package_skill.py +156 -0
- package/.claude/skills/skill-expert-skills/scripts/quick_validate.py +493 -0
- package/.claude/skills/skill-expert-skills/scripts/requirements.txt +2 -0
- package/.claude/skills/skill-expert-skills/scripts/universal_validate.py +182 -0
- package/.claude/skills/skill-expert-skills/scripts/upgrade_skill.py +431 -0
- package/.claude/skills/subagent-driven-development/SKILL.md +268 -0
- package/.claude/skills/test-driven-development/SKILL.md +246 -0
- package/.claude/skills/test-driven-development/references/testing-anti-patterns.md +192 -0
- package/.claude/skills/using-git-worktrees/SKILL.md +266 -0
- package/.claude/skills/using-skillstack/SKILL.md +127 -0
- package/.claude/skills/vercel-deploy/SKILL.md +166 -0
- package/.claude/skills/vercel-deploy/scripts/deploy.sh +249 -0
- package/.claude/skills/verification-before-completion/SKILL.md +305 -0
- package/.claude/skills/writing-plans/SKILL.md +259 -0
- package/README.md +69 -0
- package/bin/cli.js +468 -0
- package/lib/init.js +333 -0
- package/package.json +29 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Configuration-Driven Fixes
|
|
2
|
+
|
|
3
|
+
Avoid hardcoded solutions. Prefer dynamic, maintainable approaches.
|
|
4
|
+
|
|
5
|
+
## Why Avoid Hardcoding?
|
|
6
|
+
|
|
7
|
+
| Hardcoded | Problem |
|
|
8
|
+
|-----------|---------|
|
|
9
|
+
| List of models | New models require code changes |
|
|
10
|
+
| Feature flags in code | Can't change without deploy |
|
|
11
|
+
| Environment-specific logic | Breaks in other environments |
|
|
12
|
+
| Version checks | Breaks when versions change |
|
|
13
|
+
|
|
14
|
+
## Solution Hierarchy
|
|
15
|
+
|
|
16
|
+
### 1. Database-Driven (Best)
|
|
17
|
+
|
|
18
|
+
Store capability/config in database, allowing runtime updates.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
# Model with capability field
|
|
22
|
+
class LLMProvider(Base):
|
|
23
|
+
supports_tool_calling: bool | None = None
|
|
24
|
+
|
|
25
|
+
# Service uses field
|
|
26
|
+
if not provider.supports_tool_calling:
|
|
27
|
+
use_fallback_mode()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Pros**: User configurable, no code changes needed
|
|
31
|
+
**Cons**: Requires migration for new fields
|
|
32
|
+
|
|
33
|
+
### 2. Runtime Detection
|
|
34
|
+
|
|
35
|
+
Probe the system at runtime to detect capabilities.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
async def detect_tool_support(model: str, api_key: str) -> bool:
|
|
39
|
+
"""Probe API to check if model supports tools."""
|
|
40
|
+
try:
|
|
41
|
+
response = await client.chat(
|
|
42
|
+
model=model,
|
|
43
|
+
messages=[{"role": "user", "content": "test"}],
|
|
44
|
+
tools=[test_tool_definition],
|
|
45
|
+
)
|
|
46
|
+
return "tool_calls" in response
|
|
47
|
+
except Exception:
|
|
48
|
+
return False
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Pros**: Always accurate, adapts to changes
|
|
52
|
+
**Cons**: Additional API call, may have latency
|
|
53
|
+
|
|
54
|
+
### 3. Configuration File
|
|
55
|
+
|
|
56
|
+
Use YAML/JSON config that can be updated without code changes.
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
# config/features.yaml
|
|
60
|
+
models:
|
|
61
|
+
gpt-4:
|
|
62
|
+
supports_tools: true
|
|
63
|
+
deepseek-reasoner:
|
|
64
|
+
supports_tools: false
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
def load_model_config(model_name: str) -> dict:
|
|
69
|
+
config = yaml.safe_load(open("config/features.yaml"))
|
|
70
|
+
return config["models"].get(model_name, {})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Pros**: Easy to update, version controlled
|
|
74
|
+
**Cons**: Still requires config changes
|
|
75
|
+
|
|
76
|
+
### 4. Pattern Matching (Fallback)
|
|
77
|
+
|
|
78
|
+
When detection is impossible, use pattern matching with clear documentation.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
def infer_capability(model_name: str) -> bool:
|
|
82
|
+
"""
|
|
83
|
+
Infer capability from model name pattern.
|
|
84
|
+
|
|
85
|
+
Fallback when database config is None and runtime detection
|
|
86
|
+
is not available.
|
|
87
|
+
"""
|
|
88
|
+
patterns = ["reasoner", "r1", "o1-preview", "o1-mini"]
|
|
89
|
+
return not any(p in model_name.lower() for p in patterns)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Pros**: No external dependencies
|
|
93
|
+
**Cons**: May need updates when new models appear
|
|
94
|
+
|
|
95
|
+
### 5. Hardcoded List (Last Resort)
|
|
96
|
+
|
|
97
|
+
Only use when no other option exists. MUST document why.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
# ⚠️ HARDCODED: Used because XYZ API doesn't support capability detection
|
|
101
|
+
# TODO: Remove when API v2 adds feature detection endpoint
|
|
102
|
+
UNSUPPORTED_MODELS = frozenset(["model-a", "model-b"])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Migration Pattern
|
|
106
|
+
|
|
107
|
+
When refactoring from hardcoded to config-driven:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
# Step 1: Add database field
|
|
111
|
+
# Migration: add supports_feature column (nullable)
|
|
112
|
+
|
|
113
|
+
# Step 2: Use hybrid approach during transition
|
|
114
|
+
def get_feature_support(config) -> bool:
|
|
115
|
+
# Priority 1: Database config
|
|
116
|
+
if config.supports_feature is not None:
|
|
117
|
+
return config.supports_feature
|
|
118
|
+
|
|
119
|
+
# Priority 2: Pattern matching fallback
|
|
120
|
+
return infer_from_name(config.model_name)
|
|
121
|
+
|
|
122
|
+
# Step 3: Backfill existing records with proper values
|
|
123
|
+
|
|
124
|
+
# Step 4: Add runtime detection for new records
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Summary Table
|
|
128
|
+
|
|
129
|
+
| Approach | Maintenance | Flexibility | Complexity |
|
|
130
|
+
|----------|-------------|-------------|------------|
|
|
131
|
+
| Database field | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
|
|
132
|
+
| Runtime detection | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
|
|
133
|
+
| Config file | ⭐⭐ | ⭐⭐ | ⭐ |
|
|
134
|
+
| Pattern matching | ⭐ | ⭐ | ⭐ |
|
|
135
|
+
| Hardcoded list | ❌ | ❌ | ⭐ |
|
|
136
|
+
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Context Isolation Protocol (上下文隔离协议)
|
|
2
|
+
|
|
3
|
+
> 确保 Bug 修复过程中调用其他技能时不会丢失主上下文,防止目标漂移和范围膨胀。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 问题背景
|
|
8
|
+
|
|
9
|
+
### 技能污染 (Skill Pollution) 定义
|
|
10
|
+
|
|
11
|
+
当修复 Bug 过程中需要调用其他技能时,AI 可能会:
|
|
12
|
+
|
|
13
|
+
1. **目标漂移 (Goal Drift)**: 开始修复 Bug,但逐渐转向功能开发或重构
|
|
14
|
+
2. **范围膨胀 (Scope Creep)**: 小修复变成大工程,引入更多风险
|
|
15
|
+
3. **上下文丢失 (Context Loss)**: 忘记原始目标,无法正确验证修复效果
|
|
16
|
+
|
|
17
|
+
### 污染示例
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
❌ 污染场景:
|
|
21
|
+
|
|
22
|
+
用户报告:登录按钮点击无响应
|
|
23
|
+
|
|
24
|
+
AI 行为:
|
|
25
|
+
1. 发现需要修复登录 API ✅
|
|
26
|
+
2. 发现 API 代码"不够好",开始重构 ❌
|
|
27
|
+
3. 重构过程中发现数据库设计"有问题" ❌
|
|
28
|
+
4. 开始重新设计用户表 ❌
|
|
29
|
+
5. 几个小时后...用户的登录按钮问题还没修复 ❌
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 解决方案:上下文隔离架构
|
|
35
|
+
|
|
36
|
+
### 核心概念
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
40
|
+
│ BUG-FIXING MAIN CONTEXT (主上下文) │
|
|
41
|
+
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │
|
|
42
|
+
│ │
|
|
43
|
+
│ 🔒 IMMUTABLE ANCHOR (不可变锚点): │
|
|
44
|
+
│ ┌──────────────────────────────────────────────────────────────────┐ │
|
|
45
|
+
│ │ Bug ID: BUG-001 │ │
|
|
46
|
+
│ │ Original Symptom: 登录按钮点击无响应 │ │
|
|
47
|
+
│ │ Root Cause: onClick 事件处理函数抛出异常 │ │
|
|
48
|
+
│ │ Success Criteria: 点击登录按钮后能正常跳转 │ │
|
|
49
|
+
│ └──────────────────────────────────────────────────────────────────┘ │
|
|
50
|
+
│ │
|
|
51
|
+
│ 📋 EXECUTION STATE (可变执行状态): │
|
|
52
|
+
│ ┌──────────────────────────────────────────────────────────────────┐ │
|
|
53
|
+
│ │ Current Phase: 4.2 │ │
|
|
54
|
+
│ │ Delegated Tasks: [frontend-design: pending] │ │
|
|
55
|
+
│ │ Completed Tasks: [RCA, Scope Discovery] │ │
|
|
56
|
+
│ └──────────────────────────────────────────────────────────────────┘ │
|
|
57
|
+
│ │
|
|
58
|
+
│ 🔧 ISOLATED DELEGATION (隔离委托区): │
|
|
59
|
+
│ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │
|
|
60
|
+
│ │ Delegated Skill: frontend-design │ │
|
|
61
|
+
│ │ Purpose: 修复 LoginButton 组件 │ │
|
|
62
|
+
│ │ Scope Constraint: 仅修复点击处理,不重构 │ │
|
|
63
|
+
│ │ Exit Condition: 按钮可点击 │ │
|
|
64
|
+
│ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │
|
|
65
|
+
│ │
|
|
66
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 三层保护机制
|
|
70
|
+
|
|
71
|
+
| 保护层 | 机制 | 作用 |
|
|
72
|
+
|-------|------|------|
|
|
73
|
+
| **锚点层** | 不可变的 Bug 信息 | 始终记住原始目标 |
|
|
74
|
+
| **约束层** | 委托范围限制 | 防止范围膨胀 |
|
|
75
|
+
| **检查层** | 进入/退出验证 | 确保正确切换上下文 |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 实施规范
|
|
80
|
+
|
|
81
|
+
### 1. 主上下文初始化
|
|
82
|
+
|
|
83
|
+
**在 Phase 0 完成后,必须建立主上下文锚点:**
|
|
84
|
+
|
|
85
|
+
```markdown
|
|
86
|
+
## 🔒 主上下文锚点 (Main Context Anchor)
|
|
87
|
+
|
|
88
|
+
### 不可变信息
|
|
89
|
+
- **Bug ID**: BUG-XXX
|
|
90
|
+
- **原始症状**: [用户原话]
|
|
91
|
+
- **入口点**: [具体 UI/API/Job]
|
|
92
|
+
- **成功标准**: [如何判断修复成功]
|
|
93
|
+
|
|
94
|
+
### 当前状态
|
|
95
|
+
- **阶段**: Phase X
|
|
96
|
+
- **根因**: [如已确定]
|
|
97
|
+
- **待修复位置**: [列表]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 2. 委托前检查
|
|
101
|
+
|
|
102
|
+
**进入任何委托任务前,必须回答:**
|
|
103
|
+
|
|
104
|
+
| 检查项 | 必须明确 |
|
|
105
|
+
|-------|---------|
|
|
106
|
+
| **目的** | 这个委托任务是为了修复 Bug 的哪个方面? |
|
|
107
|
+
| **范围** | 最小必要的工作是什么? |
|
|
108
|
+
| **禁止** | 明确不能做什么? |
|
|
109
|
+
| **退出** | 什么标志着委托完成? |
|
|
110
|
+
| **时间** | 预计需要多少步骤?(超过 3 步需警惕) |
|
|
111
|
+
|
|
112
|
+
### 3. 委托中监控
|
|
113
|
+
|
|
114
|
+
**执行委托任务时,持续检查:**
|
|
115
|
+
|
|
116
|
+
```markdown
|
|
117
|
+
## ⚠️ 范围警戒 (Scope Guard)
|
|
118
|
+
|
|
119
|
+
每完成一个步骤,问自己:
|
|
120
|
+
1. 这一步是否直接服务于修复 Bug?
|
|
121
|
+
2. 是否在预定范围内?
|
|
122
|
+
3. 是否有"顺便做点其他事"的冲动?
|
|
123
|
+
|
|
124
|
+
🚨 如果发现超出范围:
|
|
125
|
+
1. 立即停止当前工作
|
|
126
|
+
2. 记录超出范围的发现
|
|
127
|
+
3. 询问用户是否需要单独处理
|
|
128
|
+
4. 返回主上下文继续修复
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 4. 委托后验证
|
|
132
|
+
|
|
133
|
+
**退出委托任务时,必须验证:**
|
|
134
|
+
|
|
135
|
+
| 验证项 | 通过标准 |
|
|
136
|
+
|-------|---------|
|
|
137
|
+
| **目标达成** | 委托目的已实现 |
|
|
138
|
+
| **范围遵守** | 未超出预定范围 |
|
|
139
|
+
| **无副作用** | 未引入无关变更 |
|
|
140
|
+
| **可集成** | 产出可直接用于修复 |
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 模板和格式
|
|
145
|
+
|
|
146
|
+
### 委托进入模板
|
|
147
|
+
|
|
148
|
+
```markdown
|
|
149
|
+
---
|
|
150
|
+
## 🔧 技能委托通知
|
|
151
|
+
|
|
152
|
+
### 主上下文确认
|
|
153
|
+
- **Bug ID**: BUG-XXX
|
|
154
|
+
- **原始症状**: [...]
|
|
155
|
+
- **根因**: [...]
|
|
156
|
+
- **当前阶段**: Phase X
|
|
157
|
+
|
|
158
|
+
### 委托详情
|
|
159
|
+
- **目标技能**: `skill-name`
|
|
160
|
+
- **委托目的**: [为什么需要这个技能]
|
|
161
|
+
- **范围限定**:
|
|
162
|
+
- ✅ [允许做的事情]
|
|
163
|
+
- ❌ [不允许做的事情]
|
|
164
|
+
- **退出条件**: [什么标志完成]
|
|
165
|
+
- **预计步骤**: X 步
|
|
166
|
+
|
|
167
|
+
### 约束传递
|
|
168
|
+
- 保持现有代码风格
|
|
169
|
+
- 不引入新依赖 (除非必须)
|
|
170
|
+
- 最小 LOC 原则
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
⏱️ 开始委托任务...
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 委托退出模板
|
|
177
|
+
|
|
178
|
+
```markdown
|
|
179
|
+
---
|
|
180
|
+
## ✅ 委托任务完成
|
|
181
|
+
|
|
182
|
+
### 完成情况
|
|
183
|
+
- **目标达成**: ✅ / ❌
|
|
184
|
+
- **范围遵守**: ✅ / ❌ (如超出,说明原因)
|
|
185
|
+
- **产出物**: [创建/修改的文件列表]
|
|
186
|
+
|
|
187
|
+
### 超出范围发现 (如有)
|
|
188
|
+
[记录发现但未处理的问题,建议后续单独处理]
|
|
189
|
+
|
|
190
|
+
### 返回指令
|
|
191
|
+
- **继续阶段**: Phase X.Y
|
|
192
|
+
- **下一步动作**: [具体动作]
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
🔄 返回 Bug 修复主上下文
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 常见污染场景及应对
|
|
201
|
+
|
|
202
|
+
### 场景 1: "顺便优化"冲动
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
❌ 污染行为:
|
|
206
|
+
修复 API 返回格式时,发现代码"不够好",开始重构整个 API 模块。
|
|
207
|
+
|
|
208
|
+
✅ 正确行为:
|
|
209
|
+
1. 记录发现的"可优化点"
|
|
210
|
+
2. 仅修复必要的返回格式问题
|
|
211
|
+
3. 修复完成后,建议用户单独处理优化
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 场景 2: 连带发现
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
❌ 污染行为:
|
|
218
|
+
修复登录 Bug 时,发现注册也有类似问题,直接开始修复注册。
|
|
219
|
+
|
|
220
|
+
✅ 正确行为:
|
|
221
|
+
1. 在 Scope Discovery 阶段记录注册问题
|
|
222
|
+
2. 如果是同一根因,一起修复 ✅
|
|
223
|
+
3. 如果是不同问题,记录为 Related Issue,当前聚焦登录
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### 场景 3: 基础设施问题
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
❌ 污染行为:
|
|
230
|
+
修复前端 Bug 时,发现测试框架配置有问题,开始修复测试配置。
|
|
231
|
+
|
|
232
|
+
✅ 正确行为:
|
|
233
|
+
1. 如果不影响修复:记录,继续修复 Bug
|
|
234
|
+
2. 如果阻塞修复:最小化解决阻塞,不全面修复配置
|
|
235
|
+
3. 建议后续单独处理测试配置问题
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## 检查清单
|
|
241
|
+
|
|
242
|
+
### 委托前
|
|
243
|
+
- [ ] 主上下文锚点已建立
|
|
244
|
+
- [ ] 委托目的明确
|
|
245
|
+
- [ ] 范围限定清晰
|
|
246
|
+
- [ ] 退出条件定义
|
|
247
|
+
|
|
248
|
+
### 委托中
|
|
249
|
+
- [ ] 每步都在范围内
|
|
250
|
+
- [ ] 未被"优化冲动"带偏
|
|
251
|
+
- [ ] 保持对主上下文的意识
|
|
252
|
+
|
|
253
|
+
### 委托后
|
|
254
|
+
- [ ] 目标已达成
|
|
255
|
+
- [ ] 范围未超出
|
|
256
|
+
- [ ] 产出可集成
|
|
257
|
+
- [ ] 已返回主上下文
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## 违规处理
|
|
262
|
+
|
|
263
|
+
| 违规类型 | 处理方式 |
|
|
264
|
+
|---------|---------|
|
|
265
|
+
| 发现超出范围 | 立即停止,记录,询问用户 |
|
|
266
|
+
| 目标漂移 | 重新读取主上下文锚点,回到正轨 |
|
|
267
|
+
| 范围膨胀 | 收缩到最小必要,其余作为建议 |
|
|
268
|
+
| 上下文丢失 | 重新输出主上下文确认,继续 |
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Cross-surface Regression Checklist
|
|
2
|
+
|
|
3
|
+
Fixing a bug in one “surface” (e.g., an API endpoint or a settings page) often introduces regressions in other surfaces that share the same **contract**, **data**, or **behavior**.
|
|
4
|
+
|
|
5
|
+
This checklist helps you find and validate *all* impacted consumers, so a fix can be shipped once with low risk.
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
Use this checklist when the fix touches any shared artifact:
|
|
10
|
+
|
|
11
|
+
- An API response/request schema
|
|
12
|
+
- A database model / data shape
|
|
13
|
+
- A shared configuration (feature flags, provider lists, routing rules)
|
|
14
|
+
- A shared UI component or domain hook/store
|
|
15
|
+
- A shared cache key / pagination / sorting rules
|
|
16
|
+
- A shared “list of things” used across multiple screens (settings, runtime selection, admin views, etc.)
|
|
17
|
+
|
|
18
|
+
## Definitions
|
|
19
|
+
|
|
20
|
+
- **Surface**: any user-visible or system-visible touchpoint (UI screens, API endpoints, background jobs, CLIs, integrations).
|
|
21
|
+
- **Contract**: the expectations that connect a producer to its consumers (types, schema, invariants, default behavior).
|
|
22
|
+
- **Consumer inventory**: a complete list of places that depend on the same contract/data.
|
|
23
|
+
|
|
24
|
+
## Step 1 — Identify the shared contract/data
|
|
25
|
+
|
|
26
|
+
Write this down explicitly (1–3 sentences):
|
|
27
|
+
|
|
28
|
+
- What changed? (field name, endpoint behavior, allowed values, sorting, auth, error shape)
|
|
29
|
+
- What must remain stable? (backward compatibility constraints)
|
|
30
|
+
- What is the “source of truth”? (API, DB, config file, derived cache)
|
|
31
|
+
|
|
32
|
+
## Step 2 — Build a consumer inventory (the critical step)
|
|
33
|
+
|
|
34
|
+
List every consumer that reads/derives the same contract/data.
|
|
35
|
+
|
|
36
|
+
- **UI consumers**
|
|
37
|
+
- List view(s)
|
|
38
|
+
- Detail view(s)
|
|
39
|
+
- Settings/config page(s)
|
|
40
|
+
- Selection drop-down(s) / pickers / modals
|
|
41
|
+
- Export/download flows
|
|
42
|
+
- **API consumers**
|
|
43
|
+
- Public endpoints
|
|
44
|
+
- Internal services/clients
|
|
45
|
+
- SDK calls (if any)
|
|
46
|
+
- **Background consumers**
|
|
47
|
+
- Jobs/tasks/cron
|
|
48
|
+
- Async pipelines (analysis, indexing, etc.)
|
|
49
|
+
- **Operational consumers**
|
|
50
|
+
- Admin dashboards
|
|
51
|
+
- Metrics/alerts/log parsers
|
|
52
|
+
- Migrations/backfills
|
|
53
|
+
|
|
54
|
+
### Consumer inventory template
|
|
55
|
+
|
|
56
|
+
Fill a table like this:
|
|
57
|
+
|
|
58
|
+
| Consumer | Surface type | Entry point | Uses what? | Risk level | Verification |
|
|
59
|
+
|---|---|---|---|---|---|
|
|
60
|
+
| UI: selection picker | UI | route → control | reads list, filters by status | high | manual + unit |
|
|
61
|
+
| API: status endpoint | API | GET /… | returns updated fields | high | contract test |
|
|
62
|
+
| background analyzer | job | task name | expects enum values | medium | integration smoke |
|
|
63
|
+
|
|
64
|
+
## Step 3 — Define a minimal regression matrix per consumer
|
|
65
|
+
|
|
66
|
+
For each **high-risk** consumer, verify the smallest set of cases that catch 80% of regressions:
|
|
67
|
+
|
|
68
|
+
- **Happy path**: typical request with typical data
|
|
69
|
+
- **Empty state**: no items / no results
|
|
70
|
+
- **Pagination**: first page vs subsequent page (if applicable)
|
|
71
|
+
- **Sorting**: default sort and one explicit sort parameter (if applicable)
|
|
72
|
+
- **Filtering**: the most common filter path (if applicable)
|
|
73
|
+
- **Permissions**: allowed vs forbidden user/role (if applicable)
|
|
74
|
+
- **Error shape**: one representative error should still be actionable and consistent
|
|
75
|
+
|
|
76
|
+
## Step 4 — Check cross-surface invariants
|
|
77
|
+
|
|
78
|
+
These are common “looks fine here, broken there” causes:
|
|
79
|
+
|
|
80
|
+
- **Field naming drift**: one surface uses `analysis_status`, another expects `status`
|
|
81
|
+
- **Default values**: missing fields vs explicit `null` vs omitted keys
|
|
82
|
+
- **Compatibility fallbacks**: legacy fields overriding new mappings
|
|
83
|
+
- **Caching**: stale cache keys; different TTLs; inconsistent invalidation triggers
|
|
84
|
+
- **Feature flags**: enabled in one surface but not in another
|
|
85
|
+
- **Versioned base URLs**: `/v1` vs `/v4`; accidental double-prefixing
|
|
86
|
+
|
|
87
|
+
## Step 5 — Add the smallest automated guardrail
|
|
88
|
+
|
|
89
|
+
Pick one (or more) that best matches the contract:
|
|
90
|
+
|
|
91
|
+
- **Contract tests**: assert response shape and key invariants across versions
|
|
92
|
+
- **Unit tests**: URL builders, mappers, parsing logic, fallbacks
|
|
93
|
+
- **Integration smoke**: critical path end-to-end for the shared contract
|
|
94
|
+
|
|
95
|
+
Rule of thumb: if the bug involved a **mapping/fallback**, add a unit test that locks the mapping behavior.
|
|
96
|
+
|
|
97
|
+
## Similar-bug hunt (recommended)
|
|
98
|
+
|
|
99
|
+
After the fix, search for the same pattern elsewhere:
|
|
100
|
+
|
|
101
|
+
- URL construction patterns (e.g., `/v1` joining, trailing slashes)
|
|
102
|
+
- Field fallback logic (legacy vs new config)
|
|
103
|
+
- Consumer parsing assumptions (lists vs dicts, optional vs required)
|
|
104
|
+
|
|
105
|
+
Example search prompts (adapt to repo conventions):
|
|
106
|
+
|
|
107
|
+
- `"legacy" AND "fallback" AND "<field_name>"`
|
|
108
|
+
- `"base_url" AND "v1" AND "join"`
|
|
109
|
+
- `"model_map" OR "mapping" OR "selector"`
|
|
110
|
+
- `"analysis_status" AND ("list" OR "dropdown" OR "picker")`
|
|
111
|
+
|
|
112
|
+
## Definition of Done (cross-surface)
|
|
113
|
+
|
|
114
|
+
You are not “done” until:
|
|
115
|
+
|
|
116
|
+
- Every **high-risk consumer** in your inventory has a pass/fail outcome recorded
|
|
117
|
+
- At least one **automated guardrail** exists for the root cause (or a justified exception)
|
|
118
|
+
- The fix does not introduce new inconsistencies between list/detail/settings/selection surfaces
|
|
119
|
+
|
|
120
|
+
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Database Investigation Guide
|
|
2
|
+
|
|
3
|
+
Bugs often originate from database schema, migrations, or data issues.
|
|
4
|
+
|
|
5
|
+
## What to Check
|
|
6
|
+
|
|
7
|
+
### 1. Schema Definition
|
|
8
|
+
|
|
9
|
+
| Location | Description |
|
|
10
|
+
|----------|-------------|
|
|
11
|
+
| `migrations/` | Migration history |
|
|
12
|
+
| `alembic/versions/` | Alembic migrations (Python) |
|
|
13
|
+
| `*.sql` | Raw SQL scripts |
|
|
14
|
+
| `models/` | ORM model definitions |
|
|
15
|
+
| `entities/` | Entity definitions |
|
|
16
|
+
|
|
17
|
+
**Key Questions**:
|
|
18
|
+
- Does the DB column exist?
|
|
19
|
+
- Is the type correct?
|
|
20
|
+
- Are constraints appropriate?
|
|
21
|
+
- Is the index present for query performance?
|
|
22
|
+
|
|
23
|
+
### 2. Migration Status
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Alembic (Python)
|
|
27
|
+
alembic current
|
|
28
|
+
alembic history
|
|
29
|
+
|
|
30
|
+
# Django
|
|
31
|
+
python manage.py showmigrations
|
|
32
|
+
|
|
33
|
+
# TypeORM
|
|
34
|
+
npm run typeorm migration:show
|
|
35
|
+
|
|
36
|
+
# Sequelize
|
|
37
|
+
npx sequelize db:migrate:status
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. Compare ORM vs Actual DB
|
|
41
|
+
|
|
42
|
+
```sql
|
|
43
|
+
-- PostgreSQL: Check actual column
|
|
44
|
+
SELECT column_name, data_type, is_nullable
|
|
45
|
+
FROM information_schema.columns
|
|
46
|
+
WHERE table_name = 'your_table';
|
|
47
|
+
|
|
48
|
+
-- SQLite: Check schema
|
|
49
|
+
.schema your_table
|
|
50
|
+
|
|
51
|
+
-- MySQL: Check schema
|
|
52
|
+
DESCRIBE your_table;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Common Database Bugs
|
|
56
|
+
|
|
57
|
+
### Missing Field
|
|
58
|
+
|
|
59
|
+
**Symptom**: `column does not exist`
|
|
60
|
+
|
|
61
|
+
**Investigation**:
|
|
62
|
+
1. Check if field exists in ORM model
|
|
63
|
+
2. Check if migration was created
|
|
64
|
+
3. Check if migration was applied
|
|
65
|
+
|
|
66
|
+
**Fix**:
|
|
67
|
+
```bash
|
|
68
|
+
# Create migration
|
|
69
|
+
alembic revision --autogenerate -m "add_field_name"
|
|
70
|
+
|
|
71
|
+
# Apply migration
|
|
72
|
+
alembic upgrade head
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Type Mismatch
|
|
76
|
+
|
|
77
|
+
**Symptom**: Data truncation, constraint violation
|
|
78
|
+
|
|
79
|
+
**Investigation**:
|
|
80
|
+
1. Compare ORM field type vs DB column type
|
|
81
|
+
2. Check data being inserted
|
|
82
|
+
|
|
83
|
+
**Fix**: Create migration to alter column type
|
|
84
|
+
|
|
85
|
+
### Missing Index
|
|
86
|
+
|
|
87
|
+
**Symptom**: Slow queries
|
|
88
|
+
|
|
89
|
+
**Investigation**:
|
|
90
|
+
```sql
|
|
91
|
+
EXPLAIN ANALYZE SELECT * FROM table WHERE field = 'value';
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Fix**: Add index in migration
|
|
95
|
+
|
|
96
|
+
### Constraint Violation
|
|
97
|
+
|
|
98
|
+
**Symptom**: `violates not-null constraint`, `unique constraint`
|
|
99
|
+
|
|
100
|
+
**Investigation**:
|
|
101
|
+
1. Check constraint definition
|
|
102
|
+
2. Check data being inserted
|
|
103
|
+
3. Check if default value is needed
|
|
104
|
+
|
|
105
|
+
## Migration Best Practices
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# Always set PYTHONPATH when running alembic
|
|
109
|
+
# Windows
|
|
110
|
+
set PYTHONPATH=.\backend
|
|
111
|
+
alembic upgrade head
|
|
112
|
+
|
|
113
|
+
# Linux/macOS
|
|
114
|
+
PYTHONPATH=./backend alembic upgrade head
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Data Investigation
|
|
118
|
+
|
|
119
|
+
```sql
|
|
120
|
+
-- Check for null values
|
|
121
|
+
SELECT COUNT(*) FROM table WHERE field IS NULL;
|
|
122
|
+
|
|
123
|
+
-- Check for duplicates
|
|
124
|
+
SELECT field, COUNT(*) FROM table GROUP BY field HAVING COUNT(*) > 1;
|
|
125
|
+
|
|
126
|
+
-- Check data distribution
|
|
127
|
+
SELECT field, COUNT(*) FROM table GROUP BY field ORDER BY COUNT(*) DESC LIMIT 10;
|
|
128
|
+
```
|
|
129
|
+
|