refactor(storage): replace better-sqlite3 with PGlite adapter #378

Merged
jason.woltje merged 3 commits from refactor/storage-pglite-replace-sqlite into main 2026-04-04 21:58:15 +00:00
Owner

Summary

  • Replaces SqliteAdapter (built on better-sqlite3) with a new PgliteAdapter using @electric-sql/pglite — eliminates the prebuild-install@7.1.3 deprecation warning from mosaic gateway install
  • Ported all 18 adapter tests to in-memory PGlite (fully hermetic, zero external deps)
  • Updated StorageConfig discriminated union: { type: 'sqlite', path }{ type: 'pglite', dataDir? } (absent = in-memory)
  • CLI install wizard now writes { type: 'pglite', dataDir: '…/storage-pglite' }
  • Removed better-sqlite3 + @types/better-sqlite3 from @mosaic/storage deps; added @electric-sql/pglite@^0.2.17
  • Removed pnpm.onlyBuiltDependencies: ["better-sqlite3"] from root package.json
  • Fixed pre-existing @mosaic/config missing eslint devDependency
  • Bumped @mosaic/storage 0.0.2 → 0.0.3, @mosaic/gateway 0.0.3 → 0.1.0

Breaking Changes

The local-tier storage dialect changes from SQLite to PGlite. Existing ~/.config/mosaic/gateway/data.db files 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 pass
  • pnpm --filter @mosaic/cli test — 34/34 pass
  • All typecheck, lint, format:check pass monorepo-wide
  • pnpm why better-sqlite3 → empty
  • pnpm why prebuild-install → empty
## Summary - Replaces `SqliteAdapter` (built on `better-sqlite3`) with a new `PgliteAdapter` using `@electric-sql/pglite` — eliminates the `prebuild-install@7.1.3` deprecation warning from `mosaic gateway install` - Ported all 18 adapter tests to in-memory PGlite (fully hermetic, zero external deps) - Updated `StorageConfig` discriminated union: `{ type: 'sqlite', path }` → `{ type: 'pglite', dataDir? }` (absent = in-memory) - CLI install wizard now writes `{ type: 'pglite', dataDir: '…/storage-pglite' }` - Removed `better-sqlite3` + `@types/better-sqlite3` from `@mosaic/storage` deps; added `@electric-sql/pglite@^0.2.17` - Removed `pnpm.onlyBuiltDependencies: ["better-sqlite3"]` from root `package.json` - Fixed pre-existing `@mosaic/config` missing `eslint` devDependency - Bumped `@mosaic/storage` 0.0.2 → 0.0.3, `@mosaic/gateway` 0.0.3 → 0.1.0 ## Breaking Changes The local-tier storage dialect changes from SQLite to PGlite. Existing `~/.config/mosaic/gateway/data.db` files 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 pass - [ ] `pnpm --filter @mosaic/cli test` — 34/34 pass - [ ] All typecheck, lint, format:check pass monorepo-wide - [ ] `pnpm why better-sqlite3` → empty - [ ] `pnpm why prebuild-install` → empty
jason.woltje added 3 commits 2026-04-04 21:49:38 +00:00
Eliminates 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>
Update DEFAULT_LOCAL_CONFIG, VALID_STORAGE_TYPES, and repo-root
mosaic.config.json to use pglite instead of sqlite, completing the
storage dialect migration started in the previous commit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(config): add missing eslint devDependency
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
99a865db74
The package declared an eslint lint script but eslint was not in
devDependencies, causing the pre-push hook to fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jason.woltje merged commit c0d0fd44b7 into main 2026-04-04 21:58:15 +00:00
jason.woltje deleted branch refactor/storage-pglite-replace-sqlite 2026-04-04 21:58:15 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#378