module ActiveRecord::ConnectionAdapters::PostgreSQL::ColumnMethods
def primary_key(name, type = :primary_key, **options)
a record (as primary keys cannot be +nil+). This might be done via the
require you to assure that you always provide a UUID value before saving
Note that setting the UUID primary key default value to +nil+ will
different UUID generation function from another library.
You may also pass a custom stored procedure that returns a UUID or use a
end
t.timestamps
t.uuid :foo_id
t.primary_key :id, :uuid, default: nil
create_table :stuffs, id: false do |t|
+:default+ option to +nil+:
To use a UUID primary key without any of the extensions, set the
the +enable_extension+ method in your migrations.
To enable the appropriate extension, which is a requirement, use
end
t.timestamps
t.uuid :foo_id
t.primary_key :id, :uuid, default: "uuid_generate_v4()"
create_table :stuffs, id: false do |t|
to use uuid_generate_v4() from the +uuid-ossp+ extension instead:
PostgreSQL 9.4+, for earlier versions an explicit default can be set
+pgcrypto+ extension. As that extension is only available in
By default, this will use the gen_random_uuid() function from the
end
t.timestamps
t.string :content
create_table :stuffs, id: :uuid do |t|
by defining your tables as such:
Use of the native PostgreSQL UUID type is supported, and can be used
Defines the primary key field.
def primary_key(name, type = :primary_key, **options) if type == :uuid options[:default] = options.fetch(:default, "gen_random_uuid()") end super end