1 class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
3 create_enum :issue_status_enum, %w[open ignored resolved]
5 create_table :issues do |t|
6 t.string :reportable_type, :null => false
7 t.integer :reportable_id, :null => false
8 t.integer :reported_user_id
9 t.column :status, :issue_status_enum, :null => false, :default => "open"
10 t.column :assigned_role, :user_role_enum, :null => false
11 t.datetime :resolved_at
12 t.integer :resolved_by
14 t.integer :reports_count, :default => 0
15 t.timestamps :null => false
18 add_foreign_key :issues, :users, :column => :reported_user_id, :name => "issues_reported_user_id_fkey"
19 add_foreign_key :issues, :users, :column => :resolved_by, :name => "issues_resolved_by_fkey"
20 add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey"
22 add_index :issues, [:reportable_type, :reportable_id]
23 add_index :issues, [:reported_user_id]
24 add_index :issues, [:status]
25 add_index :issues, [:assigned_role]
26 add_index :issues, [:updated_by]
28 create_table :reports do |t|
29 t.integer :issue_id, :null => false
30 t.integer :user_id, :null => false
31 t.text :details, :null => false
32 t.string :category, :null => false
33 t.timestamps :null => false
36 add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
37 add_foreign_key :reports, :users, :column => :user_id, :name => "reports_user_id_fkey"
39 add_index :reports, :issue_id
40 add_index :reports, :user_id
42 create_table :issue_comments do |t|
43 t.integer :issue_id, :null => false
44 t.integer :user_id, :null => false
45 t.text :body, :null => false
46 t.timestamps :null => false
49 add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
50 add_foreign_key :issue_comments, :users, :column => :user_id, :name => "issue_comments_user_id_fkey"
52 add_index :issue_comments, :issue_id
53 add_index :issue_comments, :user_id
57 drop_table :issue_comments
60 drop_enumeration :issue_status_enum