I just made first version (0.1.0) of db_discovery_generator.
DB discovery generator allows you to discover exact ( almost exact to be
exact structure of your tables and create the models in app/models
including discovered associations.
If user uses mixedCase field names and unusual (different from id)
primary keys this generator will properly recognize that and will setup
correct table_name and primary_key in the model.
Also it discovers associations between tables and creates correct
At this moment it uses only has_many associations, next versions will be
more clever on this matter, and will use information about foreign keys.
It properly recognizes fields like user_id or UserID and if table users
or user exists it will link them together.
HABTM is not done yet, but in the TODO list.
At this moment it correctly recognizes primary keys only for PostgreSQL
and MySQL, other RDBMSes on the way ( I don’t have an access to them
I created project on RubyForge: http://db-discovery.rubyforge.org and
released files but they are not shown up yet.
At this moment you can download gem and tarball from
If you have any suggestions and ideas do not hesitate to contact me via
At this moment if you will type script/generate db_discovery - it will
start discover right away. If you would like to see the parameters you
have to add --help
All the best!