ProjectOS / docs /storage-migration-plan.md
AnthropicallyHuggingFaces's picture
Sync full ProjectOS monorepo from GitHub 7f633f5
a8f4b72 verified
|
Raw History Blame Contribute Delete
2.59 kB

Storage migration plan

bootstrap.xml is the source of storage configuration. The schema engine validates the provider, vector-store, retention, and migration settings, then writes configs/generated/storage.generated.json. The local SQLite schema is already applied when the API opens data/projectos.sqlite; existing state routes still use app_state.

Phase 1: Dual-write

Add normalized writes for project and snapshot changes while continuing to update app_state. Perform both writes in one SQLite transaction, and return success only after both have committed. Give events and snapshots stable IDs so retries do not create duplicates.

Phase 2: Repositories

Introduce ProjectRepository, SnapshotRepository, CanonRepository, FrontierRepository, ArchiveRepository, and EmbeddingRepository. Keep HTTP handlers responsible for request validation and call the repositories for persistence.

Route Primary table
POST /api/projects projects
POST /api/snapshots snapshots, snapshot_items
POST /api/canon canon_entries, canon_revisions
POST /api/frontier frontier_items, frontier_observations
POST /api/archive archive_records

Phase 3: Backfill and read cutover

Read legacy arrays from app_state, map each record into its normalized table, and preserve the original JSON payload for fields without a normalized column. Make the backfill idempotent. Compare record counts and content checksums before switching reads to repositories. Keep the old state values until the cutover is confirmed.

  • app_state.projects → projects
  • app_state.snapshots → snapshots and snapshot_items
  • governance history → project_events

Phase 4: Vector backfill

Generate embeddings for canon entries, frontier items, and project descriptions through the configured embedding provider. Record model key, dimensions, and source content hash. Verify the configured dimensions before writing. SQLite stores JSON vectors; PostgreSQL uses vector(1536) and its HNSW cosine index. Change both schemas and the manifest together when adopting a model with a different dimension.

Phase 5: Remove compatibility storage

After all reads and writes use repositories and the backfill is verified, remove app_state, its route compatibility code, and legacy migration logic. Keep migration history and archive records according to the configured retention policy. Before enabling automatic schema changes, honor backupBeforeMigration and validateSchema from the generated storage config.