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.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-21 20: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"?
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-05-21 20: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)
1ebcd34bbfe62169964bb9a5006de29f?d=identicon&s=25 Manasi V1 (manasi)
on 2009-05-21 20: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
Ced56202e9039027cfc2da2f70457977?d=identicon&s=25 E. Litwin (Guest)
on 2009-05-21 20: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.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-21 21: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.
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-05-21 21: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
marnen@marnen.org
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2009-05-22 06: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.