Magic Model Generator

Tháng Ba 26, 2009

Dr Nic is a great guy :)

Source: http://magicmodels.rubyforge.org/magic_model_generator/

./script/generate magic_model

What

Imagine you get offered $5,000 to write a basic website/admin application on a legacy database that has 200 interconnected tables. You’ll need to add all the associations and validations based on the existing schema.

Imagine how long that would take! 1 day? 1 week? more?

Try 1 minute.

The Magic Model Generator does all this for you automatically.

Installing

$ sudo gem install magic_model_generator

Quick demo

Create a rails application, and point it to your database.

$ rails magic_show -d [mysql|sqlite|postgresql|oracle|etc|etc]
$ cd magic_show
$ cp database.yml.sample database.yml
and point it to your database.yml to your legacy database

In the video below I use the database created for the ActiveRecord test cases – activerecord_unittest. If you’ve never downloaded the activerecord gem, run:

$ rake build_[mysql|sqlite|postgresql|oracle|etc|etc]_databases
$ rake test_[mysql|sqlite|postgresql|oracle|etc|etc]

Now install the magic_model_generator gem:

$ sudo gem install magic_model_generator

By the way, that’s all the preparation I did for the video.

Now recreate the schema.rb file and the schema_info database table via

$ rake db:migrate

.

Finally, run the generator:

$ ./script/generate magic_model

Coming

Currently rails_generators cannot merge results into existing files, only skip or overwrite. I am investigating a fix for this so that you can use the MMG for iterative development.

Related articles

  • Original release at RejectConf –

Similar ideas

Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

%d bloggers like this: