RMRE - rails models reverse engineering gem
Very often I have to work on databases which do not follow ActiveRecord convention and making ActiveRecord models, if number of tables is large, is very slow and boring task. In order to speed up and simplify it I’ve created Rmre gem. Gem is quite simple yet you might find it useful if you want to create fixtures, migrations or simply port application to Ruby on Rails.
So how it works? For each table in the database, gem creates model. Name of the model is created using Rails classify method. Moreover, if table’s primary key is not column named “id” gem sets primary key by adding set_primary_key "primaryKeyColumnName" line to the model. In addition for MySQL, PostgreSQL, Oracle or MS SQL foreign keys are analyzed and for each constraint gem generates belongs_to or has_many lines. Here is model created for table store in Sakila MySQL test database:
1 2 3 4 5 6 7 8 9 |
class Store < ActiveRecord::Base set_primary_key :store_id set_table_name 'store' has_many :customers, :class_name => 'Customer' has_many :inventories, :class_name => 'Inventory' has_many :staffs, :class_name => 'Staff' belongs_to :address, :class_name => 'Addres', :foreign_key => :address_id belongs_to :staff, :class_name => 'Staff', :foreign_key => :manager_staff_id end |


November 01, 2010 at 1:12 PM
I tried to use this gem, inside my application dir, but when I typed:
rmre -a postgresql -d Pessoa -u postgres -p <I_put_my_pass_here> -o /app/models
I got the error:
... generator.rb:29:in 'create models':undefined method 'exists?' for Dir:Class (NoMethodError)
Can you help me?
November 01, 2010 at 1:59 PM
Can you tell me which Ruby do you use, which OS? Rmre works with ActiveRecord 3.0 version thus with Ruby 1.9. Have you tried it with Ruby 1.8.x maybe?
March 10, 2011 at 12:02 AM
Any example for Oracle database?
March 10, 2011 at 7:07 PM
What example do you mean exactly? Gem is working on Oracle just same as it works on any database that is supported by ActiveRecord. Particularly, for Oracle you need oci8 and oracle_enhanced gems. Configuration depends on your Oracle installation and should look similar to this:
adapter: oracle_enhanced
database: localhost/xe
username: <your_username>
password: <your_password>
June 29, 2011 at 6:12 PM
Hi How do you use this when reverse engineering tables in a schema within a database? Thanks!
June 30, 2011 at 7:33 PM
I'm not sure what exactly you want to achieve but if you want to dump database schema use --dump-schema option. This will create script to easily re-create database (only structure, not data).
February 29, 2012 at 2:52 AM
Hi there.
I need to reverse engineer a remote postgresql database.
My database.yml connections all connect to this remote server.
Is this possible or are there plans to include this functionality in rmre ?
December 06, 2012 at 10:29 PM
Bosko - I was very excited to find this gem but haven't been able to use it with Jruby and Oracle. Jruby doesn't use oci8.
The message here is login failed even though the login information is correct. It's Oracle 10.2.
>> rmre -a oracle_enhanced -d database -u username -p password -o app/models -p 1521 -s servername
>> ORA-01017: invalid username/password; logon denied
December 07, 2012 at 3:29 AM
In response to my own post, the issue was having two values for the same named parameter -p (dash 'p').
Because password and port number are both inputted with -p, the last value of -p is the one being used.
The fix was to use the canonical parameter names.
>> rmre --adapter oracle_enhanced --database database --user user --password pass --port 1521 --host servername
>> Generating models...
Now I am simply waiting for rmre to generate 471 models for me.
December 10, 2012 at 2:21 PM
Hello! caeaddd interesting caeaddd site! I'm really like it! Very, very caeaddd good!
December 10, 2012 at 2:22 PM
Very nice site!
December 10, 2012 at 2:22 PM
Hello! febcded interesting febcded site! I'm really like it! Very, very febcded good!
December 10, 2012 at 2:22 PM
Very nice site!
April 08, 2013 at 9:22 PM
We are convinced We have see this identical form of statement anywhere else, it must be gaining popularity with all the masses.