default database schema and relationships

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

arigold wrote:

i'm a high school teacher

Don't you mean "i ARE a high school teacher"? :wink:

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

Grab /Rails Recipes/, by Chad Fowler, 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.

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

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 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

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.

Here's a helpful blog post I found titled "making a web app rewrite
work"

http://blog.evanweaver.com/articles/2007/02/01/making-a-web-app-rewrite-work

HTH,
Andrew