( filePath: string, content: string )
| 642 | type: f.type || "unknown", |
| 643 | flags: f.flags || [], |
| 644 | })) as SchemaField[], |
| 645 | relations: (m.relations || []).map((r: any) => `${r.name}: ${r.target}`), |
| 646 | orm: "sqlalchemy" as const, |
| 647 | confidence: "ast" as const, |
| 648 | })); |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Extract Django ORM models from a Python file using AST. |
| 653 | * Handles models.Model subclasses with CharField, ForeignKey, etc. |
| 654 | */ |
| 655 | export async function extractDjangoModelsAST( |
| 656 | filePath: string, |
| 657 | content: string |
| 658 | ): Promise<SchemaModel[] | null> { |
| 659 | const result = await runPythonWithStdin(PYTHON_DJANGO_SCRIPT, content, filePath); |
| 660 | if (!result || !Array.isArray(result) || result.length === 0) return null; |
| 661 | |
| 662 | return result.map((m: any) => ({ |
| 663 | name: m.name, |
| 664 | fields: (m.fields || []).map((f: any) => ({ |
| 665 | name: f.name, |
| 666 | type: f.type || "unknown", |
| 667 | flags: f.flags || [], |
no test coverage detected