Added IssueComments + ForeignKeys + Indexes

This commit is contained in:
Shrey 2015-05-28 23:51:54 +05:30 committed by Matt Amos
parent d49922eb63
commit 683722ed5c
16 changed files with 285 additions and 18 deletions

View file

@ -0,0 +1,12 @@
class CreateIssueComments < ActiveRecord::Migration
def change
create_table :issue_comments do |t|
t.integer :issue_id
t.integer :user_id
t.text :body
t.datetime :created_at
t.timestamps null: false
end
end
end

View file

@ -0,0 +1,11 @@
require "migrate"
class AddForeignKeysForIssues < ActiveRecord::Migration
def change
add_foreign_key :issues, :users, :name => "issues_user_id_fkey"
add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
add_foreign_key :reports, :users, :name => "reports_user_id_fkey"
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
add_foreign_key :issue_comments, :users, :name => "issue_comments_user_id"
end
end

View file

@ -0,0 +1,19 @@
class AddIndexesForIssues < ActiveRecord::Migration
def self.up
add_index :issues, :user_id
add_index :issues, [:reportable_id, :reportable_type]
add_index :reports, :issue_id
add_index :reports, :user_id
add_index :issue_comments, :user_id
add_index :issue_comments, :issue_id
end
def self.down
remove_index :issues, :user_id
remove_index :issues, [:reportable_id, :reportable_type]
remove_index :reports, :issue_id
remove_index :reports, :user_id
remove_index :issue_comments, :user_id
remove_index :issue_comments, :issue_id
end
end