Skip to content

Instantly share code, notes, and snippets.

@kapso
Created May 24, 2012 03:49
Show Gist options
  • Save kapso/2779327 to your computer and use it in GitHub Desktop.
Save kapso/2779327 to your computer and use it in GitHub Desktop.
class CreateFriends < ActiveRecord::Migration
def option_1
create_table :friends do |t|
t.string :user_guid, null: false
t.string :friend_guid, null: false
t.boolean :reciprocal, default: false
t.string :name, null: false
end
add_index :friends, [:user_guid, :reciprocal, :name]
add_index :friends, :friend_guid
end
def option_2_normalized
create_table :friends_relation do |t|
t.string :user_guid, null: false
t.string :friend_guid, null: false
t.boolean :reciprocal, default: false
end
create_table :friends_name, id: false do |t|
t.string :guid, null: false # primary key
t.string :name, null: false
end
add_index :friends_relation, [:user_guid, :friend_guid, :reciprocal]
add_index :friends_name, :name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment