Skip to content

[Phase C1] Replace JSON store with SQLite-backed schema (extends #14) #26

@terisuke

Description

@terisuke

Tracked under ADR 0002 — Phase C. Detail: implementation plan §C1. Subsumes Issue #14.

Problem

The flat data/workflow_store.json snapshot has no versioning, no per-persona isolation, no Project/Article concept, and no way to fork sessions on edit. It is a process-global mutex-protected map that gets serialized as one blob (internal/infrastructure/repository/memory/workflow.go). Every Phase B and Phase A2/A3 feature needs durable, queryable history. Continuing on JSON forces a second migration later.

Scope

  • New package internal/infrastructure/repository/sqlite using modernc.org/sqlite (pure Go, no CGO) — preferred — or mattn/go-sqlite3 if CGO is acceptable. Decision documented in PR.
  • Schema migrations under internal/infrastructure/repository/sqlite/migrations/0001_*.sql, applied at boot via a tiny in-process migrator.
  • Tables (minimum):
    • personas
    • author_sources
    • writing_style_guides (versioned per persona)
    • projects
    • articles
    • brief_sessions
    • brief_answers (with parent_answer_id for fork-on-edit)
    • drafts (versioned per article)
  • persona_id is NOT NULL on every guide and answer to prevent cross-persona contamination.
  • Default DB path: data/note_maker.db (gitignored).
  • First-boot importer: if the JSON file exists, import it and rename to data/workflow_store.json.imported.{timestamp}.

Acceptance criteria

  • All repository interfaces have SQLite implementations. Existing in-memory implementations remain available for tests.
  • go test ./... passes against both the in-memory and SQLite implementations.
  • Re-opening the app after a restart shows past projects, sessions, and drafts.
  • Cross-persona guarantee: a unit test asserts that selecting persona A never returns guide rows from persona B.
  • Migration test: a JSON store from before this change is imported cleanly.
  • Fork-on-edit (Phase A1) is supported by brief_answers.parent_answer_id.

Out of scope

  • Multi-user / multi-tenant (still single-user local).
  • Cloud sync.
  • A web admin UI for the DB (CLI-only inspection is enough).

Closes

  • #14 (subsumed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions