class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition
def column(name, type = nil, options = {})
def column(name, type = nil, options = {}) super column = self[name] column.array = options[:array] self end
def create_column_definition(name, type)
def create_column_definition(name, type) ColumnDefinition.new name, type end
def primary_key(name, type = :primary_key, options = {})
done via the SecureRandom.uuid method and a +before_save+ callback,
before saving a record (as primary keys cannot be nil). This might be
will require you to assure that you always provide a UUID value
Note that setting the UUID primary key default value to +nil+
or another library.
You may also pass a different UUID generation function from +uuid-ossp+
end
t.timestamps
t.uuid :foo_id
t.primary_key :id, :uuid, default: nil
create_table :stuffs, id: false do |t|
set the +:default+ option to nil:
migrations To use a UUID primary key without +uuid-ossp+ enabled, you can
the +uuid-ossp+ extension, you can use the +enable_extension+ method in your
+uuid-ossp+ extension, which MUST be enabled on your databse. To enable
By default, this will use the +uuid_generate_v4()+ 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 = {}) return super unless type == :uuid options[:default] = options.fetch(:default, 'uuid_generate_v4()') options[:primary_key] = true column name, type, options end