38 lines
1.9 KiB
SQL
38 lines
1.9 KiB
SQL
-- Per-user chat preferences.
|
|
--
|
|
-- A row is created on first change, so absence means "all defaults". That is
|
|
-- why every column carries the product default rather than something neutral:
|
|
-- reading a missing row and reading an untouched row must give the same answer.
|
|
CREATE TABLE IF NOT EXISTS chat_settings (
|
|
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
|
|
|
-- Read receipts are reciprocal: turning them off also stops you seeing
|
|
-- other people's. Enforced in the service, not here.
|
|
read_receipts BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
-- Who may START a conversation with this user:
|
|
-- anyone — no restriction (default)
|
|
-- friends — people they follow, or who follow them, accepted
|
|
-- account_age — accounts at least min_account_age_months old
|
|
-- same_gender — accounts whose gender matches theirs; requires the user
|
|
-- to have set their own gender, since there is nothing to
|
|
-- match against otherwise
|
|
who_can_message VARCHAR(16) NOT NULL DEFAULT 'anyone',
|
|
|
|
-- Only meaningful when who_can_message = 'account_age'.
|
|
min_account_age_months INTEGER NOT NULL DEFAULT 3,
|
|
|
|
-- Consent for using this user's chats as training data for the Kautilya
|
|
-- assistant. Recorded now so the choice exists before the feature does —
|
|
-- collecting consent retroactively is worse than collecting it early.
|
|
train_kautilya BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
CONSTRAINT chat_settings_who_can_message_check
|
|
CHECK (who_can_message IN ('anyone', 'friends', 'account_age', 'same_gender')),
|
|
CONSTRAINT chat_settings_account_age_check
|
|
CHECK (min_account_age_months BETWEEN 1 AND 120)
|
|
);
|