## Generating an ERD The corgi CLI supports generating an ERD from database data. The auto-generated ERD, as well as a small description, replaces the README section labeled `## CORGI ERD`. ### Running the script Assuming you have the CORGI stack running and you are in the root of the repository, you can generate an ERD like this: ```bash # Create some sample data if you have not already ./corgi create-jobs # Generate the ERD and update the README ./corgi create-erd ``` ### How it works This will run the [generate-erd](https://github.com/openstax/corgi/tree/main/scripts/generate-erd.py) script which attempts to crawl all database entities, starting with `Jobs` entity, and collect information about their fields and relationships. From this, the script generates an ERD using mermaid diagram syntax. An awk script replaces the section in the README with the newly generated ERD. ### Limitations (TODO?) * Does not specify which fields are primary or foreign keys * When an optional field is None, it cannot infer the data type (uses `opt` as placeholder type) * Annoyingly, in mermaid ERD syntax `relationship-label` is [required](https://mermaid.js.org/syntax/entityRelationshipDiagram.html#entities-and-relationships). Since that is non-trivial to auto-generate, it is set to "" (empty string).