72 lines
3.5 KiB
SQL
72 lines
3.5 KiB
SQL
-- Feedback, kept in the system only (no e-mail, no Telegram). Nothing of it
|
||||
|
|
-- is shown publicly: these are not reviews.
|
|||
|
|
|
|||
|
|
-- Ratings of what a user got: the short summary, a detailed analysis, a
|
|||
|
|
-- forecast, a synastry, a tarot reading (analyses), or an answer to a
|
|||
|
|
-- question. Only the one who got it rates it, once (a rating can be
|
|||
|
|
-- changed). Kind, model and prompt version are copied, so the statistics
|
|||
|
|
-- stay when the analysis is deleted.
|
|||
|
|
CREATE TABLE content_ratings (
|
|||
|
|
id uuid PRIMARY KEY,
|
|||
|
|
-- Cleared with the account (the comment goes too; the stars stay, without a name).
|
|||
|
|
user_id uuid REFERENCES users (id) ON DELETE SET NULL,
|
|||
|
|
analysis_id uuid REFERENCES analyses (id) ON DELETE SET NULL,
|
|||
|
|
question_id uuid REFERENCES questions (id) ON DELETE SET NULL,
|
|||
|
|
-- summary, natal, synastry, forecast, tarot or question.
|
|||
|
|
kind text NOT NULL,
|
|||
|
|
model text,
|
|||
|
|
prompt_version text,
|
|||
|
|
-- 1–5 stars; an answer's thumbs are 1 (down) or 5 (up).
|
|||
|
|
stars smallint NOT NULL CHECK (stars BETWEEN 1 AND 5),
|
|||
|
|
tags text[] NOT NULL DEFAULT '{}',
|
|||
|
|
comment text,
|
|||
|
|
-- The user lets the operator read the rated text (to improve it).
|
|||
|
|
may_read boolean NOT NULL DEFAULT false,
|
|||
|
|
-- Had paid for a package when rating.
|
|||
|
|
buyer boolean NOT NULL DEFAULT false,
|
|||
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|||
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|||
|
|
-- An admin has looked at it (the admin menu counts the ones to look at).
|
|||
|
|
reviewed_at timestamptz,
|
|||
|
|
CHECK (analysis_id IS NULL OR question_id IS NULL)
|
|||
|
|
);
|
|||
|
|
CREATE UNIQUE INDEX content_ratings_analysis_idx ON content_ratings (analysis_id, user_id)
|
|||
|
|
WHERE analysis_id IS NOT NULL AND user_id IS NOT NULL;
|
|||
|
|
CREATE UNIQUE INDEX content_ratings_question_idx ON content_ratings (question_id, user_id)
|
|||
|
|
WHERE question_id IS NOT NULL AND user_id IS NOT NULL;
|
|||
|
|
CREATE INDEX content_ratings_created_idx ON content_ratings (created_at DESC);
|
|||
|
|
|
|||
|
|
-- Messages through the "Visszajelzés" page: bugs, ideas, questions. The
|
|||
|
|
-- user sees their state and the operator's reply on the same page.
|
|||
|
|
CREATE TABLE feedback_messages (
|
|||
|
|
id uuid PRIMARY KEY,
|
|||
|
|
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|||
|
|
category text NOT NULL CHECK (category IN ('bug', 'idea', 'question', 'other')),
|
|||
|
|
body text NOT NULL,
|
|||
|
|
-- The page the user came from, and the browser (for bugs).
|
|||
|
|
page text,
|
|||
|
|
user_agent text,
|
|||
|
|
status text NOT NULL DEFAULT 'new' CHECK (status IN ('new', 'in_progress', 'done', 'dismissed')),
|
|||
|
|
-- Only the operator sees it.
|
|||
|
|
admin_note text,
|
|||
|
|
reply text,
|
|||
|
|
replied_at timestamptz,
|
|||
|
|
-- The user has seen the reply.
|
|||
|
|
reply_seen_at timestamptz,
|
|||
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|||
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|||
|
|
);
|
|||
|
|
CREATE INDEX feedback_messages_status_idx ON feedback_messages (status, created_at DESC);
|
|||
|
|
CREATE INDEX feedback_messages_user_idx ON feedback_messages (user_id, created_at DESC);
|
|||
|
|
|
|||
|
|
-- "How likely are you to recommend Sorsfonalak to a friend?" (0–10), asked
|
|||
|
|
-- once in the app. A closed question is kept with no score: not asked again.
|
|||
|
|
CREATE TABLE nps_answers (
|
|||
|
|
id uuid PRIMARY KEY,
|
|||
|
|
user_id uuid UNIQUE REFERENCES users (id) ON DELETE SET NULL,
|
|||
|
|
score smallint CHECK (score BETWEEN 0 AND 10),
|
|||
|
|
comment text,
|
|||
|
|
buyer boolean NOT NULL DEFAULT false,
|
|||
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|||
|
|
);
|