Last active
          August 29, 2015 14:18 
        
      - 
      
 - 
        
Save tiagopog/ba6fca8cdd633ea1e7fd to your computer and use it in GitHub Desktop.  
    JSONB example with Rails
  
        
  
    
      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 characters
    
  
  
    
  | # db/migrate/*_create_authentications.rb | |
| class CreateAuthentications < ActiveRecord::Migration | |
| def change | |
| create_table :authentications do |t| | |
| t.references :user, index: true | |
| t.integer :provider, default: 0, null: false | |
| t.jsonb :access_data, null: false, default: '{}' | |
| t.timestamps | |
| end | |
| add_index :authentications, :access_data, using: :gin | |
| end | |
| end | |
| # db/migrate/*__add_index_to_access_data_path_on_authentications.rb | |
| class AddIndexToAccessDataPathOnAuthentications < ActiveRecord::Migration | |
| def up | |
| execute <<-SQL | |
| CREATE INDEX access_data_token_on_authentications ON authentications ((access_data->>'token')) | |
| SQL | |
| end | |
| def down | |
| remove_index :authentications, name: :access_data_token_on_authentications | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment