Geert: “Geert's an Enterprise Entity Relation Tracker”

Find missing foreign keys in ActiveRecord and create a migration to add them.

Usage

Go to your Rails application and type the command:

geert

And you'll get all the possible migrations you can have for your application. Run “geert -h” for all possible options.

A note of caution

Foreign key constraints have a real impact on your application. Geert can't always see the difference between the desired and unwanted foreign keys. It does try to get the proper type of constraint (restrict, nullify or delete), but that might not be what you want. A properly tested application will help you.

Generating an ERD

See a sample of the generated ERD here, based on Webistrano:

http://github.com/finalist/geert/blob/master/sample-erd.png

Click on raw for full size. Can't link directly, because github will show it directly, which is rather awkward.

If you run on a Mac, this is really easy. You'll might have to sacrifice a database for it, and you'll need at least graphviz and Sequel Pro.

  • Run geert

  • Migrate your database, apply all foreign keys for the best effect.

  • Open the database in Sequel Pro

  • Select: File -> Export -> Graphviz dotfile

  • Save the dotfile

  • In the console:

    dot -Tsvg your_database.dot > your_database.svg
    
  • If you have librsvg installed, you can also generate a png file:

    dot -Tsvg your_database.dot | rsvg-convert -o your_database.png
    

You can find these applications here:

  • Sequel Pro: sequelpro.com

  • Graphviz: graphviz.org

  • librsvg: sudo port install librsvg (warning, has a lot of X11 dependencies)

Installation

To install geert:

gem install geert --source http://gemcutter.org

It requires the foreigner gem as well, so please install that into your project, before running the “geert” command.

In Rails < 3, edit config/environment.rb:

config.gem "matthuhiggins-foreigner", :lib => "foreigner", :source => "http://gemcutter.org"

In Rails 3, edit your Gemfile:

gem "matthuhiggins-foreigner", :require_as => "foreigner"

See github.com/matthuhiggins/foreigner for more info about foreigner.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Iain Hecker. Released under the MIT License.