@workglow/storage 0.2.31 → 0.2.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/browser.js +977 -48
  2. package/dist/browser.js.map +23 -13
  3. package/dist/bun.js +1030 -53
  4. package/dist/bun.js.map +24 -14
  5. package/dist/common.d.ts +7 -0
  6. package/dist/common.d.ts.map +1 -1
  7. package/dist/migrations/IMigration.d.ts +57 -0
  8. package/dist/migrations/IMigration.d.ts.map +1 -0
  9. package/dist/migrations/MigrationRunner.d.ts +44 -0
  10. package/dist/migrations/MigrationRunner.d.ts.map +1 -0
  11. package/dist/migrations/TabularMigration.d.ts +85 -0
  12. package/dist/migrations/TabularMigration.d.ts.map +1 -0
  13. package/dist/migrations/TabularMigrationOrchestrator.d.ts +34 -0
  14. package/dist/migrations/TabularMigrationOrchestrator.d.ts.map +1 -0
  15. package/dist/migrations/index.d.ts +11 -0
  16. package/dist/migrations/index.d.ts.map +1 -0
  17. package/dist/migrations/runBackfill.d.ts +19 -0
  18. package/dist/migrations/runBackfill.d.ts.map +1 -0
  19. package/dist/node.js +1030 -53
  20. package/dist/node.js.map +24 -14
  21. package/dist/sql/Dialect.d.ts +26 -0
  22. package/dist/sql/Dialect.d.ts.map +1 -0
  23. package/dist/sql/PredicateBuilder.d.ts +30 -0
  24. package/dist/sql/PredicateBuilder.d.ts.map +1 -0
  25. package/dist/sql/PrefixDdl.d.ts +79 -0
  26. package/dist/sql/PrefixDdl.d.ts.map +1 -0
  27. package/dist/sql/index.d.ts +9 -0
  28. package/dist/sql/index.d.ts.map +1 -0
  29. package/dist/tabular/BaseSqlTabularStorage.d.ts +63 -2
  30. package/dist/tabular/BaseSqlTabularStorage.d.ts.map +1 -1
  31. package/dist/tabular/BaseTabularStorage.d.ts +111 -6
  32. package/dist/tabular/BaseTabularStorage.d.ts.map +1 -1
  33. package/dist/tabular/CachedTabularStorage.d.ts +38 -0
  34. package/dist/tabular/CachedTabularStorage.d.ts.map +1 -1
  35. package/dist/tabular/Cursor.d.ts +79 -0
  36. package/dist/tabular/Cursor.d.ts.map +1 -0
  37. package/dist/tabular/FsFolderTabularStorage.d.ts +5 -1
  38. package/dist/tabular/FsFolderTabularStorage.d.ts.map +1 -1
  39. package/dist/tabular/HuggingFaceTabularStorage.d.ts +26 -2
  40. package/dist/tabular/HuggingFaceTabularStorage.d.ts.map +1 -1
  41. package/dist/tabular/ITabularStorage.d.ts +203 -3
  42. package/dist/tabular/ITabularStorage.d.ts.map +1 -1
  43. package/dist/tabular/InMemoryTabularMigrationApplier.d.ts +39 -0
  44. package/dist/tabular/InMemoryTabularMigrationApplier.d.ts.map +1 -0
  45. package/dist/tabular/InMemoryTabularStorage.d.ts +6 -2
  46. package/dist/tabular/InMemoryTabularStorage.d.ts.map +1 -1
  47. package/dist/tabular/SharedInMemoryTabularStorage.d.ts +4 -1
  48. package/dist/tabular/SharedInMemoryTabularStorage.d.ts.map +1 -1
  49. package/dist/tabular/SqlTabularMigrationApplier.d.ts +53 -0
  50. package/dist/tabular/SqlTabularMigrationApplier.d.ts.map +1 -0
  51. package/dist/tabular/StorageError.d.ts.map +1 -1
  52. package/dist/tabular/TelemetryTabularStorage.d.ts +11 -1
  53. package/dist/tabular/TelemetryTabularStorage.d.ts.map +1 -1
  54. package/dist/tabular/sqlMigrationDdl.d.ts +11 -0
  55. package/dist/tabular/sqlMigrationDdl.d.ts.map +1 -0
  56. package/dist/vector/IVectorStorage.d.ts +61 -1
  57. package/dist/vector/IVectorStorage.d.ts.map +1 -1
  58. package/package.json +3 -3
  59. package/src/tabular/README.md +73 -0
  60. package/src/vector/README.md +79 -0
