Files
sorsfonalak/crates/db/migrations/0041_forum_more.sql
T
fecoandClaude Opus 5.5 564c22176f Forum: daily sky thread, listeners, mentions, own avatars, restricted topics
- The worker opens a "Mai égbolt" thread every morning from the day's sky
  (no AI), pinned for the day.
- Volunteer listeners (from the Kereső rank) get a badge, a count of the
  threads asking to be heard that still wait for a reply, and, if they ask,
  an e-mail after two hours of waiting.
- "@Holdfény" names a member (nicknames with spaces too): they follow the
  thread, hear of it live and, if they asked, by e-mail; a search helps
  typing it.
- From the Kereső rank a member may upload an own avatar: a small square
  JPEG without metadata in the object storage (now a shared crate with the
  backend), served by the forum; moderators can put the starter back.
- The "Támogató" badge for buyers who switch it on.
- The admin creates and edits topics; restricted ones are read by their
  approved members, who ask to join and moderators decide.
- "Most itt vannak" on the front page; the weekly summary e-mail on Sunday
  evening for those who ask (off by default).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-26 12:37:52 +00:00

56 lines
3.0 KiB
SQL

-- 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:<file>` 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'));