---
estimated_steps: 11
estimated_files: 5
skills_used: []
---

# T02: PostgreSQL schema and migrations

1. Create SQLAlchemy models for all 7 entities:
   - Creator (id, name, slug, genres, folder_name, view_count, timestamps)
   - SourceVideo (id, creator_id FK, filename, file_path, duration, content_type enum, transcript_path, processing_status enum, timestamps)
   - TranscriptSegment (id, source_video_id FK, start_time, end_time, text, segment_index, topic_label)
   - KeyMoment (id, source_video_id FK, technique_page_id FK nullable, title, summary, start/end time, content_type enum, plugins, review_status enum, raw_transcript, timestamps)
   - TechniquePage (id, creator_id FK, title, slug, topic_category, topic_tags, summary, body_sections JSONB, signal_chains JSONB, plugins, source_quality enum, view_count, review_status enum, timestamps)
   - RelatedTechniqueLink (id, source_page_id FK, target_page_id FK, relationship enum)
   - Tag (id, name, category, aliases)
2. Set up Alembic for migrations
3. Create initial migration
4. Add seed data for canonical tags (6 top-level categories)

## Inputs

- `chrysopedia-spec.md section 6 (Data Model)`

## Expected Output

- `backend/models.py`
- `backend/database.py`
- `alembic/versions/001_initial.py`
- `config/canonical_tags.yaml`

## Verification

alembic upgrade head succeeds; all 7 tables exist with correct columns and constraints
