Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using UUID in a Migration
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chief7 Chief7  
View profile  
 More options Oct 29 2007, 10:25 pm
From: Chief7 Chief7 <rails-mailing-l...@andreas-s.net>
Date: Tue, 30 Oct 2007 03:25:19 +0100
Local: Mon, Oct 29 2007 10:25 pm
Subject: Using UUID in a Migration
Has anyone ever used UUID in a migration?

I thought I could set the default value of a field to be ‘UUID’ but that
only sets the value the string instead of executing the function to
create a new unique identifier.
--
Posted via http://www.ruby-forum.com/.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Hogan  
View profile  
 More options Oct 29 2007, 10:28 pm
From: "Brian Hogan" <bpho...@gmail.com>
Date: Mon, 29 Oct 2007 21:28:52 -0500
Local: Mon, Oct 29 2007 10:28 pm
Subject: Re: [Rails] Using UUID in a Migration

Please explain what you mean by UUID. What database?

Rails migrations will create an ID column automatically for you and set it
to your DB's equivalent of autonumbering.

On 10/29/07, Chief7 Chief7 <rails-mailing-l...@andreas-s.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wentwj@gmail.com  
View profile  
 More options Oct 30 2007, 1:05 am
From: "wen...@gmail.com" <wen...@gmail.com>
Date: Tue, 30 Oct 2007 05:05:03 -0000
Local: Tues, Oct 30 2007 1:05 am
Subject: Re: Using UUID in a Migration
I'm assuming he means a genuine unique identifier.  Generally I think
a hash approximately 32 characters long thats theoretically supposed
to be unique amongst all tables.

I know what you're asking about but I haven't done it in rails yet so
I'm not much help, though I do recall seeing a plugin that worked with
and/or generated GUIDs

On Oct 29, 9:28 pm, "Brian Hogan" <bpho...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chief7 Chief7  
View profile  
 More options Oct 30 2007, 10:11 pm
From: Chief7 Chief7 <rails-mailing-l...@andreas-s.net>
Date: Wed, 31 Oct 2007 03:11:03 +0100
Local: Tues, Oct 30 2007 10:11 pm
Subject: Re: Using UUID in a Migration
In MySQL, the UUID() function returns a "Universal Unique Identifier".
"A UUID is a 128-bit number represented by a string of five hexadecimal
numbers in aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee format."

There must be a way to set the value of a column using the UUID function
in a migration.

Has anyone else done this?

Is there a way to set the default value for a column to a db function?
Such SUM() or RAND()?  The syntax should be the same.
--
Posted via http://www.ruby-forum.com/.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Graff  
View profile  
 More options Oct 31 2007, 1:55 am
From: "Michael Graff" <skan.gryp...@gmail.com>
Date: Wed, 31 Oct 2007 00:55:40 -0500
Local: Wed, Oct 31 2007 1:55 am
Subject: Re: [Rails] Re: Using UUID in a Migration
Not all databases will have that function, so in one go you limit your
application's portability.

Why not set it to a string, and write your uuid generator?

--Michael

On 10/30/07, Chief7 Chief7 <rails-mailing-l...@andreas-s.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
drbuettner@gmail.com  
View profile  
 More options Nov 20 2007, 4:21 pm
From: "drbuett...@gmail.com" <drbuett...@gmail.com>
Date: Tue, 20 Nov 2007 13:21:48 -0800 (PST)
Local: Tues, Nov 20 2007 4:21 pm
Subject: Re: Using UUID in a Migration
I'm curious about this as well; I'm currently building an application
that may use multiple independent databases, and want to have the
ability to do object replication among them at some point in the
future for redundancy.  Database-generated integer IDs are convenient
and all but they don't scale well to this sort of application!

I've been designing and testing tables in my Rails app (on MySQL)
using a UUID for the 'id' column, which is declared as a VARCHAR(40)
with a unique index, and so far I have not encountered any problems.
Anybody see any real problems with it, conceptually?  The problem with
handling it all within a MySQL model, as previously noted, is that you
cannot currently assign the value of a function as the default value
of a column in MySQL, except for a couple of timestamp-type columns.

Here's what I've got in my Rails app:

in lib/uuid.rb:
class UUID
  def self.new
    return ActiveRecord::Base.connection.select_value("SELECT
LOWER( UUID() )")
  end
end

And then in each model:
  def before_create
    if self.id.nil?
      self.id = UUID.new
    end
  end

And finally, in my table creation migrations:
def self.up
  create_table :hot_folders, :id => false do |t|
    t.column :id, :string, :limit => 40, :null => false
    ...
  end
  add_index('hot_folders', 'id', 'UNIQUE')
end

If you were on a different database engine, or if I am someday, you
could update the uuid.rb lib file to do something different and
appropriate for the database you're using - or generate a UUID
programatically instead of via the db - via  a series of IF/ELSIFs.
(IF mysql ELSIF sqlserver ELSIF postgres ELSE ...)

The above table creation will be somewhat inefficient for MySQL's
InnoDB engine, as ISTR that if you don't declare a unique ID during
table creation, it creates one internally.  When I get to load testing
& whatnot that may mean dropping and recreating the tables to avoid
the extra overhead of two unique columns, one of which I never use.

-Dan

On Oct 30, 11:55 pm, "Michael Graff" <skan.gryp...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »