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
8 t.column :assigned_role, :user_role_enum, :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"
17 add_foreign_key :issues, :users, :column => :resolved_by, :name => "issues_resolved_by_fkey"
18 add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey"
20 add_index :issues, :reported_user_id
21 add_index :issues, [:reportable_type, :reportable_id]
22 add_index :issues, :updated_by
24 create_table :reports do |t|
25 t.integer :issue_id, :null => false
26 t.integer :user_id, :null => false
27 t.text :details, :null => false
28 t.string :category, :null => false
29 t.timestamps :null => false
32 add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
33 add_foreign_key :reports, :users, :column => :user_id, :name => "reports_user_id_fkey"
35 add_index :reports, :user_id
36 add_index :reports, :issue_id
38 create_table :issue_comments do |t|
39 t.integer :issue_id, :null => false
40 t.integer :user_id, :null => false
41 t.text :body, :null => false
42 t.timestamps :null => false
45 add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
46 add_foreign_key :issue_comments, :users, :column => :user_id, :name => "issue_comments_user_id_fkey"
48 add_index :issue_comments, :user_id
49 add_index :issue_comments, :issue_id