comments: allow votes to be soft deleted.
Make it so that when a user removes their own vote, the vote is soft deleted (the is_deleted flag is set) instead of hard deleted. Changes: * Add is_deleted flag to comment votes. * Relax uniqueness constraint so you can have multiple deleted votes on the same comment. You can still only have one active vote on the comment. * Add `soft_delete` method to Deletable concern.
This commit is contained in:
11
db/migrate/20210330003356_add_is_deleted_to_comment_votes.rb
Normal file
11
db/migrate/20210330003356_add_is_deleted_to_comment_votes.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class AddIsDeletedToCommentVotes < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :comment_votes, :is_deleted, :boolean, default: false, null: :false
|
||||
change_column_null :comment_votes, :is_deleted, false
|
||||
|
||||
add_index :comment_votes, :is_deleted, where: "is_deleted = TRUE"
|
||||
|
||||
remove_index :comment_votes, [:user_id, :comment_id], unique: true
|
||||
add_index :comment_votes, [:user_id, :comment_id], unique: true, where: "is_deleted = FALSE"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user