# Schema Analysis - {{FEATURE_NAME_TITLE}}

**Feature**: {{FEATURE_NAME}}
**Date**: {{DATE}}
**Method**: {{#if method}}{{method}}{{else}}Manual Code Analysis{{/if}}
**Analyzed By**: {{AUTHOR}}

---

## Summary

**Tables Analyzed**: {{#if tableCount}}{{tableCount}}{{else}}0{{/if}}
**Code Files Scanned**: {{#if fileCount}}{{fileCount}}{{else}}0{{/if}}
**MCP Tools Used**: {{#if mcpUsed}}{{mcpUsed}}{{else}}No (manual analysis){{/if}}

---

## Tables Analyzed

{{#each tables}}
### Table: {{this.name}}

**Source:**
{{#if this.mcpSource}}- MCP: {{this.mcpSource}}{{/if}}
{{#if this.codeSource}}- Code: {{this.codeSource}}{{/if}}

**Columns:**
| Column Name | Type | Nullable | Default | Notes |
|------------|------|----------|---------|-------|
{{#each this.columns}}
| {{this.name}} | {{this.type}} | {{#if this.nullable}}YES{{else}}NO{{/if}} | {{#if this.default}}{{this.default}}{{else}}-{{/if}} | {{#if this.notes}}{{this.notes}}{{else}}-{{/if}} |
{{/each}}

**Relationships:**
{{#each this.relationships}}
- {{this.description}}
{{/each}}

**Indexes:**
{{#each this.indexes}}
- {{this.description}}
{{/each}}

---
{{/each}}

## ⚠️ CRITICAL FINDINGS

### Field Name Mismatches (MUST FIX)

{{#if fieldMismatches}}
{{#each fieldMismatches}}
- ❌ {{this.description}}
{{/each}}
{{else}}
✅ No field name mismatches found
{{/if}}

### Type Mismatches

{{#if typeMismatches}}
{{#each typeMismatches}}
- ⚠️ {{this.description}}
{{/each}}
{{else}}
✅ No type mismatches found
{{/if}}

### Relationship Corrections

{{#if relationshipIssues}}
{{#each relationshipIssues}}
- ⚠️ {{this.description}}
{{/each}}
{{else}}
✅ All relationships correctly identified
{{/if}}

---

## Recommendations for contracts.cs

Based on real schema analysis:

\`\`\`csharp
{{#each dtoRecommendations}}
// {{this.tableName}} → {{this.dtoName}}
public record {{this.dtoName}}(
{{#each this.fields}}
    {{this.type}} {{this.name}}{{#if this.nullable}}?{{/if}}{{#unless @last}},{{/unless}}  // {{#if this.comment}}{{this.comment}}{{/if}}
{{/each}}
);

{{/each}}
\`\`\`

---

## Analysis Notes

{{#if notes}}
{{notes}}
{{else}}
_No additional notes._
{{/if}}

---

## Next Steps

- [ ] Verify schema analysis with stakeholders
- [ ] Generate `contracts.cs` using real field names
- [ ] Update `spec.md` data model section with findings
- [ ] Document any schema migrations needed in `decisions.md`

---

*Generated by MORPH-SPEC v{{FRAMEWORK_VERSION}}*
*Schema analysis helps prevent DTO field name mismatches and ensures contracts match real database schema*