@@ -4,7 +4,8 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import type { DataPortSchemaObject, FromSchema, TypedArraySchemaOptions } from "@workglow/util/schema";
7
- import type { AutoGeneratedKeys, CoveringIndexQueryOptions, DeleteSearchCriteria, InsertEntity, ITabularStorage, QueryOptions, SearchCriteria, SimplifyPrimaryKey, TabularChangePayload, TabularEventListener, TabularEventName, TabularEventParameters, TabularSubscribeOptions } from "./ITabularStorage";
7
+ import type { ITabularMigrationApplier } from "../migrations";
8
+ import type { AutoGeneratedKeys, CoveringIndexQueryOptions, DeleteSearchCriteria, InsertEntity, ITabularStorage, Page, PageRequest, QueryOptions, SearchCriteria, SimplifyPrimaryKey, TabularChangePayload, TabularEventListener, TabularEventName, TabularEventParameters, TabularSubscribeOptions } from "./ITabularStorage";
8
9
  /**
9
10
  * Telemetry wrapper for any ITabularStorage implementation.
10
11
  * Creates spans for all storage operations.
@@ -23,12 +24,21 @@ export declare class TelemetryTabularStorage<Schema extends DataPortSchemaObject
23
24
  count(criteria?: SearchCriteria<Entity>): Promise<number>;
24
25
  deleteSearch(criteria: DeleteSearchCriteria<Entity>): Promise<void>;
25
26
  getBulk(offset: number, limit: number): Promise<Entity[] | undefined>;
27
+ getPage(request?: PageRequest<Entity>): Promise<Page<Entity>>;
28
+ queryPage(criteria: SearchCriteria<Entity>, request?: PageRequest<Entity>): Promise<Page<Entity>>;
26
29
  query(criteria: SearchCriteria<Entity>, options?: QueryOptions<Entity>): Promise<Entity[] | undefined>;
27
30
  queryIndex<K extends keyof Entity & string>(criteria: SearchCriteria<Entity>, options: CoveringIndexQueryOptions<Entity, K>): Promise<Pick<Entity, K>[]>;
28
31
  records(pageSize?: number): AsyncGenerator<Entity, void, undefined>;
29
32
  pages(pageSize?: number): AsyncGenerator<Entity[], void, undefined>;
30
33
  subscribeToChanges(callback: (change: TabularChangePayload<Entity>) => void, options?: TabularSubscribeOptions): () => void;
34
+ withTransaction<T>(fn: (tx: this) => Promise<T>): Promise<T>;
31
35
  setupDatabase(): Promise<void>;
36
+ /**
37
+ * Forwards to the inner storage's applier so callers that wrap a
38
+ * migration-aware storage in TelemetryTabularStorage still observe
39
+ * declared migrations.
40
+ */
41
+ getMigrationApplier(): ITabularMigrationApplier | null;
32
42
  destroy(): void;
33
43
  [Symbol.dispose](): void;
34
44
  [Symbol.asyncDispose](): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"TelemetryTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/TelemetryTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,qBAAa,uBAAuB,CAClC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EACjE,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,EACpD,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,eAAe,CAAC,EACxD,UAAU,GAAG,YAAY,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAC5D,YAAW,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;IAEjF,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM;IACtC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CACvC,MAAM,EACN,eAAe,EACf,MAAM,EACN,UAAU,EACV,UAAU,CACX;IARH,YACqB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,eAAe,CACvC,MAAM,EACN,eAAe,EACf,MAAM,EACN,UAAU,EACV,UAAU,CACX,EACC;IAEJ,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtC;IAED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":3,"file":"TelemetryTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/TelemetryTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,qBAAa,uBAAuB,CAClC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EACjE,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,EACpD,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,eAAe,CAAC,EACxD,UAAU,GAAG,YAAY,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAC5D,YAAW,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;IAEjF,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM;IACtC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CACvC,MAAM,EACN,eAAe,EACf,MAAM,EACN,UAAU,EACV,UAAU,CACX;IARH,YACqB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,eAAe,CACvC,MAAM,EACN,eAAe,EACf,MAAM,EACN,UAAU,EACV,UAAU,CACX,EACC;IAEJ,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC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AC,GAClD,IAAI,CAEN;IAED,IAAI,CAAC,KAAK,SAAS,gBAAgB,EACjC,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GACzD,IAAI,CAEN;IAED,IAAI,CAAC,KAAK,SAAS,gBAAgB,EACjC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAClD,IAAI,CAEN;IAED,MAAM,CAAC,KAAK,SAAS,gBAAgB,EACnC,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAE5D;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare function buildAddColumnSql(dialect: "sqlite" | "postgres", table: string, column: string, sqlType: string, nullable: boolean, hasDefault?: boolean, defaultLiteralSql?: string): string;
