Rails and Legacy Databases - RailsConf 2009

100 %
0 %
Information about Rails and Legacy Databases - RailsConf 2009

Published on May 8, 2009

Author: napcs

Source: slideshare.net


Slides from my RailsConf 2009 talk showing some methods for using legacy database schemas with the Ruby on Rails framework.

Rails + Legacy Databases Brian Hogan - RailsConf 2009 twitter: bphogan IRC: hoganbp

Please don’t do it!


Just kidding.

Who’s here?

Rails and Legacy database schemas

Anything that doesn’t follow ActiveRecord conventions

This is going to be boring, isn’t it?

I bet Obie’s business panel is awesome.

or that musical patterns one...


Simple(er) solutions with ActiveRecord

Simple problems Person singular person_id table firstname lastname name and middlename prefixed address city ID state zip

Simple solutions Person person_id firstname lastname middlename address city state zip

Bad Column names Person old- person_id school person_name person_email prefixes person_sex

alias_attribute Person person_id person_name person_email person_sex

Uglier Schemas

Really Bad Column Names Person Prefixes! Person id Spaces! Person Name Yikes!! Person e-mail Person sex

Use a View! Person Person id Person Name Person e-mail Person sex

Non-incrementing Keys

Try to add them.

Generate them in your code somehow.


Compound keys

Dr. Nic to the rescue. http://compositekeys.rubyforge.org/

Establish a connection database.yml

Establish a connection environment.rb


Foreign Keys are easy

Working with Legacy Data

Getting even this was a challenge!


Data security • Secure internal network between the database server and the mainframe • Replication to the application database server using Microsoft DTS packages • Access restricted at the table level • Access granted to primary developers via views • Access granted to third-party develpers by stored procedures.

Views are a security tool!

Views are often a performance gain!

Stored Procedures

There’s no direct support for stored procs in ActiveRecord...

...but the connection class will work!

Call a procedure

Get a return value

Get Rows


This is nice.

Biggest problem with Rails and Legacy is “automagical code”

DataMapper Drawbacks?

Doesn’t work well on Windows yet

No Microsoft SQL Server support.

Moving From Legacy

Where are you coming from and where are you going?



Oracle NUMBER datatype is used for integers and floats

DATE is used for Time AND Date.

Oracle NUMBER and CHAR can both be used for :boolean!

Oracle Enhanced Driver • http://github.com/rsim/oracle-enhanced • Raimonds Simanovskis • Good slides on this at http://www.slideshare.net/rsim/using-ruby-on- rails-with-legacy-oracle-databases-presentation

SQL Server SQL Server 2000 and 2005 are very different.

SQL Server TEXT fields with AR are really troublesome.

SQL Server 2000-2005-sqlserver- adapter Ken Collins http://github.com/rails-sqlserver/2000-2005-adapter

Finally, watch out for triggers!

Dealing with Constraints • Avoid using fixtures for tests. They’re bad news anyway • Use .new() and stubs • Duplicate validation / constraints in your code • Use exception handling • Use Stubble - http://github.com/dchelimsky/ stubble

Migrating to a new DBMS • rake db:schema:dump, and then paste that in as a new base migration • sometimes columns aren’t usable this way. Dump schema as SQL and use Regex instead to convert to Ruby.

MS SQL Databases • Tables within different databases on the same server can be joined as if they are in the same database. •

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Rails and Legacy Databases: RailsConf 2009 - O'Reilly ...

Sponsorship Opportunities. For information on exhibition and sponsorship opportunities at RailsConf, contact Yvonne Romaine at yromaine@oreilly.com.
Read more

Rails and Legacy Databases - RailsConf | World History Project

This session will show how we built a Rails application around a database that didn’t even come close to following the conventions that Rails wants you ...
Read more

Rails + Legacy Databases - New Auburn Personal Computer ...

Rails + Legacy Databases Brian Hogan - RailsConf 2009 twitter: bphogan IRC: hoganbp Thursday, May 14, 2009 So the main thing I want you to take away from ...
Read more

Presentations: General: RailsConf 2009 - O'Reilly ...

Presentations: General. ... Rails and Legacy Databases – RailsConf 2009. ... in "Working effectively with legacy Rails code"
Read more

Working Effectively with Legacy Rails Code - RailsConf ...

Working Effectively with Legacy Rails Code ... By Year; By Day; By Year; Quizzes; SEARCH. May 6 2009 2:50PM to 3:40PM ... Rails has powered Oakley.com, ...
Read more

Ruby on Rails - Wikipedia, the free encyclopedia

Ruby on Rails is typically deployed with a database server ... at the RailsConf ... 28, 2009). "Agile Web Development with Rails" ...
Read more

RailsConf Europe 2008 Spreads the Power of Rails

RailsConf Europe 2008 Delivers Advanced Skills to European Rails Community ... database and UI ... The next Rails conference, RailsConf 2009, ...
Read more

A Look at Rails 5 - Engine Yard Blog

A Look at Rails 5 From ... As is tradition, this April at RailsConf 2015 in Atlanta, the creator of Rails, ... Legacy Apps in the Cloud.
Read more

General: Top (13 ideas) – Customer Feedback for RailsConf

Have a suggestion for a topic or speaker for RailsConf 2009? Leave your suggestion here: I think you should have as a topic or speaker ...
Read more