3 class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
5 create_enumeration :issue_status_enum, %w[open ignored resolved]
7 create_table :issues do |t|
8 t.string :reportable_type, :null => false
9 t.integer :reportable_id, :null => false
10 t.integer :reported_user_id
11 t.column :status, :issue_status_enum, :null => false, :default => "open"
12 t.column :assigned_role, :user_role_enum, :null => false
13 t.datetime :resolved_at
14 t.integer :resolved_by
16 t.integer :reports_count, :default => 0
17 t.timestamps :null => false
20 add_foreign_key :issues, :users, :column => :reported_user_id, :name => "issues_reported_user_id_fkey"
21 add_foreign_key :issues, :users, :column => :resolved_by, :name => "issues_resolved_by_fkey"
22 add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey"
24 add_index :issues, [:reportable_type, :reportable_id]
25 add_index :issues, [:reported_user_id]
26 add_index :issues, [:status]
27 add_index :issues, [:assigned_role]
28 add_index :issues, [:updated_by]
30 create_table :reports do |t|
31 t.integer :issue_id, :null => false
32 t.integer :user_id, :null => false
33 t.text :details, :null => false
34 t.string :category, :null => false
35 t.timestamps :null => false
38 add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
39 add_foreign_key :reports, :users, :column => :user_id, :name => "reports_user_id_fkey"
41 add_index :reports, :issue_id
42 add_index :reports, :user_id
44 create_table :issue_comments do |t|
45 t.integer :issue_id, :null => false
46 t.integer :user_id, :null => false
47 t.text :body, :null => false
48 t.timestamps :null => false
51 add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
52 add_foreign_key :issue_comments, :users, :column => :user_id, :name => "issue_comments_user_id_fkey"
54 add_index :issue_comments, :issue_id
55 add_index :issue_comments, :user_id
59 drop_table :issue_comments
62 drop_enumeration :issue_status_enum