Files
digital-psychology/apps/api/migrations/000003_scales.up.sql
T
jackyu66gitandCursor 15a9db374a feat: add exploration scale list, questions, and scoring
Seed communication-style scale, expose /api/v1/scales APIs, and wire
Explore/Scale H5 pages for the P1 探索测试 path.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-02 16:29:31 +08:00

59 lines
2.4 KiB
SQL

CREATE TABLE IF NOT EXISTS scales (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
slug varchar(64) NOT NULL UNIQUE,
title varchar(128) NOT NULL,
description varchar(512) NOT NULL DEFAULT '',
status varchar(32) NOT NULL DEFAULT 'published',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz NULL
);
CREATE TABLE IF NOT EXISTS scale_questions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
scale_id uuid NOT NULL REFERENCES scales(id),
sort int NOT NULL DEFAULT 0,
body jsonb NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz NULL
);
CREATE INDEX IF NOT EXISTS idx_scale_questions_scale_id ON scale_questions(scale_id);
CREATE TABLE IF NOT EXISTS scale_results (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES users(id),
scale_id uuid NOT NULL REFERENCES scales(id),
profile_id uuid NOT NULL REFERENCES profiles(id),
answers jsonb NOT NULL DEFAULT '{}',
result jsonb NOT NULL DEFAULT '{}',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz NULL
);
CREATE INDEX IF NOT EXISTS idx_scale_results_user_id ON scale_results(user_id);
-- Seed one 探索测试 (communication style)
INSERT INTO scales (id, slug, title, description, status)
VALUES (
'11111111-1111-1111-1111-111111111111',
'communication-style',
'沟通方式探索',
'了解你在表达与倾听时的偏好,生成探索结果标签。',
'published'
) ON CONFLICT (slug) DO NOTHING;
INSERT INTO scale_questions (scale_id, sort, body) VALUES
(
'11111111-1111-1111-1111-111111111111', 1,
'{"prompt":"意见不合时,你更常怎么做?","options":[{"key":"A","text":"先讲清事实与逻辑"},{"key":"B","text":"先照顾彼此的情绪"},{"key":"C","text":"先暂停,稍后再谈"}]}'
),
(
'11111111-1111-1111-1111-111111111111', 2,
'{"prompt":"朋友找你商量事情,你更倾向于?","options":[{"key":"A","text":"帮对方拆解方案"},{"key":"B","text":"先认真听完感受"},{"key":"C","text":"给对方安静空间"}]}'
),
(
'11111111-1111-1111-1111-111111111111', 3,
'{"prompt":"你希望对方如何回应你?","options":[{"key":"A","text":"直接、清楚、可执行"},{"key":"B","text":"温暖、肯定、有共鸣"},{"key":"C","text":"尊重节奏、不急着下结论"}]}'
);