Skip to content

Instantly share code, notes, and snippets.

@yannvery
Last active April 29, 2016 12:22
Show Gist options
  • Select an option

  • Save yannvery/78ae095bdfe1556ff882f8242e47b1e9 to your computer and use it in GitHub Desktop.

Select an option

Save yannvery/78ae095bdfe1556ff882f8242e47b1e9 to your computer and use it in GitHub Desktop.

Revisions

  1. yannvery revised this gist Apr 29, 2016. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions uuid_on_rails.md
    Original 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`
    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 degine a relation reference
    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
    ```
  2. yannvery created this gist Apr 29, 2016.
    24 changes: 24 additions & 0 deletions uuid_on_rails.md
    Original 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