# Rails with existing RDBMS schema

**URL:** <https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755>\
**Category:** Rails\
**Created:** [April 13, 2006, 6:39pm UTC](https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755 "2006-04-13T18:39:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [April 13, 2006, 6:39pm UTC](https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755/1 "2006-04-13T18:39:19Z")

</div>

Hi,

I’m seriously considering using Rails to develop several internal  
corporate web apps that will need to interact with well-established  
database systems (3 systems running SQL Server, Oracle, and PostgreSQL).  
The schema on these systems are basically set in stone. Can a Rails  
application interact with an existing schema without serious Rails  
modification? From what I’ve read about Rails, it expects the schema to  
have certain names, entries, and structure.

Has someone developed with Rails in a similar situation? How did it go  
for you?

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [April 13, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755/2 "2006-04-13T18:59:35Z")

</div>

Hi David,

You should be able to use Rails without modifying the Rails code itself.  
Most likely you’ll need to do some extra configuration in your  
application’s  
models. This should help:  
[http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.ht](http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.ht)  
ml

You would also probably use the set\_table\_name macro here:

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000880)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

Daniel

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [April 13, 2006, 7:27pm UTC](https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755/3 "2006-04-13T19:27:11Z")

</div>

David M. \<david.mattes@…\> writes:

> I’m seriously considering using Rails to develop several internal  
> corporate web apps that will need to interact with well-established  
> database systems (3 systems running SQL Server

Works fine, I am doing exact that as we speak, mostly with SQL-server.  
You can  
override the primary key name etc. Of course more you configure, more  
you lose  
the “convention over configuration” advantages of Rails.

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [April 14, 2006, 5:35am UTC](https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755/4 "2006-04-14T05:35:24Z")

</div>

> [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/HowToUseLegacySchemas). There

from what i can tell, this is great for a place that is soo stodgy they  
dont want to ever move to a new schema, or theres too much other legacy  
stuff relying on it…

is there an easy way to cast from one class to another? for example, i  
have a bunch of old data, and id like to make a OldThing and Thing  
class, they would be identical except OldThing would be decorated with  
all the custom SQL, and once the object is read, id like to write it out  
in the shiny new schema format…

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [April 13, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/rails-with-existing-rdbms-schema/57755/5 "2006-04-13T18:59:28Z")

</div>

Yes. I am also building an internal app that interacts with an existing  
database system. It works fine. Check out  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/HowToUseLegacySchemas). There  
isn’t much you need to change in Rails, just more settings to point away  
from the default settings that’s all.

David M. wrote:

> Has someone developed with Rails in a similar situation? How did it go  
> for you?
> 
> Thanks,  
> David

–  
Sau S.

[http://blog.saush.com](http://blog.saush.com)  
[http://read.saush.com](http://read.saush.com)  
[http://jaccal.sourceforge.net](http://jaccal.sourceforge.net)
