2021-04-26 03:42:20 +00:00
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
UPDATE version SET minor = 7;
|
|
|
|
|
|
|
|
ALTER TABLE votes
|
2021-04-26 05:09:16 +00:00
|
|
|
ALTER COLUMN requestUrl SET NOT NULL,
|
2021-04-26 03:42:20 +00:00
|
|
|
ALTER COLUMN userId SET NOT NULL;
|
|
|
|
|
|
|
|
CREATE OR REPLACE PROCEDURE clear_zero_votes()
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
DELETE FROM requests WHERE NOT EXISTS
|
|
|
|
(SELECT FROM votes WHERE requests.url = votes.requesturl);
|
|
|
|
$$;
|
|
|
|
|
|
|
|
CREATE OR REPLACE PROCEDURE delete_vote(url varchar,voteuser int)
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
DELETE FROM votes WHERE requesturl = url AND userid = voteuser;
|
|
|
|
CALL update_scores();
|
|
|
|
CALL clear_zero_votes();
|
|
|
|
$$;
|
|
|
|
|
|
|
|
COMMIT;
|