Files
mostlymatter/db/migrations/postgres/000042_create_threads.up.sql
2022-01-08 10:16:07 +02:00

17 строки
423 B
SQL

CREATE TABLE IF NOT EXISTS threads (
postid VARCHAR(26) PRIMARY KEY,
replycount bigint,
lastreplyat bigint,
participants text
);
ALTER TABLE threads ADD COLUMN IF NOT EXISTS channelid VARCHAR(26);
CREATE INDEX IF NOT EXISTS idx_threads_channel_id ON threads (channelid);
UPDATE threads
SET channelId=posts.channelid
FROM posts
WHERE posts.id=threads.postid
AND threads.channelid IS NULL;