summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-08-06 16:08:16 +0200
committerYorhel <git@yorhel.nl>2020-08-07 10:39:16 +0200
commitc3a26b56d68c56ee9ffa17900fb1f1a6fcf32e26 (patch)
tree2542e1a94d317f0ae23dd90ccf928e713dbd0deb /util
parent4ff57327c4c95652c0634ca97ed5495c037fc16e (diff)
Discussions: Fix handling of user deletion
Which I broke by removing the DEFAULT clause on threads_posts.uid. That column still used the old uid=0 for deleted users rather than the uid=NULL that I was planning to migrate the entire DB to. So while I'm fixing up the threads schema, may as well update this too. There's still a bunch of columns relying on uid=0, but I can fix that later.
Diffstat (limited to 'util')
-rw-r--r--util/updates/2020-08-07-threads.sql3
1 files changed, 3 insertions, 0 deletions
diff --git a/util/updates/2020-08-07-threads.sql b/util/updates/2020-08-07-threads.sql
index d036ee81..ede9621b 100644
--- a/util/updates/2020-08-07-threads.sql
+++ b/util/updates/2020-08-07-threads.sql
@@ -34,10 +34,13 @@ ALTER TABLE threads ADD COLUMN c_lastnum smallint NOT NULL DEFAULT 1; -- 'num' o
ALTER TABLE threads_posts ALTER COLUMN num DROP DEFAULT;
ALTER TABLE threads_posts ALTER COLUMN uid DROP DEFAULT;
+ALTER TABLE threads_posts ALTER COLUMN uid DROP NOT NULL;
ALTER TABLE threads_posts ADD CONSTRAINT threads_posts_first_nonhidden CHECK(num > 1 OR NOT hidden);
UPDATE threads
SET c_count = (SELECT COUNT(*) FROM threads_posts WHERE NOT hidden AND tid = threads.id)
, c_lastnum = (SELECT MAX(num) FROM threads_posts WHERE NOT hidden AND tid = threads.id);
+UPDATE threads_posts SET uid = NULL WHERE uid = 0;
+
\i sql/triggers.sql