lemmy/migrations/2024-09-20-134838_add_federation_vote_rejection/down.sql
Dessalines ffb94fde85
Adding local site settings to reject federated upvotes or downvotes. (#5038)
* Adding local site settings to reject federated upvotes or downvotes.

- Should help defend against downvote spamming instances.
- Fixes #4086

* Adding new vote mode types.

* Simpler activitypub vote check.

* Adding undo vote for failed vote mode check.

* Update crates/api_common/src/utils.rs

---------

Co-authored-by: Nutomic <me@nutomic.com>
2024-10-02 06:55:37 -04:00

32 lines
691 B
SQL

-- Add back the enable_downvotes column
ALTER TABLE local_site
ADD COLUMN enable_downvotes boolean DEFAULT TRUE NOT NULL;
-- regenerate their values (from post_downvotes alone)
WITH subquery AS (
SELECT
post_downvotes,
CASE WHEN post_downvotes = 'Disable'::federation_mode_enum THEN
FALSE
ELSE
TRUE
END
FROM
local_site)
UPDATE
local_site
SET
enable_downvotes = subquery.case
FROM
subquery;
-- Drop the new columns
ALTER TABLE local_site
DROP COLUMN post_upvotes,
DROP COLUMN post_downvotes,
DROP COLUMN comment_upvotes,
DROP COLUMN comment_downvotes;
DROP TYPE federation_mode_enum;