Files
ai-dev-portal/schema.sql
Hyemin Lee 87289502c8 feat(db): 공개여부·언어·대댓글·좋아요(hearts) 스키마와 쿼리 개편
- projects: is_public(공개/비공개)·lang 컬럼 추가(멱등)
- comments: parent_id 추가 — 대댓글 1뎁스(앱에서 강제)
- hearts(❤️ 좋아요) 테이블 신설, stars( 즐겨찾기)는 유지
- db.js: 카운트+viewer 반응여부 공통 SELECT, 공개+본인비공개만 노출,
  toggleHeart/toggleStar({on,count}), setVisibility/deleteProject/deleteComment

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 17:11:53 +09:00

59 lines
2.7 KiB
SQL

-- AI DEV portal 스키마 (search_path=portal). 멱등.
-- 직원 식별자는 사번(Keycloak preferred_username). 표시 이름은 name.
CREATE TABLE IF NOT EXISTS users (
sabun text PRIMARY KEY, -- 사번 (Keycloak preferred_username)
name text NOT NULL,
email text,
avatar_seed text, -- 아바타 색/이니셜용
created_at timestamptz NOT NULL DEFAULT now(),
last_login timestamptz
);
-- 공유 프로젝트 (직원이 만든 앱/repo 를 포털에 공유)
CREATE TABLE IF NOT EXISTS projects (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
owner_sabun text NOT NULL REFERENCES users(sabun),
title text NOT NULL,
description text DEFAULT '',
repo_url text DEFAULT '', -- Gitea repo
app_url text DEFAULT '', -- 배포된 앱 (*.apps.bokdev.in)
tags text DEFAULT '', -- 콤마 구분
is_public boolean NOT NULL DEFAULT true, -- 공개(피드 노출) / 비공개(나만)
lang text DEFAULT '', -- 대표 언어(태그에서 추론, 카드 언어 점)
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
-- 기존 배포 DB 대비 멱등 컬럼 추가
ALTER TABLE projects ADD COLUMN IF NOT EXISTS is_public boolean NOT NULL DEFAULT true;
ALTER TABLE projects ADD COLUMN IF NOT EXISTS lang text DEFAULT '';
CREATE INDEX IF NOT EXISTS idx_projects_created ON projects(created_at DESC);
-- 코멘트 (parent_id 가 null 이면 최상위, 있으면 대댓글 — 1뎁스만 허용: 앱에서 검증)
CREATE TABLE IF NOT EXISTS comments (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
project_id bigint NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
author_sabun text NOT NULL REFERENCES users(sabun),
parent_id bigint REFERENCES comments(id) ON DELETE CASCADE,
body text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
ALTER TABLE comments ADD COLUMN IF NOT EXISTS parent_id bigint REFERENCES comments(id) ON DELETE CASCADE;
CREATE INDEX IF NOT EXISTS idx_comments_project ON comments(project_id, created_at);
-- 좋아요(❤️) — 1인 1좋아요
CREATE TABLE IF NOT EXISTS hearts (
project_id bigint NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
sabun text NOT NULL REFERENCES users(sabun),
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (project_id, sabun)
);
-- 즐겨찾기(⭐ Star) — 1인 1즐겨찾기
CREATE TABLE IF NOT EXISTS stars (
project_id bigint NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
sabun text NOT NULL REFERENCES users(sabun),
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (project_id, sabun)
);