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:
# 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 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
optas placeholder type)Annoyingly, in mermaid ERD syntax
relationship-labelis required. Since that is non-trivial to auto-generate, it is set to “” (empty string).