Last active
April 29, 2016 12:22
-
-
Save yannvery/78ae095bdfe1556ff882f8242e47b1e9 to your computer and use it in GitHub Desktop.
Revisions
-
yannvery revised this gist
Apr 29, 2016 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ This guide is a sort of extract of official rails guide: [Official rails guide](http://edgeguides.rubyonrails.org/active_record_postgresql.html) Here I describe an implementation of **uuid** with **PostgreSQL** >= **9.4**. This requires to enable `pgcrypto` Example with a creation of a table named trackers: @@ -20,5 +20,17 @@ class CreateTrackers < ActiveRecord::Migration[5.0] end ``` You can use **uuid** to define a relation reference ```rb class CreateProjects < ActiveRecord::Migration[5.0] def change enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto') create_table :projects, id: :uuid, default: 'gen_random_uuid()' do |t| t.string :name t.uuid :user_id t.timestamps end end end ``` -
yannvery created this gist
Apr 29, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # Use uuid on rails with PostgreSQL This guide is a sort of extract of official rails guide: [Official rails guide](http://edgeguides.rubyonrails.org/active_record_postgresql.html) Here I describe an implementation of uuid with PostgreSQL >= 9.4. This requires to enable `pgcrypto` Example with a creation of a table named trackers: ```rb class CreateTrackers < ActiveRecord::Migration[5.0] def change enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto') create_table :trackers, id: :uuid, default: 'gen_random_uuid()' do |t| t.integer :duration, null: false t.string :description, null: false t.timestamps end end end ``` You can use uuid to degine a relation reference