Files
digital-psychology/apps/api/migrations/000011_account_bootstrap.up.sql
T
jackyu66gitandCursor 7ab9add5dd
ci / h5 (push) Canceled after 0s
ci / api (push) Canceled after 0s
ci / ess-docs (push) Canceled after 0s
feat(ops): ECR-007 行为分析与 ECR-008 内容运营后台
落地埋点 ingest/数据看板、首页宫格 CMS 与测评上下架;含账号引导、问答流式与免责声明去重,以及 review P1 审计同事务修复。

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

30 lines
1.3 KiB
SQL

-- Account auth + report peer for birthday bootstrap bundles
ALTER TABLE users ADD COLUMN IF NOT EXISTS phone varchar(20) NULL;
ALTER TABLE users ADD COLUMN IF NOT EXISTS password_hash text NULL;
ALTER TABLE users ADD COLUMN IF NOT EXISTS nickname varchar(64) NULL;
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_phone_unique
ON users(phone) WHERE phone IS NOT NULL AND deleted_at IS NULL;
CREATE TABLE IF NOT EXISTS user_sessions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES users(id),
token varchar(128) NOT NULL UNIQUE,
expires_at timestamptz NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
revoked_at timestamptz NULL
);
CREATE INDEX IF NOT EXISTS idx_user_sessions_user_id ON user_sessions(user_id);
CREATE INDEX IF NOT EXISTS idx_user_sessions_token ON user_sessions(token) WHERE revoked_at IS NULL;
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS peer_profile_id uuid NULL REFERENCES profiles(id);
CREATE INDEX IF NOT EXISTS idx_growth_reports_latest_solo
ON growth_reports(user_id, profile_id, type, created_at DESC)
WHERE deleted_at IS NULL AND peer_profile_id IS NULL;
CREATE INDEX IF NOT EXISTS idx_growth_reports_latest_pair
ON growth_reports(user_id, profile_id, type, peer_profile_id, created_at DESC)
WHERE deleted_at IS NULL AND peer_profile_id IS NOT NULL;