3 class CreateIssuesAndReports < ActiveRecord::Migration
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, :null => false
11 t.datetime :resolved_at
12 t.integer :resolved_by
13 t.datetime :created_at
14 t.datetime :updated_at
17 t.timestamps null: false
20 add_foreign_key :issues, :users, :column => :reported_user_id,:name => "issues_reported_user_id_fkey", on_delete: :cascade
22 add_index :issues, :reported_user_id
23 add_index :issues, [:reportable_id, :reportable_type]
25 create_table :reports do |t|
27 t.integer :reporter_user_id
29 t.datetime :created_at
30 t.datetime :updated_at
32 t.timestamps null: false
35 add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey", on_delete: :cascade
36 add_foreign_key :reports, :users,:column => :reporter_user_id, :name => "reports_reporter_user_id_fkey", on_delete: :cascade
38 add_index :reports, :reporter_user_id
39 add_index :reports, :issue_id