# Default database schema and relationships

**URL:** <https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375>\
**Category:** Rails\
**Created:** [February 13, 2007, 1:59am UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375 "2007-02-13T01:59:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arigold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@arigold](https://www.ruby-forum.com/u/arigold)\
**Post date:** [February 13, 2007, 1:59am UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375/1 "2007-02-13T01:59:44Z")

</div>

hi everyone…

i’m a high school teacher who wrote a webapp in PHP and MySQL for my  
curriculum… i use it to keep attendance, take notes per student or  
class and keep track of activities. i would like to soup it up and  
have read both the pickax and version 2 of agile web dev…

now i’m starting to work and i’d like to rename columns and  
relationships in the database so that when i create rails  
functionality to work with the database i can use the same database.  
yep, i dont want to copy the data to a new database and have two apps  
and two databases but its live - im using it daily. i’d like to  
slowly move the functionality to the rails app and eventually just  
archive the PHP one. but before i do that i have to switch my primary  
keys to the rails defaults and the join tables and all that jazz to  
the rails defaults…

i’m not worried about the data because i back it up and if all else  
fails i’ll just do the ol’ INSERT INTO or UPDATE commands in terminal.

all that being said (phew) are the different defaults for rails in  
terms of column types (id type, etc) and singular plural conventions  
kept in one place somewhere? has anyone made a list? ive searched  
the web quite a bit and was going to start going through v2 of agile  
web dev but i thought i’d try an email before i got too into it…

sorry for the long background but i thought it best to be thorough…

thanks…~ari

---

<div class="post-metadata">

**Author:** ![arigold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@arigold](https://www.ruby-forum.com/u/arigold)\
**Post date:** [February 14, 2007, 1:35am UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375/2 "2007-02-14T01:35:17Z")

</div>

thank you philip…

dont quite get the “i ARE a high school teacher” joke but maybe thats  
because i just got home and had back to back 10th and 9th graders.  
maybe, just maybe 14 - 16 year olds arent biologically able to be  
focused after 8 hours of school… hmm… ; )

i just might get that rails recipes book but from your short answer i  
dont think that it answers my question. it seems like you’re looking  
to bend rails to the legacy database. i want to - yes its true - bend  
the legacy database to rails’ defaults. i want to change the ID  
column from “student\_id” to “id”. actually, ive done that one  
already… im wondering what other things i’ll need to change in the  
legacy database to make it comply with the rails defaults.

any ideas?

in any event, thanks for pointing that book out…

all the best…~ari

---

<div class="post-metadata">

**Author:** ![arigold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@arigold](https://www.ruby-forum.com/u/arigold)\
**Post date:** [February 13, 2007, 6:08am UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375/3 "2007-02-13T06:08:12Z")

</div>

arigold wrote:

> i’m a high school teacher

Don’t you mean “i ARE a high school teacher”? 😉

> have read both the pickax and version 2 of agile web dev…

Grab /Rails Recipes/, by Chad F., and hie thee hence to page 73,  
“Integrating with Legacy Databases”. The shortest answer is you must  
start  
using all the defaults that you currently leave out of the ActiveRecord  
calls. Google for ActiveRecord::Base.set\_primary\_key or  
.table\_name\_prefix  
for a preview.

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![arigold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@arigold](https://www.ruby-forum.com/u/arigold)\
**Post date:** [February 14, 2007, 1:47am UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375/4 "2007-02-14T01:47:18Z")

</div>

> kept in one place somewhere? has anyone made a list? ive searched

I don’t know if there is a list, but if someone else knows, that would  
be a  
good resource to share. I would recommend using [api.rubyonrails.com](http://api.rubyonrails.com) and  
looking at the following relationships (listed in the lower left pane):

belongs\_to  
has\_and\_belongs\_to\_many  
has\_many  
has\_one

I think all give notes on database structure.

-andy

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![arigold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@arigold](https://www.ruby-forum.com/u/arigold)\
**Post date:** [February 14, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375/5 "2007-02-14T16:39:50Z")

</div>

arigold wrote:

> dont quite get the “i ARE a high school teacher” joke

You were permitting sloppy grammar…

> …comply with the rails defaults…

Rails practices “Convention over Configuration”. Those are not  
defaults they are conventions, and if you convene or configure Rails  
differently, it will obey.

Your best bet would be a combination of that chapter in /Rails  
Recipes/ and database migrations. Pick whichever is easiest, for each  
detail of non-compliance.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![arigold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@arigold](https://www.ruby-forum.com/u/arigold)\
**Post date:** [February 14, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/default-database-schema-and-relationships/85375/6 "2007-02-14T17:42:57Z")

</div>

Here’s a helpful blog post I found titled “making a web app rewrite  
work”

> **[making a web app rewrite work](https://blog.evanweaver.com/2007/02/01/making-a-web-app-rewrite-work/)**
>
> One of my friends was recently involved in a very large Rails rewrite project that failed pretty abjectly. Meanwhile, at CNET, we just deployed a total overhaul of a crufty old Rails app, replacing…

HTH,  
Andrew
