@mastra/pg 0.13.0 → 0.13.1

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 (50) hide show
  1. package/.turbo/turbo-build.log +2 -21
  2. package/CHANGELOG.md +23 -0
  3. package/dist/index.cjs +29 -17
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +4 -5
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +29 -17
  8. package/dist/index.js.map +1 -0
  9. package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
  10. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  11. package/dist/storage/domains/memory/index.d.ts +88 -0
  12. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  13. package/dist/storage/domains/operations/index.d.ts +50 -0
  14. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  15. package/dist/storage/domains/scores/index.d.ts +44 -0
  16. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  17. package/dist/storage/domains/traces/index.d.ts +23 -0
  18. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  19. package/dist/storage/domains/utils.d.ts +6 -0
  20. package/dist/storage/domains/utils.d.ts.map +1 -0
  21. package/dist/storage/domains/workflows/index.d.ts +36 -0
  22. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  23. package/dist/storage/index.d.ts +211 -0
  24. package/dist/storage/index.d.ts.map +1 -0
  25. package/dist/storage/test-utils.d.ts +5 -0
  26. package/dist/storage/test-utils.d.ts.map +1 -0
  27. package/dist/vector/filter.d.ts +32 -0
  28. package/dist/vector/filter.d.ts.map +1 -0
  29. package/dist/vector/index.d.ts +99 -0
  30. package/dist/vector/index.d.ts.map +1 -0
  31. package/dist/vector/performance.helpers.d.ts +95 -0
  32. package/dist/vector/performance.helpers.d.ts.map +1 -0
  33. package/dist/vector/prompt.d.ts +6 -0
  34. package/dist/vector/prompt.d.ts.map +1 -0
  35. package/dist/vector/sql-builder.d.ts +8 -0
  36. package/dist/vector/sql-builder.d.ts.map +1 -0
  37. package/dist/vector/types.d.ts +15 -0
  38. package/dist/vector/types.d.ts.map +1 -0
  39. package/package.json +5 -5
  40. package/src/storage/domains/operations/index.ts +5 -3
  41. package/src/storage/domains/scores/index.ts +22 -8
  42. package/src/storage/domains/workflows/index.ts +5 -5
  43. package/src/storage/index.test.ts +1 -0
  44. package/src/storage/index.ts +1 -1
  45. package/tsconfig.build.json +9 -0
  46. package/tsconfig.json +1 -1
  47. package/tsup.config.ts +22 -0
  48. package/dist/_tsup-dts-rollup.d.cts +0 -786
  49. package/dist/_tsup-dts-rollup.d.ts +0 -786
  50. package/dist/index.d.cts +0 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEtD,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE;QACN,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,UAAU,mBAAoB,SAAQ,iBAAiB,CAAC,cAAc,CAAC;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OA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ACP,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IA4FzC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAsE1F,OAAO,CAAC,MAAM,CAAY;YACZ,gBAAgB;IAS9B,OAAO,CAAC,iBAAiB;YAIX,WAAW;IAmDnB,WAAW,CAAC,EAChB,SAAS,EACT,SAAS,EACT,MAAiB,EACjB,WAAgB,EAChB,UAAiB,GAClB,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuFhC,UAAU,CAAC,EAAE,SAAS,EAAE,MAAiB,EAAE,WAAW,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;YAuBrF,UAAU;YAoDV,sBAAsB;IAoD9B,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IA4BtC;;;;;OAKG;IACG,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;IA4GxE,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B5D,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9D,UAAU;IAIhB;;;;;;;;;OASG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DhF;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CA6BzE"}
