# reportable_type :string not null
# reportable_id :integer not null
# reported_user_id :integer
-# status :integer
+# status :enum default(NULL), not null
# assigned_role :enum not null
# resolved_at :datetime
# resolved_by :integer
before_validation :set_default_assigned_role
before_validation :set_reported_user
- # Check if more statuses are needed
- enum :status => %w[open ignored resolved]
-
scope :with_status, ->(issue_status) { where(:status => statuses[issue_status]) }
def read_reports
+require "migrate"
+
class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
- def change
+ def up
+ create_enumeration :issue_status_enum, %w[open ignored resolved]
+
create_table :issues do |t|
t.string :reportable_type, :null => false
t.integer :reportable_id, :null => false
t.integer :reported_user_id
- t.integer :status
+ t.column :status, :issue_status_enum, :null => false, :default => "open"
t.column :assigned_role, :user_role_enum, :null => false
t.datetime :resolved_at
t.integer :resolved_by
add_index :issue_comments, :user_id
add_index :issue_comments, :issue_id
end
+
+ def down
+ drop_table :issue_comments
+ drop_table :reports
+ drop_table :issues
+ drop_enumeration :issue_status_enum
+ end
end
);
+--
+-- Name: issue_status_enum; Type: TYPE; Schema: public; Owner: -
+--
+
+CREATE TYPE issue_status_enum AS ENUM (
+ 'open',
+ 'ignored',
+ 'resolved'
+);
+
+
--
-- Name: note_event_enum; Type: TYPE; Schema: public; Owner: -
--
reportable_type character varying NOT NULL,
reportable_id integer NOT NULL,
reported_user_id integer,
- status integer,
+ status issue_status_enum DEFAULT 'open'::public.issue_status_enum NOT NULL,
assigned_role user_role_enum NOT NULL,
resolved_at timestamp without time zone,
resolved_by integer,