Hobo Cookbook

View Source

Question: Question Importing an existing database schema

Markdown Asks lmorris99
I have a MySQL database already created and populated.
I was using ActiveScaffold, so it's a nice Rails database with _id fields for foreign keys, etc.
I'd like to let Hobo generate its normal UI against this existing database.

I guess one way to do it is to write a script that reads the existing table and field names, and spits out a lot of
* ruby script/generate hobo_model_resource TABLEA FIELDA1:type FIELDA2:type ...
* ruby script/generate hobo_model_resource TABLEB FIELDB1:type FIELDB2:type ...

where TABLE and FIELD names come from the existing database layout.

Is there a better way? Perhaps using the existing schema.rb?

Discussion

  • You don't need to do that much. Just

    - `ruby script/generate hobo_model_resource TABLEA`
    - `ruby script/generate hobo_model_resource TABLEB`

    et cetera. Hobo uses reflection to pull in the column names and types. The "fields" definition in a Hobo model is pretty much only used for migrations and for rich types, so is optional on a hobo model, so just use it for rich types. This assumes that your schema is pretty final so it'll be easier for you to manually generate your migrations rather than fully populate every fields definition.