$ rails g migration enable_uuid_extension
psql
postgres=# CREATE EXTENSION "uuid-ossp";
CREATE EXTENSION
postgres=# SELECT uuid_generate_v4();
uuid_generate_v4
--------------------------------------
f8c9ffd6-a234-4729-bd2a-68379df315fb
(1 row)
Migration to enable uuid
class EnableUuidExtension < ActiveRecord::Migration
def change
enable_extension 'uuid-ossp'
end
end
create model with uuid default
create_table :users, id: :uuid do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
add uuid ot model
class AddUuidToBooks < ActiveRecord::Migration
def change
add_column :books, :uuid, :uuid, default: 'uuid_generate_v4()'
end
end