demonGeek wrote:
I need to use a UUID as a primary key.
I have everything working right now with the exception of being able
to create the column in MySQL (v4) as a primary key.
The migration looks like this:
create_table :groups, :id => false do |t|
t.string :id, :limit => 36, :null => false
t.string :name, :limit => 100, :null => false
t.string :description, :limit => 500
t.timestamps
end
All I want to do is specify that my replcement 'id' column is the
primary key and have the generated SQL create that column as the
primary key in the MySQL table.
Any help would be appreciated.
Thanks.
back to the question;
so rails migrations by default effectively does this,
create_table :giraffes, :id => false do
t.column :id, :primary_key
end
line 96ish.
so, :primary_key is a column type, rather than an extra property.
This makes sense, for 99.99999% of purposes.
and, so we end up called "type_to_sql" with the type=:primary_key,
in mysql this renders "int(11) DEFAULT NULL auto_increment PRIMARY KEY"
(line 176 of the mysql connection adapter)
ie. it's not very easy to hack this...
so. my only reasonable suggestion;
create_table :giraffes, :id => false do
t.string :id
...
end
execute("ALTER TABLE giraffes ADD PRIMARY KEY id")
or something, as this isn't a normal case.