Published on May 8, 2009
Rails + Legacy Databases Brian Hogan - RailsConf 2009 twitter: bphogan IRC: hoganbp
Please don’t do it!
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 ﬁrstname lastname name and middlename preﬁxed address city ID state zip
Simple solutions Person person_id ﬁrstname lastname middlename address city state zip
Bad Column names Person old- person_id school person_name person_email preﬁxes person_sex
alias_attribute Person person_id person_name person_email person_sex
Really Bad Column Names Person Preﬁxes! Person id Spaces! Person Name Yikes!! Person e-mail Person sex
Use a View! Person Person id Person Name Person e-mail Person sex
Try to add them.
Generate them in your code somehow.
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!
THIS IS NOT ALL THE DATA.
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!
There’s no direct support for stored procs in ActiveRecord...
...but the connection class will work!
Call a procedure
Get a return value
This is nice.
Biggest problem with Rails and Legacy is “automagical code”
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 ﬂoats
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 ﬁelds 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 ﬁxtures 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. •
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...
Sponsorship Opportunities. For information on exhibition and sponsorship opportunities at RailsConf, contact Yvonne Romaine at email@example.com.
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 ...
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 ...
Presentations: General. ... Rails and Legacy Databases – RailsConf 2009. ... in "Working effectively with legacy Rails code"
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, ...
Ruby on Rails is typically deployed with a database server ... at the RailsConf ... 28, 2009). "Agile Web Development with Rails" ...
RailsConf Europe 2008 Delivers Advanced Skills to European Rails Community ... database and UI ... The next Rails conference, RailsConf 2009, ...
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.
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 ...