Forum: Ruby on Rails modifing db

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mk 2. (Guest)
on 2009-05-21 22:20
If I am going to build a sql database for use in rails (rather than
building it in rails), is there anything I need to know beyond using an
id column in every table?  Does the id need to be the "primary key"?
Maurício L. (Guest)
on 2009-05-21 22:22
(Received via mailing list)
Yes, the id needs to be the primary key.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
Manasi V. (Guest)
on 2009-05-21 22:25
Mk 27 wrote:
> If I am going to build a sql database for use in rails (rather than
> building it in rails), is there anything I need to know beyond using an
> id column in every table?  Does the id need to be the "primary key"?

By convention, rails would look for an id as a primary key for all
tables. Also, if you use rails migrations to generate the tables, you
can say -
create_table(:table_name, :id => false) if you don't want id.
This might be required in case your table is from a legacy system.

Thanks
E. Litwin (Guest)
on 2009-05-21 22:25
(Received via mailing list)
The id should be an auto-incrementing primary key.
Also, column names should be lower cased using an underscore to
separate words, i.e. first_name
You should also consider adding "created_at" and "updated_at" datetime
fields to handle timestamps.

Table names should be pluralized.
Mk 2. (Guest)
on 2009-05-21 23:03
E. Litwin wrote:
> The id should be an auto-incrementing primary key.
> Also, column names should be lower cased using an underscore to
> separate words, i.e. first_name
> You should also consider adding "created_at" and "updated_at" datetime
> fields to handle timestamps.
>
> Table names should be pluralized.

Thanks.  I just realized I confused this post with one I forgot writing
yesterday.  This looks like the info I need.
Marnen L. (Guest)
on 2009-05-21 23:48
Mk 27 wrote:
> If I am going to build a sql database for use in rails (rather than
> building it in rails),
[...]

Why would you do that?  I understand the use case of a preexisting
"legacy" DB, but if you're building a DB from scratch for use with a
Rails app, then it's just more efficient to use the DB tools that Rails
provides.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
removed_email_address@domain.invalid
Sijo k. (Guest)
on 2009-05-22 08:16
>   Does the id need to be the "primary key"?

You can set your own primary key like

def self.up
create_table :table_name, :primary_key => :primary_key_field_name, do
|t|
      t.integer :primary_key_field_name
       ---------
end


Sijo
This topic is locked and can not be replied to.