1 class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
3 create_table :issues do |t|
4 t.string :reportable_type, :null => false
5 t.integer :reportable_id, :null => false
6 t.integer :reported_user_id, :null => false
9 t.datetime :resolved_at
10 t.integer :resolved_by
12 t.integer :reports_count, :default => 0
13 t.timestamps :null => false
16 add_foreign_key :issues, :users, :column => :reported_user_id, :name => "issues_reported_user_id_fkey", :on_delete => :cascade
17 add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", :on_delete => :cascade
19 add_index :issues, :reported_user_id
20 add_index :issues, [:reportable_id, :reportable_type]
21 add_index :issues, :updated_by
23 create_table :reports do |t|
26 t.text :details, :null => false
27 t.timestamps :null => false
30 add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey", :on_delete => :cascade
31 add_foreign_key :reports, :users, :column => :user_id, :name => "reports_user_id_fkey", :on_delete => :cascade
33 add_index :reports, :user_id
34 add_index :reports, :issue_id
36 create_table :issue_comments do |t|
37 t.integer :issue_id, :null => false
38 t.integer :user_id, :null => false
39 t.text :body, :null => false
40 t.timestamps :null => false
43 add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey", :on_delete => :cascade
44 add_foreign_key :issue_comments, :users, :column => :user_id, :name => "issue_comments_user_id", :on_delete => :cascade
46 add_index :issue_comments, :user_id
47 add_index :issue_comments, :issue_id