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 COLUMN upvotes SET DEFAULT FALSE,
ALTER COLUMN downvotes SET DEFAULT FALSE,
ALTER COLUMN score SET DEFAULT TRUE,
ALTER COLUMN upvote_percentage SET DEFAULT TRUE;
DROP COLUMN score,
ADD COLUMN score boolean DEFAULT TRUE NOT NULL,
DROP COLUMN upvotes,
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
-- Score + upvote_percentage
ALTER TABLE local_user_vote_display_mode
ALTER COLUMN upvotes SET DEFAULT TRUE,
ALTER COLUMN downvotes SET DEFAULT TRUE,
ALTER COLUMN score SET DEFAULT FALSE,
ALTER COLUMN upvote_percentage SET DEFAULT FALSE;
-- Regenerate the rows with the new default
DELETE FROM local_user_vote_display_mode;
-- Re-insert them
INSERT INTO local_user_vote_display_mode (local_user_id)
SELECT
id
FROM
local_user;
DROP COLUMN score,
ADD COLUMN score boolean DEFAULT FALSE NOT NULL,
DROP COLUMN upvotes,
ADD COLUMN upvotes boolean DEFAULT TRUE NOT NULL,
DROP COLUMN downvotes,
ADD COLUMN downvotes boolean DEFAULT TRUE NOT NULL,
DROP COLUMN upvote_percentage,
ADD COLUMN upvote_percentage boolean DEFAULT FALSE NOT NULL;