# Legacy databases and migrating

**URL:** <https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310>\
**Category:** Rails\
**Created:** [November 9, 2006, 12:53am UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310 "2006-11-09T00:53:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 12:53am UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/1 "2006-11-09T00:53:03Z")

</div>

Working on a project where the database will be migrated from MS SQL  
Server  
to MySQL. All fine, however the client  
is requesting that the schema remains the same. This means that table  
names  
are not pluralized and id is not just ‘id’ but  
the table name and id (i.e. table\_id)  
All in all it’s not a huge database, I’m looking at 30 tables total, but  
want to consider first the extra work I’ll have to do to make  
it all play together nicely. Any opinions ?  
and if I remember correctly from AWDWR the id column is probably not a  
big  
deal, but the singular table names disturb me.

TIA  
Stuart

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 4:57am UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/2 "2006-11-09T04:57:21Z")

</div>

Stuart Fellowes wrote:

> Working on a project where the database will be migrated from MS SQL  
> Server  
> to MySQL. All fine, however the client  
> is requesting that the schema remains the same. This means that table  
> names  
> are not pluralized and id is not just ‘id’ but  
> the table name and id (i.e. table\_id)  
> All in all it’s not a huge database, I’m looking at 30 tables total, but  
> want to consider first the extra work I’ll have to do to make  
> it all play together nicely. Any opinions ?  
> and if I remember correctly from AWDWR the id column is probably not a  
> big  
> deal, but the singular table names disturb me.
> 
> TIA  
> Stuart
> 
> –  
> [http://en.wikipedia.org/wiki/Dark\_amb](http://en.wikipedia.org/wiki/Dark_amb)

Stuart, on the table names, here is a quote from page 191 of the Agile  
Rails book:  
"TheserulesreflectDHHâ€™sphilosophythatclassnamesshouldbesingular  
whilethenamesof tablesshouldbeplural. If youdonâ€™tlikethisbehavior,  
youcandisableit bysettingaglobal flaginyour configuration(thefile  
environment.rbintheconfigdirectory).  
ActiveRecord::Base.pluralize\_table\_names= false "  
(sorry about the wacky formatting there, Mac “Preview” or “Safari” bug I  
guess)

best,  
jp

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/3 "2006-11-09T13:12:26Z")

</div>

In my case I made a small Ruby script who uses DBI interface.  
It keeps connection to old and new databases ( in may case that was the  
same flavor - PgSQL ) and  
recreates the model from legacy MixedCase way to RoR way, including data  
migration.

This script somewhat generalized, but this is possible to do more  
generalization to make it possible to port from  
one DB flavor to other.

PS: I spent few hours for that script and it saves me a days of hassle  
🙂

All the Best!  
Sergey.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 3:57pm UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/4 "2006-11-09T15:57:05Z")

</div>

Since I am always having to work with some old, legacy schema, I do  
this as a matter of course on all my model files:

class MyClass \< ActiveRecord::Base  
set\_table\_name ‘whatevernameIwant’  
set\_primary\_key ‘nameOfPrimaryKeyColNeedntBeid’  
end

Then you;re good to go. -Ralph

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/5 "2006-11-09T19:15:54Z")

</div>

Wait – Isnt MySQL not case sensitive (at least \<5.0, and I believe

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/6 "2006-11-09T17:07:18Z")

</div>

Ike wrote:

> Since I am always having to work with some old, legacy schema, I do  
> this as a matter of course on all my model files:
> 
> class MyClass \< ActiveRecord::Base  
> set\_table\_name ‘whatevernameIwant’  
> set\_primary\_key ‘nameOfPrimaryKeyColNeedntBeid’  
> end
> 
> Then you;re good to go. -Ralph

Not true. It works quite good for most of the cases but not all of them.  
If your column name starts with capital letter, then it starts to srew  
up a lot of plagins that expecting  
behavior like record.filedName or record.field\_name because in this case  
Ruby has conversation that  
if first letter is capital then it’s a constant. in this case you can  
get it only by record[‘FieldName’],  
so you see my point here.

That was my reason to make a script that converts tables from MixedCase  
to lower\_case

All the Best!  
Sergey.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/7 "2006-11-09T19:19:54Z")

</div>

Ike wrote:

> Wait – Isnt MySQL not case sensitive (at least \<5.0, and I believe
> 
> > =5.0 that can be specified) so why not make them all be lowercase in your rails app? -Ralph

Because I am using PostgreSQL, and this RDBMS is case sensitive. So the  
same can be true for other flavors such as Oracle.

All the Best!  
Sergey.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 12, 2006, 1:29pm UTC](https://www.ruby-forum.com/t/legacy-databases-and-migrating/75310/8 "2006-11-12T13:29:40Z")

</div>

Sergey,

Would you mind posting the script here, or is it proprietary?  
Thanks.
