데이터 모델 및 저장소
SQLite 엔티티, 관계, 상태가 재수화되는 방법.
PlanToCode는 모든 로컬 상태에 SQLite를 사용합니다. 이 문서는 스키마, 엔티티 관계, 앱 재시작 시 상태가 복원되는 방법을 설명합니다.
SQLite 구성
데이터베이스는 동시 읽기/쓰기 액세스를 위해 WAL 모드를 사용합니다. 파일은 Tauri 앱 데이터 디렉토리에 저장됩니다 (Linux에서 ~/.local/share/plantocode, macOS에서 ~/Library/Application Support/plantocode).
스키마 마이그레이션은 consolidated_schema.sql에 통합됩니다. 앱은 시작 시 스키마 버전을 확인하고 보류 중인 마이그레이션을 실행합니다.
핵심 엔티티
- sessions: 작업 설명, 파일 선택, 모델 기본 설정, 검색 설정, 비디오/병합 프롬프트, 히스토리 인덱스가 있는 프로젝트 컨텍스트
- background_jobs: 프롬프트, 응답, 토큰, 비용, is_finalized 플래그, error_message가 있는 LLM 기반 작업
- terminal_sessions: 출력 로그, 상태, 프로세스 정보가 있는 PTY 세션
- task_description_history: 작업 설명에 대한 버전 히스토리
- file_selection_history: 파일 선택에 대한 버전 히스토리
- project_system_prompts: 프로젝트별 프롬프트 오버라이드
- key_value_store: 앱 설정 및 구성
- error_logs: 클라이언트 측 오류 추적
- migrations: 타임스탬프와 함께 적용된 데이터베이스 마이그레이션 추적
- db_diagnostic_logs: 데이터베이스 진단 이슈와 오류 기록
- app_settings: 설명이 있는 애플리케이션 구성 키-값 쌍
엔티티 관계 다이어그램
SQLite 스키마와 관계의 시각적 표현.
Schema details
sessions table
id TEXT PRIMARY KEY
name, project_directory, project_hash
task_description, search_term, model_used
search_selected_files_only INTEGER (0/1)
video_analysis_prompt, merge_instructions
included_files, force_excluded_files (JSON)
task_history_version, file_history_version
task_history_current_index, file_history_current_index
created_at, updated_at (Unix timestamps)
background_jobs table
id TEXT PRIMARY KEY, session_id FK
task_type, status (with CHECK constraint)
prompt TEXT, response TEXT, error_message TEXT
tokens_sent, tokens_received, cache_*_tokens
model_used, actual_cost REAL
metadata JSON, system_prompt_template
is_finalized INTEGER (0/1 flag)
start_time, end_time, server_request_id
terminal_sessions table
id TEXT PRIMARY KEY, job_id FK (optional)
session_id TEXT UNIQUE
status: idle, starting, initializing, running, completed, failed, agent_requires_attention, recovering, disconnected, stuck, restored
process_pid, exit_code
working_directory, environment_vars JSON
output_log TEXT (accumulated PTY output)
last_output_at, started_at, ended_at
migrations table
id INTEGER PRIMARY KEY AUTOINCREMENT
name TEXT NOT NULL
applied_at INTEGER (Unix timestamp)
db_diagnostic_logs table
id INTEGER PRIMARY KEY AUTOINCREMENT
timestamp INTEGER, error_type TEXT
error_message TEXT, additional_info TEXT
app_settings table
key TEXT PRIMARY KEY
value TEXT NOT NULL, description TEXT
created_at, updated_at (Unix timestamps)
엔티티 관계
엔티티는 연쇄 삭제 규칙이 있는 외래 키를 통해 연결됩니다:
- sessions → background_jobs: 일대다, 연쇄 삭제
- background_jobs → terminal_sessions: job_id를 통한 선택적 일대일 링크
- sessions → task_description_history: 버전 추적을 위한 일대다
- sessions → file_selection_history: 버전 추적을 위한 일대다
리포지토리 레이어
모든 데이터베이스 액세스는 desktop/src-tauri/src/db_utils/의 타입화된 리포지토리를 통해 이루어집니다:
- background_job_repository/: base.rs, worker.rs, metadata.rs, cleanup.rs로 모듈화
- session_repository.rs: 히스토리 관리가 있는 세션 CRUD
- terminal_repository.rs: 터미널 세션 영속 및 출력 로깅
- settings_repository.rs: 키-값 설정 저장소
상태 재수화
앱이 시작되면 SQLite에서 상태가 복원됩니다:
활성 세션은 작업 설명, 파일 선택, 모델 기본 설정과 함께 로드됩니다. 최근 세션은 세션 선택기에서 사용 가능합니다.
데이터 보존
구성 가능한 보존 기간에 따라 오래된 데이터가 정리됩니다:
세션과 작업은 정리 전에 백업을 위해 내보낼 수 있습니다.
Key source files
- desktop/src-tauri/migrations/consolidated_schema.sql - Full schema
- desktop/src-tauri/src/db_utils/mod.rs - Repository exports
- desktop/src-tauri/src/db_utils/background_job_repository/ - Job CRUD (directory with base.rs, worker.rs, metadata.rs, cleanup.rs)
- desktop/src-tauri/src/db_utils/session_repository.rs - Session management
- desktop/src-tauri/src/db_utils/terminal_repository.rs - Terminal persistence
- desktop/src-tauri/src/db_utils/settings_repository.rs - App settings
작업 처리 탐색하기
백그라운드 작업이 이 데이터 모델을 어떻게 사용하는지 확인하세요.