[Rails] auto increment id
Ara.T.Howard
Ara.T.Howard at noaa.gov
Wed Mar 9 17:34:00 GMT 2005
On Wed, 9 Mar 2005, Dave Lee wrote:
> Ara.T.Howard <Ara.T.Howard at noaa.gov> wrote:
>> looking at the unit tests of activerecord leads me to think the db is
>> completely responsible for auto-incrementing the id field and rails does no
>> magic here.
>
> correct.
>
>> that being the case - what is the preferred way to write database agnostic sql
>> for one's schema since each of the dbs has slightly different syntax for this
>> functionality... does anyone know how to do
>
> I haven't used sqlite, but in using postgresql and mysql, I definte
> the tables in one file, and then have db specific files containing
> appropriate alter table commands:
>
> -- t.sql
> create table t (
> id int not null,
> data text,
> primary key (id)
> );
>
> -- t-pgsql.sql
> create sequence t_id_seq;
> alter table t alter id set default nextval('t_id_seq');
>
> -- t-mysql.sql
> alter table modify id int not null auto_increment;
smart - i'll take it!
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
More information about the Rails
mailing list