New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JUJU-553] Add tool to infer entity schemas and render a ER-like diagram using graphviz #13694
[JUJU-553] Add tool to infer entity schemas and render a ER-like diagram using graphviz #13694
Conversation
95d72d8
to
4ea9eb0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
LGTM
The tool parses the contents of the state package and emits an ER-like diagram in dot notation. The generated diagram can then be fed into graphviz to render the diagram. For example: go run infer_schema.go | circo -o er.svg -Tsvg
4ea9eb0
to
563963a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also expand nested types, for example:
graph {
charm [shape=record, label=<{<b>charm</b><br/>github.com/juju/juju/state/charm.go | doc_id (string) | url (*charm.URL) | charm_version (string) | life (Life) | pending_upload (bool) | placeholder (bool) | bundle_sha256 (string) | storage_path (string) | macaroon ([]byte) | meta (*charm.Meta) | config (*charm.Config) | manifest (*charm.Manifest) | actions (*charm.Actions) | metrics (*charm.Metrics) | lxdprofile (*LXDProfile)}>];
}
Can we expand "manifest (*charm.Manifest)"?
See the future work/suggestion list. Ideally we would want to identify complex types and create aux tables from them. So in this example, we would have a manifests table and the charm would have a FK to the manifest ID. Not sure how much effort that would require though... I will play around with this idea and see how far I get. |
|
|
|
1 similar comment
|
This PR contributes a CLI tool that analyzes the set of structs defined in Juju's
state
package and attempts to generate an ER-like diagram to aid with the data modeling work which is part of the transition from mongo to sqlite.The actual diagram looks more like a UML class diagram as the number of entities (tables) and attributes makes it more difficult for graphviz to figure out a suitable layout for the graph nodes.
The tool automatically normalizes both table and field names to the underscore-cased format that folks are more familiar with when working with SQL databases. In addition, the tool will attempt to cluster together tables that share a common name prefix.
Future work ideas/suggestions:
QA steps
Yields something like this: