Drop and re-add columns instead.

This commit is contained in:
Dessalines 2024-04-09 19:44:52 -04:00
parent 89d5627963
commit 6efd025470
2 changed files with 16 additions and 18 deletions

View file

@ -1,6 +1,10 @@
ALTER TABLE local_user_vote_display_mode ALTER TABLE local_user_vote_display_mode
ALTER COLUMN upvotes SET DEFAULT FALSE, DROP COLUMN score,
ALTER COLUMN downvotes SET DEFAULT FALSE, ADD COLUMN score boolean DEFAULT TRUE NOT NULL,
ALTER COLUMN score SET DEFAULT TRUE, DROP COLUMN upvotes,
ALTER COLUMN upvote_percentage SET DEFAULT TRUE; ADD COLUMN upvotes boolean DEFAULT FALSE NOT NULL,
DROP COLUMN downvotes,
ADD COLUMN downvotes boolean DEFAULT FALSE NOT NULL,
DROP COLUMN upvote_percentage,
ADD COLUMN upvote_percentage boolean DEFAULT TRUE NOT NULL;

View file

@ -3,18 +3,12 @@
-- Rather than -- Rather than
-- Score + upvote_percentage -- Score + upvote_percentage
ALTER TABLE local_user_vote_display_mode ALTER TABLE local_user_vote_display_mode
ALTER COLUMN upvotes SET DEFAULT TRUE, DROP COLUMN score,
ALTER COLUMN downvotes SET DEFAULT TRUE, ADD COLUMN score boolean DEFAULT FALSE NOT NULL,
ALTER COLUMN score SET DEFAULT FALSE, DROP COLUMN upvotes,
ALTER COLUMN upvote_percentage SET DEFAULT FALSE; ADD COLUMN upvotes boolean DEFAULT TRUE NOT NULL,
DROP COLUMN downvotes,
-- Regenerate the rows with the new default ADD COLUMN downvotes boolean DEFAULT TRUE NOT NULL,
DELETE FROM local_user_vote_display_mode; DROP COLUMN upvote_percentage,
ADD COLUMN upvote_percentage boolean DEFAULT FALSE NOT NULL;
-- Re-insert them
INSERT INTO local_user_vote_display_mode (local_user_id)
SELECT
id
FROM
local_user;