Files
document-server/backend/migrations/009_create_notes_system.sql
Hyungi Ahn 3e0a03f149 🐛 Fix Alpine.js SyntaxError and backlink visibility issues
- Fix SyntaxError in viewer.js line 2868 (.bind(this) issue in setTimeout)
- Resolve Alpine.js 'Can't find variable' errors (documentViewer, goBack, etc.)
- Fix backlink rendering and persistence during temporary highlights
- Add backlink protection and restoration mechanism in highlightAndScrollToText
- Implement Note Management System with hierarchical notebooks
- Add note highlights and memos functionality
- Update cache version to force browser refresh (v=2025012641)
- Add comprehensive logging for debugging backlink issues
2025-08-26 23:50:48 +09:00

82 lines
3.6 KiB
PL/PgSQL

-- 노트 관리 시스템 생성
-- 009_create_notes_system.sql
-- 노트 문서 테이블
CREATE TABLE IF NOT EXISTS notes_documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(500) NOT NULL,
content TEXT, -- 마크다운 내용
html_content TEXT, -- 변환된 HTML 내용
note_type VARCHAR(50) DEFAULT 'note', -- note, research, summary, idea 등
tags TEXT[] DEFAULT '{}', -- 태그 배열
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
created_by VARCHAR(100) NOT NULL,
is_published BOOLEAN DEFAULT false, -- 공개 여부
parent_note_id UUID REFERENCES notes_documents(id) ON DELETE SET NULL, -- 계층 구조
sort_order INTEGER DEFAULT 0, -- 정렬 순서
word_count INTEGER DEFAULT 0, -- 단어 수
reading_time INTEGER DEFAULT 0, -- 예상 읽기 시간 (분)
-- 인덱스
CONSTRAINT notes_documents_title_check CHECK (char_length(title) > 0)
);
-- 인덱스 생성
CREATE INDEX IF NOT EXISTS idx_notes_documents_created_by ON notes_documents(created_by);
CREATE INDEX IF NOT EXISTS idx_notes_documents_created_at ON notes_documents(created_at);
CREATE INDEX IF NOT EXISTS idx_notes_documents_note_type ON notes_documents(note_type);
CREATE INDEX IF NOT EXISTS idx_notes_documents_parent_note_id ON notes_documents(parent_note_id);
CREATE INDEX IF NOT EXISTS idx_notes_documents_tags ON notes_documents USING GIN(tags);
CREATE INDEX IF NOT EXISTS idx_notes_documents_is_published ON notes_documents(is_published);
-- 업데이트 시간 자동 갱신 트리거
CREATE OR REPLACE FUNCTION update_notes_documents_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trigger_update_notes_documents_updated_at
BEFORE UPDATE ON notes_documents
FOR EACH ROW
EXECUTE FUNCTION update_notes_documents_updated_at();
-- 기존 document_links 테이블에 노트 지원 추가
-- (이미 존재하는 테이블이므로 ALTER 사용)
DO $$
BEGIN
-- source_type, target_type 컬럼이 없다면 추가
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'document_links' AND column_name = 'source_type'
) THEN
ALTER TABLE document_links
ADD COLUMN source_type VARCHAR(20) DEFAULT 'document',
ADD COLUMN target_type VARCHAR(20) DEFAULT 'document';
-- 기존 데이터는 모두 'document' 타입으로 설정
UPDATE document_links SET source_type = 'document', target_type = 'document';
END IF;
END $$;
-- 노트 관련 링크를 위한 인덱스
CREATE INDEX IF NOT EXISTS idx_document_links_source_type ON document_links(source_type);
CREATE INDEX IF NOT EXISTS idx_document_links_target_type ON document_links(target_type);
-- 샘플 노트 타입 데이터
INSERT INTO notes_documents (title, content, html_content, note_type, tags, created_by, is_published)
VALUES
('노트 시스템 사용법',
'# 노트 시스템 사용법\n\n## 기본 기능\n- 마크다운으로 노트 작성\n- HTML로 자동 변환\n- 태그 기반 분류\n\n## 고급 기능\n- 서적과 링크 연결\n- 계층 구조 지원\n- 내보내기 기능',
'<h1>노트 시스템 사용법</h1><h2>기본 기능</h2><ul><li>마크다운으로 노트 작성</li><li>HTML로 자동 변환</li><li>태그 기반 분류</li></ul><h2>고급 기능</h2><ul><li>서적과 링크 연결</li><li>계층 구조 지원</li><li>내보내기 기능</li></ul>',
'guide',
ARRAY['가이드', '사용법', '시스템'],
'Administrator',
true)
ON CONFLICT DO NOTHING;
COMMIT;