7
+ export declare function buildDropColumnSql(dialect: "sqlite" | "postgres", table: string, column: string): string;
8
+ export declare function buildRenameColumnSql(dialect: "sqlite" | "postgres", table: string, from: string, to: string): string;
9
+ export declare function buildAddIndexSql(dialect: "sqlite" | "postgres", table: string, indexName: string, columns: readonly string[], unique: boolean): string;
10
+ export declare function buildDropIndexSql(dialect: "sqlite" | "postgres", indexName: string): string;
11
+ //# sourceMappingURL=sqlMigrationDdl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlMigrationDdl.d.ts","sourceRoot":"","sources":["../../src/tabular/sqlMigrationDdl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,QAAQ,GAAG,UAAU,EAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,EACjB,UAAU,GAAE,OAAe,EAC3B,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,CAQR;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,QAAQ,GAAG,UAAU,EAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,MAAM,CAGR;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,QAAQ,GAAG,UAAU,EAC9B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,MAAM,CAGR;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,QAAQ,GAAG,UAAU,EAC9B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,MAAM,EAAE,OAAO,GACd,MAAM,CAOR;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG3F"}
@@ -6,9 +6,69 @@
6
6
  import type { DataPortSchemaObject, FromSchema, TypedArray, TypedArraySchemaOptions } from "@workglow/util/schema";
7
7
  import type { EventParameters } from "@workglow/util";
8
8
  import type { AutoGeneratedKeys, InsertEntity, ITabularStorage, SimplifyPrimaryKey, TabularEventListeners } from "../tabular/ITabularStorage";
