feat(storage): mosaic storage migrate-tier with dry-run + idempotency (FED-M1-05) #474
Reference in New Issue
Block a user
Delete Branch "feat/federation-m1-migrate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
FED-M1-05 — Adds
mosaic storage migrate-tier --to federatedfor one-way migration fromlocal(PGlite) orstandalone(Postgres without pgvector) →federated(Postgres + pgvector).Architectural correction during review
The first implementation read source data via
PgliteAdapter(flat(id, data jsonb)collection schema). Independent code review surfaced this as a P0 bug: the gateway writes domain data via the normalized Drizzle schema (createPgliteDb()→DBinjection), not via the storage adapter. Reading from the flat collections would have silently produced empty federated databases.Fix: introduced
DrizzleMigrationSourcethat queries the same normalized schema the gateway writes through. Bothlocalandstandalonesources now route through Drizzle (createPgliteDb/createDbfrom@mosaicstack/db), guaranteeing the migration captures real domain data.Behaviors
--dry-run— prints per-table row counts; no writes--allow-non-empty— required to write into a populated target (default refuses)INSERT ... ON CONFLICT (id) DO UPDATEkeyed on primary keyschema.references()sessions,verifications,admin_tokens(TTL'd / one-time / env-bound)insights.embeddingprojected to NULL when source lacks pgvector (column is nullable per schema)Tests
32 unit tests in
packages/storage/src/migrate-tier.spec.ts:--allow-non-emptyTest plan
Refs #460