Skip to content

Instantly share code, notes, and snippets.

@theoretick
Created February 1, 2018 15:55
Show Gist options
  • Save theoretick/112a01768b5ce4fade3457facb687ac9 to your computer and use it in GitHub Desktop.
Save theoretick/112a01768b5ce4fade3457facb687ac9 to your computer and use it in GitHub Desktop.
Generating Entity Relationship Diagrams (ERD) with ruby Sequel and Graphiz
#! /usr/bin/env bash
#
# Usage: ./dot_to_png input.dot output.png
if [ ! -x $(command -v dot) ]
then
echo 1>&2 "dot missing in \$PATH"
echo 1>&2 "Couldn't find graphiz"
exit 2
fi
dot -Tpng "$1.dot" > "$2.png"
#! /usr/bin/env ruby
require "sequel"
require 'sequel_schema_dot_generator'
DB = Sequel.connect("postgres://user:password@localhost:5432/my_database")
File.open("schema_dump_#{Time.now}.dot", "w+") do |file|
file.write(
SequelSchemaDotGenerator::Generator.new(db: DB).generate
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment