9d9b3359b0
개인 운영 로그 / 일정 / 할 일 / 회고용 1차 컨테이너 도메인 신설.
plan: ~/.claude/plans/beszel-tingly-sloth.md (라운드 12 v6).
Schema:
- enum 5종 (event_kind / event_status / event_source / event_actor / history_change_kind)
- events 테이블: kind(task|calendar_event|activity_log) + lifecycle 7-state status
- events_history: lifecycle op 자동 기록, FK RESTRICT (이력은 시점 사실)
- CHECK: calendar_event → start_at NOT NULL / activity_log → started_at|ended_at NOT NULL
- partial unique (source, source_ref) — 외부 source dedup (PR-4 활용)
- partial index (active status / activity_log timeline)
API:
- POST /api/events (kind=activity_log shortcut: status=done + ended_at=now() default)
- GET /api/events/{id} | /api/events?kind&status&from&to&project_tag&source
- PATCH /api/events/{id} (extra=forbid + 시간 필드 변경 시 reschedule history)
- POST /api/events/{id}/{complete,cancel,defer,reactivate} (history 자동)
- GET /api/events/today (Asia/Seoul default, deferred 는 defer_until<=now() 만)
- GET /api/events/inbox | /api/events/activity?from&to
제외 (PR-2~5 또는 백로그):
- DELETE (회고 데이터 → /cancel 일관화)
- log shortcut / upcoming endpoint (POST + GET ?from&to 로 흡수)
- /ingest (PR-4 MailPlus forward 시 정확한 요구로 추가)
- iCal export / ntfy 알림 / recurrence / 일반 edit history
39 lines
2.2 KiB
SQL
39 lines
2.2 KiB
SQL
-- events 도메인 PR-1 (6/11) — events 1차 컨테이너 테이블
|
|
-- 개인 운영 로그 / 일정 / 할 일 / 회고용 activity database 의 본체.
|
|
-- 기존 documents/tasks/ask_events 와 직교한 새 도메인.
|
|
|
|
CREATE TABLE IF NOT EXISTS events (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
title TEXT NOT NULL,
|
|
description TEXT, -- markdown
|
|
kind event_kind NOT NULL,
|
|
status event_status NOT NULL DEFAULT 'inbox',
|
|
due_at TIMESTAMPTZ, -- task 위주
|
|
start_at TIMESTAMPTZ, -- calendar_event 위주
|
|
end_at TIMESTAMPTZ, -- calendar_event 위주
|
|
started_at TIMESTAMPTZ, -- 실제 수행 시각 (activity_log 위주)
|
|
ended_at TIMESTAMPTZ, -- 실제 수행 종료
|
|
all_day BOOLEAN NOT NULL DEFAULT false,
|
|
timezone TEXT,
|
|
defer_until TIMESTAMPTZ,
|
|
completed_at TIMESTAMPTZ,
|
|
cancelled_at TIMESTAMPTZ,
|
|
priority SMALLINT CHECK (priority BETWEEN 1 AND 4),
|
|
project_tag VARCHAR(64),
|
|
tags JSONB NOT NULL DEFAULT '[]'::jsonb,
|
|
source event_source NOT NULL DEFAULT 'manual',
|
|
source_ref TEXT, -- Message-ID 등 (TEXT, 충분한 길이)
|
|
raw_metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
memo_document_id BIGINT REFERENCES documents(id) ON DELETE SET NULL,
|
|
user_id BIGINT NOT NULL REFERENCES users(id),
|
|
created_by event_actor NOT NULL DEFAULT 'manual',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
-- CHECK 제약 (라운드 10: task 제약 제거 + activity_log 완화 — 미래 확장 막지 않게)
|
|
CONSTRAINT events_calendar_event_requires_start
|
|
CHECK (kind <> 'calendar_event' OR start_at IS NOT NULL),
|
|
CONSTRAINT events_activity_log_requires_time
|
|
CHECK (kind <> 'activity_log' OR started_at IS NOT NULL OR ended_at IS NOT NULL)
|
|
);
|