views:

2425

answers:

2

Does anyone know of any specific DSL implementations used to import legacy Oracle database schemas. I have tried to just run db:schema:dump on my existing db I want to port to a new ruby app. However, the rake dies about halfway through with out any error. It kinda just locks up. I started looking for the best way to tackle this and found examples of how to override some stuff for SQLServer but not much for Oracle.

I basically want to pull in the schema and generate a scaffold and model from it.

Is there a more simple way to do this or will I have to invent the wheel?

+4  A: 

The firs question - are you using original ActiveRecord Oracle adapter or oracle_enhanced adapter (http://github.com/rsim/oracle-enhanced)? I recommend to use oracle_enhanced adapter as I made there some performance improvements for schema dump.

Rails provides two ways for schema dump:

rake db:schema:dump

This will create schema.rb file with Rails migrations for schema creation. In Oracle case it will search for all tables in user local schema (user is specified in database.yml) and will try to translate Oracle data types to Rails model attribute types. If you have some data types which are not supported by Rails then you might loose them. But if you want to reengineer your application in Rails way then this is preferred approach. As I said I made some performance improvement in oracle_enhanced adapter for schema dump in case of large Oracle data disctionaries (if you have thousands of tables in all schemas).

rake db:structure:dump

This will create SQL schema file (e.g. db/development_structure.sql) which you can execute in other Oracle database (this will not work on other databases). This might be faster way to create schema dump and it will not lose Oracle specific data types. But in this way you can get into trouble later when you will use ActiveRecord with this database and then will notice that some data types are not processed correctly. Therefore I recommend to use Rails migration to maintain schema and not raw SQL.

But if you want to use Rails with some existing Oracle database then you don't need to recreate this schema - you can just point database.yml to this existing database schema and start to create ActiveRecord models on top of existing tables. See http://blog.rayapps.com/2008/09/26/openworld-unconference-presentation-about-rails-on-oracle/ for some tips how to use Rails with legacy Oracle databases.

Raimonds Simanovskis