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:
evazion
2021-03-29 19:40:37 -05:00
parent 55129b1819
commit 6b91e55283
11 changed files with 125 additions and 23 deletions

View File

@@ -764,7 +764,8 @@ CREATE TABLE public.comment_votes (
user_id integer NOT NULL,
score integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
updated_at timestamp without time zone NOT NULL,
is_deleted boolean DEFAULT false NOT NULL
);
@@ -5107,6 +5108,13 @@ CREATE INDEX index_comment_votes_on_comment_id ON public.comment_votes USING btr
CREATE INDEX index_comment_votes_on_created_at ON public.comment_votes USING btree (created_at);
--
-- Name: index_comment_votes_on_is_deleted; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_comment_votes_on_is_deleted ON public.comment_votes USING btree (is_deleted) WHERE (is_deleted = true);
--
-- Name: index_comment_votes_on_user_id; Type: INDEX; Schema: public; Owner: -
--
@@ -5118,7 +5126,7 @@ CREATE INDEX index_comment_votes_on_user_id ON public.comment_votes USING btree
-- Name: index_comment_votes_on_user_id_and_comment_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_comment_votes_on_user_id_and_comment_id ON public.comment_votes USING btree (user_id, comment_id);
CREATE UNIQUE INDEX index_comment_votes_on_user_id_and_comment_id ON public.comment_votes USING btree (user_id, comment_id) WHERE (is_deleted = false);
--
@@ -8005,6 +8013,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210214095121'),
('20210214101614'),
('20210303195217'),
('20210310221248');
('20210310221248'),
('20210330003356');