9
- export type AnyVectorStorage = Omit<IVectorStorage<any, any, any, any>, "queryIndex"> & {
9
+ export type AnyVectorStorage = Omit<IVectorStorage<any, any, any, any>, "queryIndex" | "withTransaction"> & {
10
10
  queryIndex(criteria: any, options: any): Promise<any[]>;
11
+ withTransaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
11
12
  };
13
+ /**
14
+ * Distance metric used by vector indexes.
15
+ *
16
+ * - `cosine`: cosine distance (1 - cosine similarity). Default for embedding
17
+ * models that produce normalised vectors. Recommended starting point for
18
+ * text/RAG workloads.
19
+ * - `l2`: euclidean distance. Use when vectors carry magnitude information.
20
+ * - `ip`: negative inner product. Use when embeddings are pre-normalised AND
21
+ * you want a slightly cheaper similarity computation than cosine.
22
+ */
23
+ export type VectorDistanceMetric = "cosine" | "l2" | "ip";
24
+ /**
25
+ * HNSW index parameters. HNSW is the default approximate-nearest-neighbour
26
+ * algorithm in pgvector and other modern vector indexes; tuning these knobs
27
+ * trades index build cost and memory for recall and query latency.
28
+ *
29
+ * Defaults from pgvector when unspecified: `m = 16`, `efConstruction = 64`,
30
+ * `efSearch = 40`.
31
+ *
32
+ * - `m`: number of bi-directional links per layer. Higher = better recall,
33
+ * more memory, slower build. Typical values: 8 (low-recall), 16 (default),
34
+ * 32 (high-recall).
35
+ * - `efConstruction`: candidate-list size during index build. Higher = better
36
+ * recall, much slower build. Typical values: 64 (default), 200, 400.
37
+ * - `efSearch`: candidate-list size at query time. Higher = better recall,
38
+ * slower queries. Typical values: 40 (default), 80, 200. This is the knob
39
+ * you want to tune at query time once the index is built.
40
+ */
41
+ export interface HnswIndexOptions {
42
+ readonly m?: number;
43
+ readonly efConstruction?: number;
44
+ readonly efSearch?: number;
45
+ }
46
+ /**
47
+ * IVFFlat index parameters (pgvector). Offers faster builds than HNSW at the
48
+ * cost of recall, useful for very large corpora.
49
+ *
50
+ * - `lists`: number of inverted lists. pgvector docs recommend `rows / 1000`
51
+ * for up to 1M rows, then `sqrt(rows)` for larger sets.
52
+ * - `probes`: number of lists scanned at query time. Higher = better recall,
53
+ * slower queries. Default `1`.
54
+ */
55
+ export interface IvfflatIndexOptions {
56
+ readonly lists: number;
57
+ readonly probes?: number;
58
+ }
59
+ /**
60
+ * Vector-index tuning options threaded into the storage constructor and
61
+ * applied during {@link IVectorStorage} setup / migration.
62
+ *
63
+ * Only one of `hnsw` or `ivfflat` should be set; if both are absent the
64
+ * backend uses a sensible default (HNSW on pgvector, COSINE-only for
65
+ * sqlite-vec which does not yet support HNSW tuning).
66
+ */
67
+ export interface VectorIndexOptions {
68
+ readonly distance?: VectorDistanceMetric;
69
+ readonly hnsw?: HnswIndexOptions;
70
+ readonly ivfflat?: IvfflatIndexOptions;
71
+ }
12
72
  /**
13
73
  * Options for vector search operations
14
74
  */
@@ -1 +1 @@
1
- {"version":3,"file":"IVectorStorage.d.ts","sourceRoot":"","sources":["../../src/vector/IVectorStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EAEV,UAAU,EACV,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;IACtF,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAClC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE9E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAClC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC9E,SAAQ,mBAAmB,CAAC,QAAQ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BAAoB,EACrE,MAAM,EAAE,MAAM,GACb,MAAM,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAOxC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workglow/storage",
3
3
  "type": "module",
4
- "version": "0.2.31",
4
+ "version": "0.2.32",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/workglow-dev/workglow.git",
@@ -26,7 +26,7 @@
26
26
  "test": "bun test"
27
27
  },
28
28
  "peerDependencies": {
29
- "@workglow/util": "0.2.31"
29
+ "@workglow/util": "0.2.32"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "@workglow/util": {
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "devDependencies": {
37
- "@workglow/util": "0.2.31"
37
+ "@workglow/util": "0.2.32"
38
38
  },
39
39
  "exports": {
40
40
  ".": {
@@ -21,6 +21,7 @@ A collection of storage implementations for tabular data with multiple backend s
21
21
  - [PostgresTabularStorage](#postgrestabularstorage)
22
22
  - [IndexedDbTabularStorage](#indexeddbtabularstorage)
23
23
  - [FsFolderTabularStorage](#fsfoldertabularstorage)
24
+ - [Migrations](#migrations)
24
25
  - [Events](#events)
25
26
  - [Testing](#testing)
26
27
  - [License](#license)
@@ -434,6 +435,78 @@ const repo = new FsFolderTabularStorage<
434
435
  >("./data/users", schema, primaryKeys);
435
436
  ```
436
437
 
438
+ ## Migrations
439
+
440
+ Tabular storages accept an optional `tabularMigrations` constructor parameter — a versioned, ordered list of declarative ops that evolve older deployments to the current target schema. Migrations work uniformly across all backends (SQL, IndexedDB, schemaless) and reuse the `_storage_migrations` bookkeeping table the rest of the migration system already uses.
441
+
442
+ ```typescript
443
+ import { SqliteTabularStorage } from "@workglow/sqlite/storage";
444
+ import type { ITabularMigration } from "@workglow/storage";
445
+
446
+ const migrations: ITabularMigration[] = [
447
+ {
448
+ version: 1,
449
+ description: "add archived flag",
450
+ ops: [
451
+ // Note: ALTER TABLE ADD COLUMN NOT NULL fails on populated tables in
452
+ // SQL backends without a DEFAULT, so use a nullable schema.
453
+ {
454
+ kind: "addColumn",
455
+ name: "archived",
456
+ schema: { anyOf: [{ type: "boolean" }, { type: "null" }] },
457
+ },
458
+ { kind: "addIndex", name: "idx_archived", columns: ["archived"] },
459
+ ],
460
+ },
461
+ {
462
+ version: 2,
463
+ description: "rename status -> state",
464
+ ops: [{ kind: "renameColumn", from: "status", to: "state" }],
465
+ },
466
+ {
467
+ version: 3,
468
+ description: "lowercase emails",
469
+ ops: [
470
+ {
471
+ kind: "backfill",
472
+ batchSize: 500,
473
+ transform: (row) => ({ ...row, email: (row.email as string).toLowerCase() }),
474
+ },
475
+ ],
476
+ },
477
+ ];
478
+
479
+ const repo = new SqliteTabularStorage(
480
+ db,
481
+ "users",
482
+ schema,
483
+ ["id"] as const,
484
+ [],
485
+ "if-missing",
486
+ migrations
487
+ );
488
+ await repo.setupDatabase(); // applies pending migrations
489
+ ```
490
+
491
+ **Op coverage:** `addColumn`, `dropColumn`, `renameColumn`, `addIndex`, `dropIndex`, `backfill`.
492
+
493
+ **Backend behavior:**
494
+
495
+ - **SQL backends** (SQLite, Postgres, Supabase): DDL ops translate to native `ALTER TABLE` / `CREATE INDEX`. Each migration runs inside a single `withTransaction` so DDL + backfill + bookkeeping commit atomically.
496
+ - **IndexedDB**: `addIndex` / `dropIndex` run inside an upgrade transaction. `backfill` runs on a normal readwrite transaction afterward (IDB upgrade transactions cannot span async work).
497
+ - **InMemory / SharedInMemory / FsFolder / HuggingFace**: DDL ops are no-ops (records are JS objects). `backfill` runs through the normal `getPage` / `put` / `delete` API. FsFolder persists bookkeeping to `_storage_migrations.json` beside the data; others hold it in process.
498
+
499
+ **Fresh-DB fast path:** when a storage is constructed at the target schema and the underlying table/store is empty, the orchestrator records every declared migration as already-applied without running its ops. This keeps backfills from running against zero rows on a fresh deployment.
500
+
501
+ **Adoption:**
502
+
503
+ - Existing storages without `tabularMigrations` continue unchanged — the migration system is fully opt-in.
504
+ - **Fresh-DB fast path:** when a storage is opened with declared migrations against a brand-new database (no prior bookkeeping AND no pre-existing table), every declared migration is recorded as already-applied without executing its ops. A fresh deployment therefore never runs `addColumn` against a table that was just created at the target schema.
505
+ - **Index ops are idempotent at the DDL level:** `addIndex` / `dropIndex` emit `CREATE INDEX IF NOT EXISTS` / `DROP INDEX IF EXISTS` on SQL backends, and the IndexedDB applier guards `createIndex` / `deleteIndex` with `objectStore.indexNames.contains`. Retries after partial failures are safe.
506
+ - **Column ops are NOT idempotent at the DDL level:** `addColumn` / `dropColumn` / `renameColumn` emit plain `ALTER TABLE` statements. Re-running a successful migration is prevented by the bookkeeping table (`_storage_migrations` records the applied `(component, version)`), not by the DDL itself.
507
+
508
+ See `docs/superpowers/specs/2026-05-07-unified-tabular-migrations-design.md` for the full design and `docs/superpowers/plans/2026-05-07-unified-tabular-migrations.md` for implementation notes.
509
+
437
510
  ## Events
438
511
 
439
512
  All implementations emit events:
@@ -347,6 +347,85 @@ Quantized vectors reduce storage and can improve performance:
347
347
  - **Cons:** Requires PostgreSQL server and pgvector extension
348
348
  - **Setup:** `CREATE EXTENSION vector;`
349
349
 
350
+ ## Vector Index Tuning
351
+
352
+ `PostgresVectorStorage` (from `@workglow/postgres/storage`) and
353
+ `SqliteAiVectorStorage` (from `@workglow/sqlite/storage`) accept a
354
+ `VectorIndexOptions` constructor argument that controls the underlying index
355
+ type and its recall/latency trade-offs.
356
+
357
+ ```typescript
358
+ import { PostgresVectorStorage } from "@workglow/postgres/storage";
359
+
360
+ const repo = new PostgresVectorStorage(
361
+ pool,
362
+ "vectors",
363
+ schema,
364
+ ["id"],
365
+ [],
366
+ 768,
367
+ Float32Array,
368
+ {
369
+ distance: "cosine",
370
+ hnsw: { m: 16, efConstruction: 64, efSearch: 80 },
371
+ // or, for very large corpora:
372
+ // ivfflat: { lists: 1000, probes: 10 },
373
+ }
374
+ );
375
+ ```
376
+
377
+ ### Recall vs latency cheat sheet
378
+
379
+ | Backend | Index | Tunable | Recall ↑ knob | Latency ↓ knob | Notes |
380
+ | --- | --- | --- | --- | --- | --- |
381
+ | `PostgresVectorStorage` (pgvector) | HNSW (default) | `m`, `efConstruction`, `efSearch` | raise `m` (8 → 16 → 32), `efConstruction` (64 → 200 → 400), `efSearch` (40 → 80 → 200) | lower the same knobs | `m` and `efConstruction` are build-time; rebuilding the index is required to change them. `efSearch` is per-session — see note below. |
382
+ | `PostgresVectorStorage` (pgvector) | IVFFlat | `lists`, `probes` | raise `probes` (1 → 10 → 50) | lower `probes` | Use when build time matters more than peak recall. Pgvector docs: `lists ≈ rows / 1000` up to 1M rows, `≈ sqrt(rows)` beyond. |
383
+ | `SqliteAiVectorStorage` (sqlite-vector) | brute-force `vector_full_scan` | cosine only | n/a (always exact) | shrink corpus / lower `topK` | sqlite-vector does not yet expose HNSW; recall is 100% but latency is O(n). The constructor rejects non-cosine distances rather than silently producing wrong scores. |
384
+ | `InMemoryVectorStorage` | brute-force JS cosine | n/a | n/a (always exact) | shrink corpus / lower `topK` | Recall is 100%; intended for tests and small corpora only. |
385
+ | `IndexedDbVectorStorage` | brute-force JS cosine | n/a | n/a (always exact) | shrink corpus / lower `topK` | Browser-only; same trade-offs as InMemory. |
386
+
387
+ ### Applying `efSearch` / `probes` at query time
388
+
389
+ Pgvector reads `hnsw.ef_search` and `ivfflat.probes` from the active session.
390
+ With a node-postgres `Pool`, every `pool.query()` checks out a fresh client, so
391
+ running `SET hnsw.ef_search = N` before the search query has no effect. To apply
392
+ query-time tuning, either:
393
+
394
+ 1. Set it on the role/database so all connections inherit it:
395
+ `ALTER ROLE workglow SET hnsw.ef_search = 80;`
396
+ 2. Run searches against a single checked-out client inside a transaction:
397
+ ```sql
398
+ BEGIN;
399
+ SET LOCAL hnsw.ef_search = 80;
400
+ SELECT * FROM vectors ORDER BY embedding <=> $1::vector LIMIT 10;
401
+ COMMIT;
402
+ ```
403
+
404
+ `PostgresVectorStorage.getQueryTuning()` returns the configured values so a
405
+ caller can wire them into either approach.
406
+
407
+ ## Migrations
408
+
409
+ Production code should run schema changes through versioned migrations rather
410
+ than the legacy `setupDatabase()` shim. Each SQL backend exposes
411
+ `migrate()` (idempotent, safe to call repeatedly) and `getMigrations()`
412
+ (returns the migration set so callers can compose several backends under a
413
+ single runner).
414
+
415
+ ```typescript
416
+ import { PostgresMigrationRunner } from "@workglow/postgres/storage";
417
+
418
+ const runner = new PostgresMigrationRunner(pool);
419
+ await runner.run([
420
+ ...queue.getMigrations(),
421
+ ...rateLimiter.getMigrations(),
422
+ ]);
423
+ ```
424
+
425
+ `setupDatabase()` is `@deprecated` on `IQueueStorage`, `IRateLimiterStorage`,
426
+ and `ITabularStorage` — it now delegates to `migrate()` for SQL backends so
427
+ existing tests keep working.
428
+
350
429
  ## Integration with KnowledgeBase
351
430
 
352
431
  The chunk vector repository works alongside `KnowledgeBase` for hierarchical document storage: