Skip to content

Commit f880c14

Browse files
committed
only use --structured option for this update and make that default
1 parent e23750d commit f880c14

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,39 @@ This will generate a text file with the GraphViz DOT representation of the ER di
9696

9797
### Structured Text Output for AI Models
9898

99-
If you want to generate a structured text representation of the ER diagram that is more suitable for AI models, you can use the `--structured` option:
99+
If you want to generate a structured text representation of the ER diagram that is more suitable for AI models, simply specify a filename with a `.txt` extension:
100100

101101
```bash
102-
php artisan generate:erd output.txt --structured
102+
php artisan generate:erd output.txt
103103
```
104104

105-
This will generate a Markdown file with a structured representation of the entities and their relationships, which can be used as context for AI models.
105+
This will automatically generate a Markdown file with a structured representation of the entities and their relationships, which can be used as context for AI models.
106+
107+
#### Output Format
108+
109+
The structured output format looks like this:
110+
111+
```markdown
112+
# Entity Relationship Diagram
113+
114+
## Entities
115+
116+
### User (`App\Models\User`)
117+
118+
#### Attributes:
119+
- `id` (integer)
120+
- `name` (string)
121+
- `email` (string)
122+
...
123+
124+
## Relationships
125+
126+
### User Relationships
127+
- **HasMany** `posts` to Post (Local Key: `id`, Foreign Key: `user_id`)
128+
...
129+
```
130+
131+
This format is particularly useful when providing context to AI models about your database structure.
106132

107133
## Customization
108134

src/GenerateDiagramCommand.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GenerateDiagramCommand extends Command
1919
*
2020
* @var string
2121
*/
22-
protected $signature = 'generate:erd {filename?} {--format=png} {--text-output : Output as text file instead of image} {--structured : Generate structured text output for AI models}';
22+
protected $signature = 'generate:erd {filename?} {--format=png} {--text-output : Output as text file instead of image}';
2323

2424
/**
2525
* The console command description.
@@ -70,13 +70,14 @@ public function handle()
7070
);
7171
});
7272

73-
// If structured text output is requested, generate it
74-
if ($this->option('structured')) {
73+
// Check if output filename has .txt extension
74+
$outputFileName = $this->getOutputFileName();
75+
if (pathinfo($outputFileName, PATHINFO_EXTENSION) === 'txt') {
76+
// Generate structured text output for .txt files
7577
$textOutput = $this->graphBuilder->generateStructuredTextRepresentation($models);
76-
$outputFileName = $this->getTextOutputFileName();
7778
file_put_contents($outputFileName, $textOutput);
7879
$this->info(PHP_EOL);
79-
$this->info('Wrote structured text diagram to ' . $outputFileName);
80+
$this->info('Wrote structured ER diagram to ' . $outputFileName);
8081
return;
8182
}
8283

@@ -99,10 +100,10 @@ public function handle()
99100
return;
100101
}
101102

102-
$graph->export($this->option('format'), $this->getOutputFileName());
103+
$graph->export($this->option('format'), $outputFileName);
103104

104105
$this->info(PHP_EOL);
105-
$this->info('Wrote diagram to ' . $this->getOutputFileName());
106+
$this->info('Wrote diagram to ' . $outputFileName);
106107
}
107108

108109
protected function getOutputFileName(): string

tests/GenerationTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function it_generated_graphviz_in_jpeg_format()
6060
}
6161

6262
/** @test */
63-
public function it_generates_text_output_file()
63+
public function it_generates_text_output_file_with_text_output_option()
6464
{
6565
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
6666

@@ -90,7 +90,7 @@ public function it_generates_text_output_file()
9090
}
9191

9292
/** @test */
93-
public function it_generates_structured_text_output_file()
93+
public function it_generates_structured_text_output_for_txt_extension()
9494
{
9595
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
9696

@@ -102,12 +102,11 @@ public function it_generates_structured_text_output_file()
102102
}
103103

104104
Artisan::call('generate:erd', [
105-
'filename' => $outputFile,
106-
'--structured' => true
105+
'filename' => $outputFile
107106
]);
108107

109108
$this->assertFileExists($outputFile);
110-
$this->assertStringContainsString('Wrote structured text diagram to ' . $outputFile, Artisan::output());
109+
$this->assertStringContainsString('Wrote structured ER diagram to ' . $outputFile, Artisan::output());
111110

112111
// Check if the file contains structured Markdown content
113112
$fileContent = file_get_contents($outputFile);

0 commit comments

Comments
 (0)