-- The forum, more (docs/kozosseg.md): the daily sky thread, volunteer -- listeners, mentions, the weekly summary, the supporter badge, and -- restricted topics with approval. (Own avatars need no column: the avatar -- holds `upload:` then.) -- The site's own threads and posts (the daily "Mai égbolt"): no member author. ALTER TABLE forum.threads ADD COLUMN system boolean NOT NULL DEFAULT false; -- The daily sky thread of that day (one a day). ALTER TABLE forum.threads ADD COLUMN daily_date date UNIQUE; ALTER TABLE forum.posts ADD COLUMN system boolean NOT NULL DEFAULT false; -- Volunteer listeners: told when a thread asking to be heard waits for a reply. ALTER TABLE forum.members ADD COLUMN listener boolean NOT NULL DEFAULT false; ALTER TABLE forum.members ADD COLUMN email_listener text NOT NULL DEFAULT 'off' CHECK (email_listener IN ('off', 'instant')); -- The listeners were told about this thread (once). ALTER TABLE forum.threads ADD COLUMN listeners_notified_at timestamptz; -- "@Holdfény" in a post: whom it names. CREATE TABLE forum.mentions ( post_id bigint NOT NULL REFERENCES forum.posts ON DELETE CASCADE, user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE, created_at timestamptz NOT NULL DEFAULT now(), PRIMARY KEY (post_id, user_id) ); CREATE INDEX mentions_user_idx ON forum.mentions (user_id, created_at DESC); ALTER TABLE forum.members ADD COLUMN email_mentions text NOT NULL DEFAULT 'instant' CHECK (email_mentions IN ('off', 'instant')); -- The weekly summary e-mail: off until the member asks for it. ALTER TABLE forum.members ADD COLUMN email_weekly boolean NOT NULL DEFAULT false; ALTER TABLE forum.members ADD COLUMN weekly_sent_at timestamptz; -- The "Támogató" badge: only for buyers, and only when they switch it on. ALTER TABLE forum.members ADD COLUMN supporter_badge boolean NOT NULL DEFAULT false; -- Members of a restricted topic: they ask, a moderator approves. CREATE TABLE forum.topic_members ( topic_id smallint NOT NULL REFERENCES forum.topics ON DELETE CASCADE, user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE, status text NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'approved')), -- A few words from the member asking to join. note text NOT NULL DEFAULT '', requested_at timestamptz NOT NULL DEFAULT now(), decided_at timestamptz, decided_by uuid REFERENCES users ON DELETE SET NULL, PRIMARY KEY (topic_id, user_id) ); CREATE INDEX topic_members_user_idx ON forum.topic_members (user_id) WHERE status = 'approved'; ALTER TABLE forum.mod_log DROP CONSTRAINT mod_log_action_check; ALTER TABLE forum.mod_log ADD CONSTRAINT mod_log_action_check CHECK (action IN ('delete_post', 'restore_post', 'delete_thread', 'restore_thread', 'ban', 'unban', 'lock', 'unlock', 'pin', 'unpin', 'resolve_report', 'dismiss_report', 'approve_member', 'reject_member', 'remove_member', 'reset_avatar', 'topic'));