3

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?

3 Answers 3

9

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.

2

did you try rake --trace?

By the way Oracle legacy schemas is a small cottage industry.

http://github.com/rsim/legacy_oracle_sample.git/README.txt

http://blog.rayapps.com/2008/06/28/activerecord-oracle-enhanced-adapter-version-111-released/

http://www.oracle.com/technology/pub/articles/saternos-rails.html

http://redsquirrel.com/cgi-bin/dave/dynamic/rails.multiple.oracle.dbs.html

0
1

update: this only fail if you use ", :require => false". Removing this param, work as expected.

This really should work?

~/Projects/test (master) $ rake db:structure:dump
(in /Users/plentz/Projects/test)
rake aborted!
Task not supported by 'oracle_enhanced'

(See full trace by running task with --trace)

Gemfile

gem 'activerecord-oracle_enhanced-adapter', :require => false

Using activerecord-oracle_enhanced-adapter (1.3.2) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.