[ANN] db_discovery generator gem

Hi Everyone,

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 :slight_smile: 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
belongs_to/has_many links.

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 :slight_smile:

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
http://db-discovery.deeptown.org.

If you have any suggestions and ideas do not hesitate to contact me via
email.

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
switch.

All the best!
Sergey.

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
switch.

All the best!
Sergey.

Sounds good, I will play with it soon. When I try to install I get the
following error:

02:29:44:~ > sudo gem install db_discovery
Need to update 24 gems from http://gems.rubyforge.org
…
complete
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find db_discovery (> 0) in the repository

I don’t know how to put it to rubyforge gem repository. It’s on my web
server yet, and in release files on db-discovery.rubyforge.org

All the Best!
Sergey.

How do I install this?

Fixed few minor bugs, put it as version 0.1.1.

If you start it without parameters it shows help, to do the actual
discovery you have to provide --discover
flag.

It generates fixtures and unit tests.

All the Best!
Sergey.

Very nice, I did almost exactly the same thing described here…

http://blog.wolfman.com/articles/2006/05/24/create-models-from-ddl

but your looks better and cleaner, and doesn’t use DDL.

However you may get ideas from mine I do handle HABTM, and I add some
validations too where I can
figure them out.

I’ll link to yours on my blog as I think it is a better solution.

Sergey K. wrote:

At this moment it correctly recognizes primary keys only for PostgreSQL
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
switch.

All the best!
Sergey.

–
Jim M., http://blog.wolfman.com

Jim,

Jim M. wrote:

Very nice, I did almost exactly the same thing described here…

Wolfmans Howlings

but your looks better and cleaner, and doesn’t use DDL.

Thanks a lot for your kind words! I definitely will think how to use
your ideas.
In case of Rails convention based HABTM this is not a problem to create
HABTM relation.
I will have one more pass through the model classes to distinguish this
relation. In other case
I have to check if the names are the same, or if there is a foreign keys
to that table from
both referrers, or record names in HABTM table belongs to that tables,
and there is no more
fields in that table.

However you may get ideas from mine I do handle HABTM, and I add some
validations too where I can figure them out.

I want to add validations as well such as validate_presence_of and so on
based on NULL/NOT NULL and
field type.

I’ll link to yours on my blog as I think it is a better solution.

Thanks a lot! I appreciate that.

All the Best!
Sergey.

Just type:

gem install db_discovery_generator

It’s already on rubyforge gem repository,

All the Best!
Sergey.