DB fix to work with existing entries
* added temp. default values for user_id and item_type * changed model validation for item_type
This commit is contained in:
parent
462a7116de
commit
3d9fceb479
4 changed files with 10 additions and 5 deletions
|
|
@ -1,7 +1,8 @@
|
|||
class Report < ActiveRecord::Base
|
||||
validates :user_id, presence: true
|
||||
validates :item_id, presence: true
|
||||
validates :item_type, presence: true
|
||||
validates :item_type, presence: true, :inclusion => { :in => %w(post comment),
|
||||
:message => 'Type should match `post` or `comment`!'}
|
||||
validates :text, presence: true
|
||||
|
||||
validate :entry_does_not_exist, :on => :create
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class AddPostTypeToPostReport < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :post_reports, :post_type, :string, :null => false, :after => :post_id
|
||||
add_column :post_reports, :post_type, :string, :null => false, :after => :post_id, :default => 'post'
|
||||
change_column_default :post_reports, :post_type, nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
class ChangeUserIdTypeToInteger < ActiveRecord::Migration
|
||||
def up
|
||||
change_column :reports, :user_id, :integer
|
||||
remove_column :reports, :user_id
|
||||
add_column :reports, :user_id, :integer, :null => false, :default => 1
|
||||
change_column_default :reports, :user_id, nil
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :reports, :user_id, :string
|
||||
remove_column :reports, :user_id
|
||||
add_column :reports, :user_id, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -402,11 +402,11 @@ ActiveRecord::Schema.define(:version => 20140422134627) do
|
|||
create_table "reports", :force => true do |t|
|
||||
t.integer "item_id", :null => false
|
||||
t.string "item_type", :null => false
|
||||
t.integer "user_id"
|
||||
t.boolean "reviewed", :default => false
|
||||
t.text "text"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
end
|
||||
|
||||
add_index "reports", ["item_id"], :name => "index_post_reports_on_post_id"
|
||||
|
|
|
|||
Loading…
Reference in a new issue