Files
spsays-bff/migrations/0049_group_send_policy.up.sql
T
2026-08-29 03:49:30 +05:30

27 lines
1.0 KiB
SQL

-- Who may post in a group.
--
-- 'everyone' keeps existing groups behaving exactly as they do today, which is
-- why it is the default: this migration must not silently mute anyone.
-- 'admins' makes the thread an announcement channel — owners and admins post,
-- everyone else reads.
--
-- DMs and Kautilya threads ignore this: a two-party conversation has no
-- administrators, and the AI thread has one participant.
ALTER TABLE conversations
ADD COLUMN IF NOT EXISTS send_policy VARCHAR(8) NOT NULL DEFAULT 'everyone';
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'conversations_send_policy_check'
) THEN
ALTER TABLE conversations
ADD CONSTRAINT conversations_send_policy_check
CHECK (send_policy IN ('everyone', 'admins'));
END IF;
END $$;
-- "Who are this group's admins?" runs on every post in an admins-only thread.
CREATE INDEX IF NOT EXISTS conversation_participants_role_idx
ON conversation_participants (conversation_id, role) WHERE left_at IS NULL;