stripe / pg-schema-diff

Go library for diffing Postgres schemas and generating SQL migrations
MIT License
316 stars 23 forks source link

Create way to visualize dependency graph #38

Closed bplunkett-stripe closed 12 months ago

bplunkett-stripe commented 1 year ago

Create a way to visualize dependency graph. I think the best way to implement this is just to modify the Graph data structure to output a graph in some sort of standard graph format that can be ingested by a graph visualization tool, e.g. Graphviz

kevinmingtarja commented 1 year ago

Hi, I'd like to take on this ticket.

bplunkett-stripe commented 1 year ago

Sweet, that would be great. I think the resolution ticket should implement some sort of graph encoder for the Graph struct in this package. It should encode the graph into some common file graph format that can be easily interpreted by an external tool like GraphViz.

I'lll leave the choice of graph file format up to you.

Feel free to respond to this ticket with any questions you might have!

kevinmingtarja commented 1 year ago

Thanks for the pointers!

One quick question, when do you think we should generate this graph output? Some options would be:

As for the graph format, I'll go with the format that GraphViz accepts, as you recommended, which is .dot. pprof also uses the same format.

bplunkett-stripe commented 1 year ago

That's an interesting thought! I was planning on making this just internal to the library, since it's really most relevant for internal debugging, but I imagine it could be useful as a debugging step if a user runs into some sort of bug with the SqlGeneration.

For one PR, just implement it internally and don't worry about exposing it to users, since that's where the core value is. Let's think about the best way we can expose this while you implement the actual encodinjg. Maybe a --debug--output-graph param would make sense on the plan command.