refactor(storage): replace better-sqlite3 with PGlite adapter #378
Reference in New Issue
Block a user
Delete Branch "refactor/storage-pglite-replace-sqlite"
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
SqliteAdapter(built onbetter-sqlite3) with a newPgliteAdapterusing@electric-sql/pglite— eliminates theprebuild-install@7.1.3deprecation warning frommosaic gateway installStorageConfigdiscriminated union:{ type: 'sqlite', path }→{ type: 'pglite', dataDir? }(absent = in-memory){ type: 'pglite', dataDir: '…/storage-pglite' }better-sqlite3+@types/better-sqlite3from@mosaic/storagedeps; added@electric-sql/pglite@^0.2.17pnpm.onlyBuiltDependencies: ["better-sqlite3"]from rootpackage.json@mosaic/configmissingeslintdevDependency@mosaic/storage0.0.2 → 0.0.3,@mosaic/gateway0.0.3 → 0.1.0Breaking Changes
The local-tier storage dialect changes from SQLite to PGlite. Existing
~/.config/mosaic/gateway/data.dbfiles will not be migrated. On upgrade, the gateway starts fresh with a new PGlite directory at~/.config/mosaic/gateway/storage-pglite. This is a clean break — the Storage Abstraction mission is r0, no production users.Test plan
pnpm --filter @mosaic/storage test— 18/18 pass (PGlite in-memory)pnpm --filter @mosaic/gateway test— 347/347 passpnpm --filter @mosaic/cli test— 34/34 passpnpm why better-sqlite3→ emptypnpm why prebuild-install→ emptyEliminates the `prebuild-install` deprecation warning that appears during `mosaic gateway install` by removing `better-sqlite3` from the dependency graph entirely and replacing the SqliteAdapter with a PGlite-based adapter that mirrors the same interface and test coverage. - New `PgliteAdapter` in `packages/storage/src/adapters/pglite.ts` using `@electric-sql/pglite` with JSONB columns and pg-style `$N` placeholders - Ported all 18 adapter tests to `pglite.test.ts` (in-memory PGlite instances) - Deleted `sqlite.ts` and `sqlite.test.ts` - Updated `StorageConfig` discriminated union: `sqlite` → `pglite` with optional `dataDir` (absent = in-memory) - `packages/storage/index.ts` re-exports `PgliteAdapter` and registers it - CLI install wizard writes `{ type: 'pglite', dataDir: '…/storage-pglite' }` - Removed `better-sqlite3` and `@types/better-sqlite3` from storage deps; added `@electric-sql/pglite@^0.2.17` - Removed `pnpm.onlyBuiltDependencies: ["better-sqlite3"]` from root package.json - Bump `@mosaic/storage` 0.0.2 → 0.0.3 - Bump `@mosaic/gateway` 0.0.3 → 0.1.0 (minor — storage dialect change) Breaking: local-tier `data.db` SQLite files are not migrated. Clean break. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>