Skip to content

Instantly share code, notes, and snippets.

@baileylo
Created October 15, 2010 06:48
Show Gist options
  • Select an option

  • Save baileylo/627737 to your computer and use it in GitHub Desktop.

Select an option

Save baileylo/627737 to your computer and use it in GitHub Desktop.
Modify migration files to add indexes and some database constraints on input size
class CreateBoards < ActiveRecord::Migration
def self.up
create_table :boards do |t|
t.integer :id
t.string :title, :limit => 50
t.timestamps
end
end
def self.down
drop_table :boards
end
end
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.integer :id
t.integer :user_id
t.integer :conversation_id
t.text :body
t.timestamps
end
add_index :comments, :conversation_id
add_index :comments, :user_id
end
def self.down
drop_table :comments
end
end
class CreateConversations < ActiveRecord::Migration
def self.up
create_table :conversations do |t|
t.integer :id
t.string :title, :limit => 50
t.integer :board_id
t.integer :user_id
t.timestamps
end
add_index :conversations, :board_id
add_index :conversations, :user_id
end
def self.down
drop_table :conversations
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment