# 설계 스펙: SQLite → PostgreSQL 전환 + JSON Export/Import

**작성일**: 2026-03-15
**범위**: DB 엔진 전환, 프로젝트 JSON export/import, Docker 배포

---

## 1. 변경 사항

### 1.1 단일 PostgreSQL DB로 통합

- 카탈로그 DB (service.sqlite) → PostgreSQL `theroad` DB
- 프로젝트별 SQLite → PostgreSQL의 스키마 또는 테이블 (project_id FK로 구분)
- 모든 프로젝트 데이터가 하나의 PostgreSQL에 저장

### 1.2 모델 변경

- `Text` → `String` (PostgreSQL에서는 동일하지만 명시적)
- `Integer` boolean → `Boolean` 타입 (is_active 등)
- UUID 기본키 유지 (Text로 저장)
- project_id FK를 프로젝트 스코프 테이블에 추가

### 1.3 DB 연결

```
DATABASE_URL=postgresql://theroad:theroad_dev_2026@localhost:5432/theroad
```

### 1.4 JSON Export/Import

프로젝트 전체를 JSON으로 export:
```json
{
  "project": {...},
  "members": [...],
  "episodes": [...],
  "entities": [...],
  "relations": [...],
  "scene_stills": [...],
  "images": [...],  // 메타데이터만, 파일은 별도
  "webbook_packages": [...],
  "operation_logs": [...],
  "generation_traces": [...]
}
```

이미지/PDF 파일은 zip으로 별도 패키징.

## 2. Docker Compose

```yaml
services:
  postgres:
    image: postgres:17
    environment:
      POSTGRES_USER: theroad
      POSTGRES_PASSWORD: theroad_dev_2026
      POSTGRES_DB: theroad
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data

  backend:
    build: ./backend
    ports:
      - "8000:8000"
    depends_on:
      - postgres
    environment:
      DATABASE_URL: postgresql://theroad:theroad_dev_2026@postgres:5432/theroad

volumes:
  pgdata:
```