@@ -0,0 +1,95 @@
1
+ import type { IndexConfig, IndexType } from './types';
2
+ import type { PgVector } from '.';
3
+ export interface TestResult {
4
+ distribution: string;
5
+ dimension: number;
6
+ type: IndexType;
7
+ size: number;
8
+ k?: number;
9
+ metrics: {
10
+ recall?: number;
11
+ minRecall?: number;
12
+ maxRecall?: number;
13
+ latency?: {
14
+ p50: number;
15
+ p95: number;
16
+ lists?: number;
17
+ vectorsPerList?: number;
18
+ m?: number;
19
+ ef?: number;
20
+ };
21
+ clustering?: {
22
+ numLists?: number;
23
+ avgVectorsPerList?: number;
24
+ recommendedLists?: number;
25
+ distribution?: string;
26
+ };
27
+ };
28
+ }
29
+ export declare const generateRandomVectors: (count: number, dim: number) => number[][];
30
+ export declare const generateClusteredVectors: (count: number, dim: number, numClusters?: number) => number[][];
31
+ export declare const generateSkewedVectors: (count: number, dim: number) => number[][];
32
+ export declare const findNearestBruteForce: (query: number[], vectors: number[][], k: number) => number[];
33
+ export declare const calculateRecall: (actual: number[], expected: number[], k: number) => number;
34
+ export declare function cosineSimilarity(a: number[], b: number[]): number;
35
+ export declare const formatTable: (data: any[], columns: string[]) => string;
36
+ export declare const groupBy: <T, K extends keyof T>(array: T[], key: K | ((item: T) => string), reducer?: (group: T[]) => any) => Record<string, any>;
37
+ export declare const calculateTimeout: (dimension: number, size: number, k: number) => number;
38
+ export declare const baseTestConfigs: {
39
+ smokeTests: {
40
+ dimension: number;
41
+ size: number;
42
+ k: number;
43
+ queryCount: number;
44
+ }[];
45
+ '64': {
46
+ dimension: number;
47
+ size: number;
48
+ k: number;
49
+ queryCount: number;
50
+ }[];
51
+ '384': {
52
+ dimension: number;
53
+ size: number;
54
+ k: number;
55
+ queryCount: number;
56
+ }[];
57
+ '1024': {
58
+ dimension: number;
59
+ size: number;
60
+ k: number;
61
+ queryCount: number;
62
+ }[];
63
+ stressTests: {
64
+ dimension: number;
65
+ size: number;
66
+ k: number;
67
+ queryCount: number;
68
+ }[];
69
+ };
70
+ export interface TestConfig {
71
+ dimension: number;
72
+ size: number;
73
+ k: number;
74
+ queryCount: number;
75
+ }
76
+ export declare function warmupQuery(vectorDB: PgVector, indexName: string, dimension: number, k: number): Promise<void>;
77
+ export declare function measureLatency<T>(fn: () => Promise<T>): Promise<[number, T]>;
78
+ export declare const getListCount: (indexConfig: IndexConfig, size: number) => number | undefined;
79
+ export declare const getHNSWConfig: (indexConfig: IndexConfig) => {
80
+ m: number;
81
+ efConstruction: number;
82
+ };
83
+ export declare function getSearchEf(k: number, m: number): {
84
+ default: number;
85
+ lower: number;
86
+ higher: number;
87
+ };
88
+ export declare function getIndexDescription({ type, hnsw, }: {
89
+ type: IndexType;
90
+ hnsw: {
91
+ m: number;
92
+ efConstruction: number;
93
+ };
94
+ }): string;
95
+ //# sourceMappingURL=performance.helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performance.helpers.d.ts","sourceRoot":"","sources":["../../src/vector/performance.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAElC,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,OAAO,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE;YACR,GAAG,EAAE,MAAM,CAAC;YACZ,GAAG,EAAE,MAAM,CAAC;YACZ,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,CAAC,CAAC,EAAE,MAAM,CAAC;YACX,EAAE,CAAC,EAAE,MAAM,CAAC;SACb,CAAC;QACF,UAAU,CAAC,EAAE;YACX,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,iBAAiB,CAAC,EAAE,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U;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,iBAGpG;AAED,wBAAsB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAKlF;AAED,eAAO,MAAM,YAAY,GAAI,aAAa,WAAW,EAAE,MAAM,MAAM,KAAG,MAAM,GAAG,SAI9E,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,aAAa,WAAW,KAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAK3F,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;;;;EAM/C;AAED,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,IAAI,GACL,EAAE;IACD,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,GAAG,MAAM,CAUT"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Vector store specific prompt that details supported operators and examples.
3
+ * This prompt helps users construct valid filters for PG Vector.
4
+ */
5
+ export declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Direct RegExp patterns will throw an error\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Basic operators handle array values as JSON strings\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$contains\": \"value\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
6
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/vector/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,eAAe,gvIAgG1B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { PGVectorFilter } from './filter';
2
+ interface FilterResult {
3
+ sql: string;
4
+ values: any[];
5
+ }
6
+ export declare function buildFilterQuery(filter: PGVectorFilter, minScore: number, topK: number): FilterResult;
7
+ export {};
8
+ //# sourceMappingURL=sql-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../src/vector/sql-builder.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAqO/C,UAAU,YAAY;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,GAAG,EAAE,CAAC;CACf;AAWD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAwGrG"}
@@ -0,0 +1,15 @@
1
+ export type IndexType = 'ivfflat' | 'hnsw' | 'flat';
2
+ interface IVFConfig {
3
+ lists?: number;
4
+ }
5
+ interface HNSWConfig {
6
+ m?: number;
7
+ efConstruction?: number;
8
+ }
9
+ export interface IndexConfig {
10
+ type?: IndexType;
11
+ ivf?: IVFConfig;
12
+ hnsw?: HNSWConfig;
13
+ }
14
+ export {};
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vector/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,UAAU,SAAS;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAClB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,15 +33,15 @@
33
33
  "tsup": "^8.5.0",
