Files
stack/packages/storage
Jarvis 9050ccacba
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
feat(storage): pgvector adapter support gated on tier=federated (FED-M1-03)
Adds pgvector support to the postgres storage adapter without affecting
local or standalone tiers:

- `StorageConfig` postgres variant gains optional `enableVector: boolean`
- `PostgresAdapter.migrate()` runs `CREATE EXTENSION IF NOT EXISTS vector`
  via `db.execute(sql)` BEFORE migrations when `enableVector === true`
  (so vector-typed columns are creatable in the same migration pass).
  Idempotent — safe to re-run on already-installed extension.
- `vector` custom type in `@mosaicstack/db/schema` is now exported so
  downstream packages can declare vector columns in their own schemas.
- `DEFAULT_FEDERATED_CONFIG.storage.enableVector = true` so the federated
  default flows through the adapter.
- `detectFromEnv()` restructured: `MOSAIC_STORAGE_TIER` is now checked
  BEFORE the `DATABASE_URL` guard so `MOSAIC_STORAGE_TIER=federated`
  alone returns the federated default config instead of silently
  misrouting to local. Same applies to `=standalone`. With
  `DATABASE_URL` set, the URL is honored and `enableVector` is preserved
  on federated.
- `detectFromEnv` is now exported for direct test access.

Tests:
- 4 PostgresAdapter unit tests cover: extension SQL issued when enabled,
  not issued when disabled or unset, ordering (extension before
  runMigrations). Assertion uses Drizzle's `toSQL()` with documented
  fallback for older versions.
- 4 detectFromEnv tests cover the four env-var permutations.
- 1 federated default constant test.

No behavior change for local or standalone tier deployments.

Refs #460

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-19 18:37:25 -05:00
..