Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Following the ERD: How to Map Your Software

Kerri Miller
September 15, 2018

Following the ERD: How to Map Your Software

Kerri Miller

September 15, 2018
Tweet

More Decks by Kerri Miller

Other Decks in Programming

Transcript

  1. digraph G { subgraph cluster_0 { style=filled; color=lightgrey; node [style=filled,color=white];

    a0 -> a1 -> a2 -> a3; label = "process #1"; } subgraph cluster_1 { node [style=filled]; b0 -> b1 -> b2 -> b3; label = "process #2"; color=blue } start -> a0; start -> b0; a1 -> b3; b2 -> a3; a3 -> a0; a3 -> end; b3 -> end; start [shape=Mdiamond]; end [shape=Msquare]; } @kerrizor CodeDaze 2018
  2. @kerrizor CodeDaze 2018 E X T R A C T

    I N G M O D E L R E L AT I O N S H I P S • Ask the DB/Parse the schema • Parse model definitions in the framework
  3. @kerrizor CodeDaze 2018 E X T R A C T

    I N G M O D E L R E L AT I O N S H I P S • Ask the DB/Parse the schema • Parse model definitions in the framework
  4. @kerrizor CodeDaze 2018 E X T R A C T

    I N G M O D E L R E L AT I O N S H I P S • Ask the DB/Parse the schema • Parse model definitions in the framework • Have the framework introspect for you
  5. @kerrizor CodeDaze 2018 g = GraphViz.new(:G, type: :digraph) models =

    ActiveRecord::Base.descendants assoc = models.first.reflect_on_all_associations.collect{|r| r.klass.to_s.downcase}.uniq # Raise your left hand if you’re reading this # user = g.add_nodes("User") assoc.each do |a| g.add_edges(user, g.add_nodes(a)) end g.output(png: "example.png")
  6. @kerrizor CodeDaze 2018 digraph G { graph [bb="0,0,362.83,108"]; node [label="\N"];

    user [height=0.5, label=user, pos="177.66,90", width=0.75]; Article [height=0.5, label=Article, pos="34.66,18", width=0.96276]; user -> Article [pos="e,59.965,30.741 155.94,79.065 132.88,67.452 96.092,48.931 69.076,35.328"]; Favorite [height=0.5, label=Favorite, pos="126.66,18", width=1.0994]; user -> Favorite [pos="e,138.9,35.277 166.09,73.662 159.81,64.805 151.92,53.658 144.84,43.67"]; […]
  7. @kerrizor CodeDaze 2018 g = GraphViz.new(:G, type: :digraph) models =

    ActiveRecord::Base.descendants assoc = models.first.reflect_on_all_associations.collect{|r| r.klass.to_s.downcase}.uniq user = g.add_nodes("User") assoc.each do |a| attrs = a.classify.constantize.attribute_names label = "#{a}\n#{attrs.join("\n")}" g.add_edges(user, g.add_nodes(label)) end g.output(png: "example_with_labels.png")
  8. @kerrizor CodeDaze 2018 “ ” THE MAP IS NOT THE

    TERRITORY… THE WORD IS NOT THE THING… - ALFRED KORZYBSKI M A P - T E R R I T O RY R E L AT I O N
  9. @kerrizor CodeDaze 2018 A N D I F Y O

    U A C T N O W… • Visual documentation for GraphQL • Shortcut for loading context • “Living Documentation”
  10. @kerrizor CodeDaze 2018 “ ” WHEN YOU CHANGE THE WAY

    YOU LOOK AT THINGS, THE THINGS YOU LOOK AT CHANGE. - DR WAYNE W DYER M A P - T E R R I T O RY R E L AT I O N
  11. @kerrizor CodeDaze 2018 M A P - T E R

    R I T O RY R E L AT I O N