Skip to content

Instantly share code, notes, and snippets.

@gkleiman
Created January 15, 2011 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkleiman/781251 to your computer and use it in GitHub Desktop.
Save gkleiman/781251 to your computer and use it in GitHub Desktop.
class HasManyThroughExample < ActiveRecord::Migration
def self.up
create_table :user do |t|
t.string :name, :null => false
t.string :email
t.timestamps
end
create_table :projects do |t|
t.integer :user_id, :null => false
t.string :name, :null => false
t.timestamps
end
create_table :project_collaborators do |t|
t.integer :user_id, :null => false
t.integer :project_id, :null => false
t.timestamps
end
add_index :project_collaborators, [:project_id, :user_id], :unique => true
end
def self.down
remove_index :project_collaborators, [:project_id, :user_id], :unique => true
drop_table :project_collaborators
drop_table :projects
drop_table :users
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment