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, :reported_user_id
25 add_index :issues, [:reportable_type, :reportable_id]
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, :user_id
40 add_index :reports, :issue_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, :user_id
53 add_index :issue_comments, :issue_id
57 drop_table :issue_comments
60 drop_enumeration :issue_status_enum