34
34
  "typescript": "^5.8.3",
35
35
  "vitest": "^3.2.4",
36
- "@internal/lint": "0.0.24",
37
- "@internal/storage-test-utils": "0.0.20",
38
- "@mastra/core": "0.12.0"
36
+ "@internal/storage-test-utils": "0.0.21",
37
+ "@internal/lint": "0.0.25",
38
+ "@mastra/core": "0.12.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@mastra/core": ">=0.12.0-0 <0.13.0-0"
42
42
  },
43
43
  "scripts": {
44
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
44
+ "build": "tsup --silent --config tsup.config.ts",
45
45
  "build:watch": "pnpm build --watch",
46
46
  "pretest": "docker compose up -d && (for i in $(seq 1 30); do docker compose exec -T db pg_isready -U postgres && break || (sleep 1; [ $i -eq 30 ] && exit 1); done)",
47
47
  "test": "vitest run",
@@ -43,7 +43,7 @@ export class StoreOperationsPG extends StoreOperations {
43
43
  const schemaExists = await this.client.oneOrNone(
44
44
  `
45
45
  SELECT EXISTS (
46
- SELECT 1 FROM information_schema.schemata
46
+ SELECT 1 FROM information_schema.schemata
47
47
  WHERE schema_name = $1
48
48
  )
49
49
  `,
@@ -183,6 +183,8 @@ export class StoreOperationsPG extends StoreOperations {
183
183
 
184
184
  const finalColumns = [...columns, ...timeZColumns].join(',\n');
185
185
 
186
+ // Constraints are global to a database, ensure schemas do not conflict with each other
187
+ const constraintPrefix = this.schemaName ? `${this.schemaName}_` : '';
186
188
  const sql = `
187
189
  CREATE TABLE IF NOT EXISTS ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} (
188
190
  ${finalColumns}
@@ -192,10 +194,10 @@ export class StoreOperationsPG extends StoreOperations {
192
194
  ? `
193
195
  DO $$ BEGIN
194
196
  IF NOT EXISTS (
195
- SELECT 1 FROM pg_constraint WHERE conname = 'mastra_workflow_snapshot_workflow_name_run_id_key'
197
+ SELECT 1 FROM pg_constraint WHERE conname = '${constraintPrefix}mastra_workflow_snapshot_workflow_name_run_id_key'
196
198
  ) THEN
197
199
  ALTER TABLE ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })}
198
- ADD CONSTRAINT mastra_workflow_snapshot_workflow_name_run_id_key
200
+ ADD CONSTRAINT ${constraintPrefix}mastra_workflow_snapshot_workflow_name_run_id_key
199
201
  UNIQUE (workflow_name, run_id);
200
202
  END IF;
201
203
  END $$;
@@ -4,6 +4,7 @@ import type { ScoreRowData } from '@mastra/core/scores';
4
4
  import { ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
5
5
  import type { IDatabase } from 'pg-promise';
6
6
  import type { StoreOperationsPG } from '../operations';
7
+ import { getTableName } from '../utils';
7
8
 
8
9
  function transformScoreRow(row: Record<string, any>): ScoreRowData {
9
10
  let input = undefined;
@@ -26,16 +27,29 @@ function transformScoreRow(row: Record<string, any>): ScoreRowData {
26
27
  export class ScoresPG extends ScoresStorage {
27
28
  public client: IDatabase<{}>;
28
29
  private operations: StoreOperationsPG;
30
+ private schema?: string;
29
31
 
30
- constructor({ client, operations }: { client: IDatabase<{}>; operations: StoreOperationsPG }) {
32
+ constructor({
33
+ client,
34
+ operations,
35
+ schema,
36
+ }: {
37
+ client: IDatabase<{}>;
38
+ operations: StoreOperationsPG;
39
+ schema?: string;
40
+ }) {
31
41
  super();
32
42
  this.client = client;
33
43
  this.operations = operations;
44
+ this.schema = schema;
34
45
  }
35
46
 
36
47
  async getScoreById({ id }: { id: string }): Promise<ScoreRowData | null> {
37
48
  try {
38
- const result = await this.client.oneOrNone<ScoreRowData>(`SELECT * FROM ${TABLE_SCORERS} WHERE id = $1`, [id]);
49
+ const result = await this.client.oneOrNone<ScoreRowData>(
50
+ `SELECT * FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE id = $1`,
51
+ [id],
52
+ );
39
53
 
40
54
  return transformScoreRow(result!);
41
55
  } catch (error) {
@@ -59,7 +73,7 @@ export class ScoresPG extends ScoresStorage {
59
73
  }): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
60
74
  try {
61
75
  const total = await this.client.oneOrNone<{ count: string }>(
62
- `SELECT COUNT(*) FROM ${TABLE_SCORERS} WHERE "scorerId" = $1`,
76
+ `SELECT COUNT(*) FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE "scorerId" = $1`,
63
77
  [scorerId],
64
78
  );
65
79
  if (total?.count === '0' || !total?.count) {
@@ -75,7 +89,7 @@ export class ScoresPG extends ScoresStorage {
75
89
  }
76
90
 
77
91
  const result = await this.client.manyOrNone<ScoreRowData>(
78
- `SELECT * FROM ${TABLE_SCORERS} WHERE "scorerId" = $1 LIMIT $2 OFFSET $3`,
92
+ `SELECT * FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE "scorerId" = $1 LIMIT $2 OFFSET $3`,
79
93
  [scorerId, pagination.perPage, pagination.page * pagination.perPage],
80
94
  );
81
95
  return {
@@ -135,7 +149,7 @@ export class ScoresPG extends ScoresStorage {
135
149
  }): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
136
150
  try {
137
151
  const total = await this.client.oneOrNone<{ count: string }>(
138
- `SELECT COUNT(*) FROM ${TABLE_SCORERS} WHERE "runId" = $1`,
152
+ `SELECT COUNT(*) FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE "runId" = $1`,
139
153
  [runId],
140
154
  );
141
155
  console.log(`total: ${total?.count}`);
@@ -153,7 +167,7 @@ export class ScoresPG extends ScoresStorage {
153
167
  }
154
168
 
155
169
  const result = await this.client.manyOrNone<ScoreRowData>(
156
- `SELECT * FROM ${TABLE_SCORERS} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
170
+ `SELECT * FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
157
171
  [runId, pagination.perPage, pagination.page * pagination.perPage],
158
172
  );
159
173
  return {
@@ -188,7 +202,7 @@ export class ScoresPG extends ScoresStorage {
188
202
  }): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
189
203
  try {
190
204
  const total = await this.client.oneOrNone<{ count: string }>(
191
- `SELECT COUNT(*) FROM ${TABLE_SCORERS} WHERE "entityId" = $1 AND "entityType" = $2`,
205
+ `SELECT COUNT(*) FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE "entityId" = $1 AND "entityType" = $2`,
192
206
  [entityId, entityType],
193
207
  );
194
208
 
@@ -205,7 +219,7 @@ export class ScoresPG extends ScoresStorage {
205
219
  }
206
220
 
207
221
  const result = await this.client.manyOrNone<ScoreRowData>(
208
- `SELECT * FROM ${TABLE_SCORERS} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
222
+ `SELECT * FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: this.schema })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
209
223
  [entityId, entityType, pagination.perPage, pagination.page * pagination.perPage],
210
224
  );
211
225
  return {
@@ -57,7 +57,7 @@ export class WorkflowsPG extends WorkflowsStorage {
57
57
  try {
58
58
  const now = new Date().toISOString();
59
59
  await this.client.none(
60
- `INSERT INTO ${TABLE_WORKFLOW_SNAPSHOT} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
60
+ `INSERT INTO ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
61
61
  VALUES ($1, $2, $3, $4, $5)
62
62
  ON CONFLICT (workflow_name, run_id) DO UPDATE
63
63
  SET snapshot = $3, "updatedAt" = $5`,
@@ -129,8 +129,8 @@ export class WorkflowsPG extends WorkflowsStorage {
129
129
 
130
130
  // Get results
131
131
  const query = `
132
- SELECT * FROM ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
133
- ${whereClause}
132
+ SELECT * FROM ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
133
+ ${whereClause}
134
134
  `;
135
135
 
136
136
  const queryValues = values;
@@ -220,8 +220,8 @@ export class WorkflowsPG extends WorkflowsStorage {
220
220
 
221
221
  // Get results
222
222
  const query = `
223
- SELECT * FROM ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
224
- ${whereClause}
223
+ SELECT * FROM ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
224
+ ${whereClause}
225
225
  ORDER BY "createdAt" DESC
226
226
  ${limit !== undefined && offset !== undefined ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ''}
227
227
  `;
@@ -6,5 +6,6 @@ import { PostgresStore } from '.';
6
6
  vi.setConfig({ testTimeout: 60_000, hookTimeout: 60_000 });
7
7
 
8
8
  createTestSuite(new PostgresStore(TEST_CONFIG));
9
+ createTestSuite(new PostgresStore({ ...TEST_CONFIG, schemaName: 'my_schema' }));
9
10
 
10
11
  pgTests();
@@ -96,7 +96,7 @@ export class PostgresStore extends MastraStorage {
96
96
  this.client = this.db;
97
97
 
98
98
  const operations = new StoreOperationsPG({ client: this.client, schemaName: this.schema });
99
- const scores = new ScoresPG({ client: this.client, operations });
99
+ const scores = new ScoresPG({ client: this.client, operations, schema: this.schema });
100
100
  const traces = new TracesPG({ client: this.client, operations, schema: this.schema });
101
101
  const workflows = new WorkflowsPG({ client: this.client, operations, schema: this.schema });
102
102
  const legacyEvals = new LegacyEvalsPG({ client: this.client, schema: this.schema });
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { spawn } from 'child_process';
2
+ import { promisify } from 'util';
3
+ import { defineConfig } from 'tsup';
4
+
5
+ const exec = promisify(spawn);
6
+
7
+ export default defineConfig({
8
+ entry: ['src/index.ts'],
9
+ format: ['esm', 'cjs'],
10
+ clean: true,
11
+ dts: false,
12
+ splitting: true,
13
+ treeshake: {
14
+ preset: 'smallest',
15
+ },
16
+ sourcemap: true,
17
+ onSuccess: async () => {
18
+ await exec('pnpm', ['tsc', '-p', 'tsconfig.build.json'], {
19
+ stdio: 'inherit',
20
+ });
21
+ },
22
+ });