@mastra/pg 1.27.0 → 1.27.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.
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.27.0"
6
+ version: "1.27.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.27.0",
2
+ "version": "1.27.1",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -54,6 +54,29 @@ const results = await store.hybridQuery({
54
54
 
55
55
  See the [MongoDB vector reference](https://mastra.ai/reference/vectors/mongodb) for details on `createSearchIndex()`, `textQuery()`, and `hybridQuery()`.
56
56
 
57
+ ### Automated Embedding
58
+
59
+ MongoDB can generate the embeddings itself, so you don't need an embedding provider in your application. Create the index with `autoEmbed` and a Voyage AI model, write plain text, and search with a query string:
60
+
61
+ ```ts
62
+ await store.createIndex({
63
+ indexName: 'myCollection',
64
+ autoEmbed: { model: 'voyage-4' },
65
+ })
66
+ await store.upsert({
67
+ indexName: 'myCollection',
68
+ documents: chunks.map(chunk => chunk.text),
69
+ metadata: chunks.map(chunk => ({ text: chunk.text })),
70
+ })
71
+ const results = await store.query({
72
+ indexName: 'myCollection',
73
+ queryText: 'search terms',
74
+ topK: 10,
75
+ })
76
+ ```
77
+
78
+ Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/reference/vectors/mongodb) for the supported options and requirements.
79
+
57
80
  **PgVector**:
58
81
 
59
82
  ```ts
package/dist/index.cjs CHANGED
@@ -118,6 +118,34 @@ function buildConnectionStringPoolConfig(config, defaults) {
118
118
  };
119
119
  }
120
120
  //#endregion
121
+ //#region src/shared/schema-name.ts
122
+ const POSTGRES_IDENTIFIER_MAX_BYTES = 63;
123
+ const UNSAFE_SCHEMA_NAME_CHARS = /["'\\$\u0000-\u001f\u007f]/;
124
+ /**
125
+ * Validates a PostgreSQL schema name.
126
+ *
127
+ * Schema names are always double-quoted in generated SQL, so PostgreSQL accepts any name
128
+ * that fits the identifier limit (for example `my-tenant`). Quotes, backslashes, `$` and
129
+ * control characters are rejected so the name can never break out of a quoted identifier,
130
+ * a string literal, or a dollar-quoted block.
131
+ */
132
+ function parseSchemaName(name, kind = "schema name") {
133
+ if (typeof name !== "string" || name.length === 0 || UNSAFE_SCHEMA_NAME_CHARS.test(name) || Buffer.byteLength(name, "utf-8") > POSTGRES_IDENTIFIER_MAX_BYTES) throw new Error(`Invalid ${kind}: ${name}. Must be 1-${POSTGRES_IDENTIFIER_MAX_BYTES} bytes long and must not contain quotes, backslashes, "$", or control characters.`);
134
+ return name;
135
+ }
136
+ /**
137
+ * Turns a schema name into a string that is safe to use as part of an unquoted identifier,
138
+ * such as the schema prefix of an index or constraint name.
139
+ *
140
+ * Names that are already plain identifiers (letters, digits, underscores) are returned
141
+ * unchanged, so existing index and constraint names keep working. Any other character
142
+ * becomes `_`, e.g. `my-tenant` -> `my_tenant`.
143
+ */
144
+ function schemaNamePrefix(name) {
145
+ const sanitized = parseSchemaName(name).replace(/[^A-Za-z0-9_]/g, "_");
146
+ return /^[0-9]/.test(sanitized) ? `_${sanitized}` : sanitized;
147
+ }
148
+ //#endregion
121
149
  //#region src/vector/filter.ts
122
150
  /**
123
151
  * Translates MongoDB-style filters to PG compatible filters.
@@ -742,7 +770,8 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
742
770
  if (vectorType === "bit") return dimension ? `bit(${dimension})` : "bit";
743
771
  if (this.vectorExtensionSchema) {
744
772
  if (this.vectorExtensionSchema === "pg_catalog") return vectorType;
745
- return `${(0, _mastra_core_utils.parseSqlIdentifier)(this.vectorExtensionSchema, "vector extension schema")}.${vectorType}`;
773
+ const extensionSchema = parseSchemaName(this.vectorExtensionSchema, "vector extension schema");
774
+ return `${/^[A-Za-z_][A-Za-z0-9_]*$/.test(extensionSchema) ? extensionSchema : `"${extensionSchema}"`}.${vectorType}`;
746
775
  }
747
776
  return vectorType;
748
777
  }
@@ -820,7 +849,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
820
849
  };
821
850
  }
822
851
  getSchemaName() {
823
- return this.schema ? `"${(0, _mastra_core_utils.parseSqlIdentifier)(this.schema, "schema name")}"` : void 0;
852
+ return this.schema ? `"${parseSchemaName(this.schema)}"` : void 0;
824
853
  }
825
854
  async ensureNamespaceSchema(indexName, client) {
826
855
  const { tableName, parsedIndexName } = this.getTableName(indexName);
@@ -2575,7 +2604,7 @@ function resolvePgConfig(config) {
2575
2604
  };
2576
2605
  }
2577
2606
  function getSchemaName$6(schema) {
2578
- return schema ? `"${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}"` : "\"public\"";
2607
+ return schema ? `"${parseSchemaName(schema)}"` : "\"public\"";
2579
2608
  }
2580
2609
  function getTableName$6({ indexName, schemaName }) {
2581
2610
  const quotedIndexName = `"${(0, _mastra_core_utils.parseSqlIdentifier)(indexName, "index name")}"`;
@@ -2614,7 +2643,7 @@ function generateTableSQL({ tableName, schema, schemaName, compositePrimaryKey,
2614
2643
  ...timeZColumns,
2615
2644
  ...tableConstraints
2616
2645
  ].join(",\n");
2617
- const parsedSchemaName = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
2646
+ const parsedSchemaName = schemaName ? schemaNamePrefix(schemaName) : "";
2618
2647
  const workflowSnapshotConstraint = buildConstraintName({
2619
2648
  baseName: "mastra_workflow_snapshot_workflow_name_run_id_key",
2620
2649
  schemaName: parsedSchemaName || void 0
@@ -2624,7 +2653,7 @@ function generateTableSQL({ tableName, schema, schemaName, compositePrimaryKey,
2624
2653
  schemaName: parsedSchemaName || void 0
2625
2654
  });
2626
2655
  const quotedSchemaName = getSchemaName$6(schemaName);
2627
- const schemaFilter = parsedSchemaName || "public";
2656
+ const schemaFilter = schemaName ? parseSchemaName(schemaName) : "public";
2628
2657
  return `
2629
2658
  CREATE TABLE IF NOT EXISTS ${getTableName$6({
2630
2659
  indexName: tableName,
@@ -2750,7 +2779,7 @@ BEGIN
2750
2779
  JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
2751
2780
  WHERE tg.tgname = ${`'${parsedTriggerName}'`}
2752
2781
  AND c.relname = ${`'${(0, _mastra_core_utils.parseSqlIdentifier)(tableName, "table name")}'`}
2753
- AND n.nspname = ${schemaName ? `'${(0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name")}'` : `'public'`}
2782
+ AND n.nspname = ${schemaName ? `'${parseSchemaName(schemaName)}'` : `'public'`}
2754
2783
  AND NOT tg.tgisinternal
2755
2784
  AND tg.tgtype = 23
2756
2785
  AND tg.tgfoid = '${functionName}()'::regprocedure
@@ -2819,7 +2848,7 @@ var PgDB = class extends _mastra_core_base.MastraBase {
2819
2848
  if (tableName === _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT) {
2820
2849
  const constraintName = buildConstraintName({
2821
2850
  baseName: "mastra_workflow_snapshot_workflow_name_run_id_key",
2822
- schemaName: this.schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(this.schemaName, "schema name") : void 0
2851
+ schemaName: this.schemaName ? schemaNamePrefix(this.schemaName) : void 0
2823
2852
  }).toLowerCase();
2824
2853
  return snapshot.indexes.has(constraintName) && snapshot.replicaIdentityIndexes.has(constraintName);
2825
2854
  }
@@ -3424,7 +3453,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
3424
3453
  async spansPrimaryKeyExists() {
3425
3454
  const constraintName = buildConstraintName({
3426
3455
  baseName: "mastra_ai_spans_traceid_spanid_pk",
3427
- schemaName: (this.schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(this.schemaName, "schema name") : "") || void 0
3456
+ schemaName: (this.schemaName ? schemaNamePrefix(this.schemaName) : "") || void 0
3428
3457
  });
3429
3458
  const schemaFilter = this.schemaName || "public";
3430
3459
  const snapshot = this.schemaSnapshot;
@@ -3446,7 +3475,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
3446
3475
  });
3447
3476
  const constraintName = buildConstraintName({
3448
3477
  baseName: "mastra_ai_spans_traceid_spanid_pk",
3449
- schemaName: (this.schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(this.schemaName, "schema name") : "") || void 0
3478
+ schemaName: (this.schemaName ? schemaNamePrefix(this.schemaName) : "") || void 0
3450
3479
  });
3451
3480
  const schemaFilter = this.schemaName || "public";
3452
3481
  try {
@@ -4039,7 +4068,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
4039
4068
  //#endregion
4040
4069
  //#region src/storage/domains/utils.ts
4041
4070
  function getSchemaName$5(schema) {
4042
- return schema ? `"${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}"` : void 0;
4071
+ return schema ? `"${parseSchemaName(schema)}"` : void 0;
4043
4072
  }
4044
4073
  function getTableName$5({ indexName, schemaName }) {
4045
4074
  const quotedIndexName = `"${(0, _mastra_core_utils.parseSqlIdentifier)(indexName, "index name")}"`;
@@ -5093,7 +5122,7 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5093
5122
  * so its supporting index is not part of the default index set.
5094
5123
  */
5095
5124
  async ensureRetentionIndexes(policies) {
5096
- const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
5125
+ const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
5097
5126
  for (const [key, entry] of Object.entries(BackgroundTasksPG.retentionTables)) {
5098
5127
  if (!entry.indexed || !policies[key]) continue;
5099
5128
  try {
@@ -5148,7 +5177,7 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5148
5177
  }
5149
5178
  static getExportDDL(schemaName) {
5150
5179
  const statements = [];
5151
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
5180
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
5152
5181
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
5153
5182
  statements.push(generateTableSQL({
5154
5183
  tableName: _mastra_core_storage.TABLE_BACKGROUND_TASKS,
@@ -5160,7 +5189,7 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5160
5189
  return statements;
5161
5190
  }
5162
5191
  getDefaultIndexDefinitions() {
5163
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
5192
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
5164
5193
  return BackgroundTasksPG.getDefaultIndexDefs(schemaPrefix);
5165
5194
  }
5166
5195
  async createDefaultIndexes() {
@@ -5522,7 +5551,7 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
5522
5551
  }
5523
5552
  static getExportDDL(schemaName) {
5524
5553
  const statements = [];
5525
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
5554
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
5526
5555
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
5527
5556
  for (const tableName of ChannelsPG.MANAGED_TABLES) statements.push(generateTableSQL({
5528
5557
  tableName,
@@ -5534,7 +5563,7 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
5534
5563
  return statements;
5535
5564
  }
5536
5565
  getDefaultIndexDefinitions() {
5537
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
5566
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
5538
5567
  return ChannelsPG.getDefaultIndexDefs(schemaPrefix);
5539
5568
  }
5540
5569
  async createDefaultIndexes() {
@@ -7046,7 +7075,7 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
7046
7075
  * so its supporting index is not part of the default index set.
7047
7076
  */
7048
7077
  async ensureRetentionIndexes(policies) {
7049
- const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
7078
+ const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
7050
7079
  for (const [key, entry] of Object.entries(ExperimentsPG.retentionTables)) {
7051
7080
  if (!entry.indexed || !policies[key]) continue;
7052
7081
  try {
@@ -8214,7 +8243,7 @@ function postgresSql(sql, schemaName) {
8214
8243
  return transformed;
8215
8244
  });
8216
8245
  if (schemaName) {
8217
- const quotedSchema = `"${(0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name")}"`;
8246
+ const quotedSchema = `"${parseSchemaName(schemaName)}"`;
8218
8247
  normalized = transformSqlCode(normalized, (code) => {
8219
8248
  let transformed = code;
8220
8249
  for (const table of [
@@ -8327,7 +8356,7 @@ function parseOutbox(row) {
8327
8356
  function knowledgeIndexes(schemaName) {
8328
8357
  const table = (name) => {
8329
8358
  const quotedName = `"${(0, _mastra_core_utils.parseSqlIdentifier)(name, "table name")}"`;
8330
- return schemaName ? `"${(0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name")}".${quotedName}` : quotedName;
8359
+ return schemaName ? `"${parseSchemaName(schemaName)}".${quotedName}` : quotedName;
8331
8360
  };
8332
8361
  return [
8333
8362
  {
@@ -9231,7 +9260,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
9231
9260
  }
9232
9261
  static getExportDDL(schemaName) {
9233
9262
  const statements = [];
9234
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
9263
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
9235
9264
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
9236
9265
  for (const tableName of MCPClientsPG.MANAGED_TABLES) statements.push(generateTableSQL({
9237
9266
  tableName,
@@ -9243,7 +9272,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
9243
9272
  return statements;
9244
9273
  }
9245
9274
  getDefaultIndexDefinitions() {
9246
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
9275
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
9247
9276
  return MCPClientsPG.getDefaultIndexDefs(schemaPrefix);
9248
9277
  }
9249
9278
  async createDefaultIndexes() {
@@ -9799,7 +9828,7 @@ var MCPServersPG = class MCPServersPG extends _mastra_core_storage.MCPServersSto
9799
9828
  }
9800
9829
  static getExportDDL(schemaName) {
9801
9830
  const statements = [];
9802
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
9831
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
9803
9832
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
9804
9833
  for (const tableName of MCPServersPG.MANAGED_TABLES) statements.push(generateTableSQL({
9805
9834
  tableName,
@@ -9811,7 +9840,7 @@ var MCPServersPG = class MCPServersPG extends _mastra_core_storage.MCPServersSto
9811
9840
  return statements;
9812
9841
  }
9813
9842
  getDefaultIndexDefinitions() {
9814
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
9843
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
9815
9844
  return MCPServersPG.getDefaultIndexDefs(schemaPrefix);
9816
9845
  }
9817
9846
  async createDefaultIndexes() {
@@ -10521,7 +10550,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
10521
10550
  * so its supporting index is not part of the default index set.
10522
10551
  */
10523
10552
  async ensureRetentionIndexes(policies) {
10524
- const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
10553
+ const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
10525
10554
  for (const [key, entry] of Object.entries(MemoryPG.retentionTables)) {
10526
10555
  if (!entry.indexed || !policies[key]) continue;
10527
10556
  try {
@@ -10556,7 +10585,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
10556
10585
  */
10557
10586
  static getExportDDL(schemaName) {
10558
10587
  const statements = [];
10559
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
10588
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
10560
10589
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
10561
10590
  const quotedSchemaName = getSchemaName$6(schemaName);
10562
10591
  for (const tableName of [
@@ -10591,7 +10620,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
10591
10620
  * Returns default index definitions for this instance's schema.
10592
10621
  */
10593
10622
  getDefaultIndexDefinitions() {
10594
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
10623
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
10595
10624
  return MemoryPG.getDefaultIndexDefs(schemaPrefix);
10596
10625
  }
10597
10626
  /**
@@ -12999,7 +13028,7 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
12999
13028
  * so its supporting index is not part of the default index set.
13000
13029
  */
13001
13030
  async ensureRetentionIndexes(policies) {
13002
- const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
13031
+ const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
13003
13032
  for (const [key, entry] of Object.entries(NotificationsPG.retentionTables)) {
13004
13033
  if (!entry.indexed || !policies[key]) continue;
13005
13034
  try {
@@ -13066,7 +13095,7 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
13066
13095
  }
13067
13096
  static getExportDDL(schemaName) {
13068
13097
  const statements = [];
13069
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
13098
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
13070
13099
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
13071
13100
  statements.push(generateTableSQL({
13072
13101
  tableName: _mastra_core_storage.TABLE_NOTIFICATIONS,
@@ -13078,7 +13107,7 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
13078
13107
  return statements;
13079
13108
  }
13080
13109
  getDefaultIndexDefinitions() {
13081
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
13110
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
13082
13111
  return NotificationsPG.getDefaultIndexDefs(schemaPrefix);
13083
13112
  }
13084
13113
  async createDefaultIndexes() {
@@ -13375,7 +13404,7 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
13375
13404
  * so its supporting index is not part of the default index set.
13376
13405
  */
13377
13406
  async ensureRetentionIndexes(policies) {
13378
- const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
13407
+ const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
13379
13408
  for (const [key, entry] of Object.entries(ObservabilityPG.retentionTables)) {
13380
13409
  if (!entry.indexed || !policies[key]) continue;
13381
13410
  try {
@@ -13456,7 +13485,7 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
13456
13485
  */
13457
13486
  static getExportDDL(schemaName) {
13458
13487
  const statements = [];
13459
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
13488
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
13460
13489
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
13461
13490
  statements.push(generateTableSQL({
13462
13491
  tableName: _mastra_core_storage.TABLE_SPANS,
@@ -13472,7 +13501,7 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
13472
13501
  * Returns default index definitions for this instance's schema.
13473
13502
  */
13474
13503
  getDefaultIndexDefinitions() {
13475
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
13504
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
13476
13505
  return ObservabilityPG.getDefaultIndexDefs(schemaPrefix);
13477
13506
  }
13478
13507
  /**
@@ -14683,15 +14712,15 @@ const SIGNAL_TIME_COLUMN = {
14683
14712
  };
14684
14713
  /** Returns a fully-qualified, double-quoted table name. */
14685
14714
  function qualifiedTable(schema, table) {
14686
- return `"${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}"."${(0, _mastra_core_utils.parseSqlIdentifier)(table, "table name")}"`;
14715
+ return `"${parseSchemaName(schema)}"."${(0, _mastra_core_utils.parseSqlIdentifier)(table, "table name")}"`;
14687
14716
  }
14688
14717
  /** Returns a parsed, quoted, schema-prefixed object name (constraint, index, etc.). */
14689
14718
  function qualifiedName(schema, name) {
14690
- return `"${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}"."${(0, _mastra_core_utils.parseSqlIdentifier)(name, "object name")}"`;
14719
+ return `"${parseSchemaName(schema)}"."${(0, _mastra_core_utils.parseSqlIdentifier)(name, "object name")}"`;
14691
14720
  }
14692
14721
  /** Schema CREATE. Safe to run repeatedly before table DDL. */
14693
14722
  function schemaDDL(schema) {
14694
- return `CREATE SCHEMA IF NOT EXISTS "${(0, _mastra_core_utils.parseSqlIdentifier)(schema, "schema name")}"`;
14723
+ return `CREATE SCHEMA IF NOT EXISTS "${parseSchemaName(schema)}"`;
14695
14724
  }
14696
14725
  /**
14697
14726
  * Postgres declarative partitioning and Timescale hypertables are mutually
@@ -18981,21 +19010,35 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
18981
19010
  if (!deltaPollingFeatureEnabled()) return [
18982
19011
  "metrics",
18983
19012
  "logs",
19013
+ "entity-type-discovery",
19014
+ "entity-name-discovery",
19015
+ "service-name-discovery",
19016
+ "environment-discovery",
19017
+ "tag-discovery",
19018
+ "metric-discovery",
18984
19019
  "trace-query",
18985
19020
  "trace-query-root-duration",
18986
19021
  "trace-query-discovery",
18987
19022
  "thread-query",
18988
- "trace-query-tenant-scope"
19023
+ "trace-query-tenant-scope",
19024
+ "feedback"
18989
19025
  ];
18990
19026
  return [
18991
19027
  "metrics",
18992
19028
  "logs",
19029
+ "entity-type-discovery",
19030
+ "entity-name-discovery",
19031
+ "service-name-discovery",
19032
+ "environment-discovery",
19033
+ "tag-discovery",
19034
+ "metric-discovery",
18993
19035
  "delta-polling",
18994
19036
  "trace-query",
18995
19037
  "trace-query-root-duration",
18996
19038
  "trace-query-discovery",
18997
19039
  "thread-query",
18998
- "trace-query-tenant-scope"
19040
+ "trace-query-tenant-scope",
19041
+ "feedback"
18999
19042
  ];
19000
19043
  }
19001
19044
  async #run(op, fn, details) {
@@ -19217,7 +19260,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
19217
19260
  */
19218
19261
  static getExportDDL(schemaName) {
19219
19262
  const statements = [];
19220
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
19263
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
19221
19264
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
19222
19265
  for (const tableName of PromptBlocksPG.MANAGED_TABLES) statements.push(generateTableSQL({
19223
19266
  tableName,
@@ -19229,7 +19272,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
19229
19272
  return statements;
19230
19273
  }
19231
19274
  getDefaultIndexDefinitions() {
19232
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
19275
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
19233
19276
  return PromptBlocksPG.getDefaultIndexDefs(schemaPrefix);
19234
19277
  }
19235
19278
  async createDefaultIndexes() {
@@ -19864,7 +19907,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
19864
19907
  * so its supporting index is not part of the default index set.
19865
19908
  */
19866
19909
  async ensureRetentionIndexes(policies) {
19867
- const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
19910
+ const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
19868
19911
  for (const [key, entry] of Object.entries(SchedulesPG.retentionTables)) {
19869
19912
  if (!entry.indexed || !policies[key]) continue;
19870
19913
  try {
@@ -19912,7 +19955,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
19912
19955
  }];
19913
19956
  }
19914
19957
  getDefaultIndexDefinitions() {
19915
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
19958
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
19916
19959
  return SchedulesPG.getDefaultIndexDefs(schemaPrefix);
19917
19960
  }
19918
19961
  async createDefaultIndexes() {
@@ -19933,7 +19976,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
19933
19976
  }
19934
19977
  static getExportDDL(schemaName) {
19935
19978
  const statements = [];
19936
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
19979
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
19937
19980
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
19938
19981
  statements.push(generateTableSQL({
19939
19982
  tableName: _mastra_core_storage.TABLE_SCHEDULES,
@@ -19955,7 +19998,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
19955
19998
  await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_SCHEDULES });
19956
19999
  }
19957
20000
  #table(tableName) {
19958
- return getTableName$2(tableName, getSchemaName$2((0, _mastra_core_utils.parseSqlIdentifier)(this.#schema, "schema name")));
20001
+ return getTableName$2(tableName, getSchemaName$2(parseSchemaName(this.#schema)));
19959
20002
  }
19960
20003
  async createSchedule(schedule) {
19961
20004
  if (await this.#getSchedule(this.#client, schedule.id)) throw new Error(`Schedule with id "${schedule.id}" already exists`);
@@ -20160,7 +20203,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
20160
20203
  */
20161
20204
  static getExportDDL(schemaName) {
20162
20205
  const statements = [];
20163
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
20206
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
20164
20207
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
20165
20208
  for (const tableName of ScorerDefinitionsPG.MANAGED_TABLES) statements.push(generateTableSQL({
20166
20209
  tableName,
@@ -20172,7 +20215,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
20172
20215
  return statements;
20173
20216
  }
20174
20217
  getDefaultIndexDefinitions() {
20175
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
20218
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
20176
20219
  return ScorerDefinitionsPG.getDefaultIndexDefs(schemaPrefix);
20177
20220
  }
20178
20221
  async createDefaultIndexes() {
@@ -20805,7 +20848,7 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
20805
20848
  * so its supporting index is not part of the default index set.
20806
20849
  */
20807
20850
  async ensureRetentionIndexes(policies) {
20808
- const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
20851
+ const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
20809
20852
  for (const [key, entry] of Object.entries(ScoresPG.retentionTables)) {
20810
20853
  if (!entry.indexed || !policies[key]) continue;
20811
20854
  try {
@@ -20840,7 +20883,7 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
20840
20883
  */
20841
20884
  static getExportDDL(schemaName) {
20842
20885
  const statements = [];
20843
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
20886
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
20844
20887
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
20845
20888
  statements.push(generateTableSQL({
20846
20889
  tableName: _mastra_core_storage.TABLE_SCORERS,
@@ -20855,7 +20898,7 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
20855
20898
  * Returns default index definitions for this instance's schema.
20856
20899
  */
20857
20900
  getDefaultIndexDefinitions() {
20858
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
20901
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
20859
20902
  return ScoresPG.getDefaultIndexDefs(schemaPrefix);
20860
20903
  }
20861
20904
  /**
@@ -21218,7 +21261,7 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
21218
21261
  }
21219
21262
  static getExportDDL(schemaName) {
21220
21263
  const statements = [];
21221
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
21264
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
21222
21265
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
21223
21266
  for (const tableName of SkillsPG.MANAGED_TABLES) statements.push(generateTableSQL({
21224
21267
  tableName,
@@ -21230,7 +21273,7 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
21230
21273
  return statements;
21231
21274
  }
21232
21275
  getDefaultIndexDefinitions() {
21233
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
21276
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
21234
21277
  return SkillsPG.getDefaultIndexDefs(schemaPrefix);
21235
21278
  }
21236
21279
  async createDefaultIndexes() {
@@ -21925,7 +21968,7 @@ var ThreadStatePG = class ThreadStatePG extends _mastra_core_storage.ThreadState
21925
21968
  * a failure here leaves pruning correct, just slower.
21926
21969
  */
21927
21970
  async #ensureRetentionIndexes(policies) {
21928
- const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
21971
+ const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
21929
21972
  for (const [key, entry] of Object.entries(ThreadStatePG.retentionTables)) {
21930
21973
  if (!entry.indexed || !policies[key]) continue;
21931
21974
  try {
@@ -22091,7 +22134,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends _mastra_
22091
22134
  }
22092
22135
  static getExportDDL(schemaName) {
22093
22136
  const statements = [];
22094
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
22137
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
22095
22138
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
22096
22139
  statements.push(generateTableSQL({
22097
22140
  tableName: _mastra_core_storage.TABLE_TOOL_PROVIDER_CONNECTIONS,
@@ -22108,7 +22151,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends _mastra_
22108
22151
  return statements;
22109
22152
  }
22110
22153
  getDefaultIndexDefinitions() {
22111
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
22154
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
22112
22155
  return ToolProviderConnectionsPG.getDefaultIndexDefs(schemaPrefix);
22113
22156
  }
22114
22157
  async createDefaultIndexes() {
@@ -22340,7 +22383,7 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends _mastra_core_sto
22340
22383
  }
22341
22384
  getDefaultIndexDefinitions() {
22342
22385
  return [{
22343
- name: `${this.#schema !== "public" ? `${this.#schema}_` : ""}idx_workflow_definitions_status`,
22386
+ name: `${this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : ""}idx_workflow_definitions_status`,
22344
22387
  table: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
22345
22388
  columns: ["status"]
22346
22389
  }];
@@ -22617,7 +22660,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
22617
22660
  */
22618
22661
  static getExportDDL(schemaName) {
22619
22662
  const statements = [];
22620
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
22663
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
22621
22664
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
22622
22665
  statements.push(generateTableSQL({
22623
22666
  tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
@@ -22634,7 +22677,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
22634
22677
  * Returns default index definitions for the workflows domain tables.
22635
22678
  */
22636
22679
  getDefaultIndexDefinitions() {
22637
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
22680
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
22638
22681
  return WorkflowsPG.getDefaultIndexDefs(schemaPrefix);
22639
22682
  }
22640
22683
  /**
@@ -22684,7 +22727,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
22684
22727
  * so its supporting index is not part of the default index set.
22685
22728
  */
22686
22729
  async ensureRetentionIndexes(policies) {
22687
- const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
22730
+ const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
22688
22731
  for (const [key, entry] of Object.entries(WorkflowsPG.retentionTables)) {
22689
22732
  if (!entry.indexed || !policies[key]) continue;
22690
22733
  try {
@@ -23062,7 +23105,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
23062
23105
  }
23063
23106
  static getExportDDL(schemaName) {
23064
23107
  const statements = [];
23065
- const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
23108
+ const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
23066
23109
  const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
23067
23110
  for (const tableName of WorkspacesPG.MANAGED_TABLES) statements.push(generateTableSQL({
23068
23111
  tableName,
@@ -23074,7 +23117,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
23074
23117
  return statements;
23075
23118
  }
23076
23119
  getDefaultIndexDefinitions() {
23077
- const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
23120
+ const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
23078
23121
  return WorkspacesPG.getDefaultIndexDefs(schemaPrefix);
23079
23122
  }
23080
23123
  async createDefaultIndexes() {
@@ -24202,7 +24245,7 @@ var PostgresStore = class extends _mastra_core_storage.MastraCompositeStore {
24202
24245
  disableInit: config.disableInit,
24203
24246
  retention: config.retention
24204
24247
  });
24205
- this.schema = (0, _mastra_core_utils.parseSqlIdentifier)(config.schemaName || "public", "schema name");
24248
+ this.schema = parseSchemaName(config.schemaName || "public");
24206
24249
  if (isPoolConfig(config)) {
24207
24250
  this.#writePool = config.pool;
24208
24251
  this.#ownsWritePool = false;