@mastra/pg 1.27.1-alpha.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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +86 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +86 -57
- package/dist/index.js.map +1 -1
- package/dist/shared/schema-name.d.ts +19 -0
- package/dist/shared/schema-name.d.ts.map +1 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/ddl.d.ts.map +1 -1
- package/dist/storage/domains/thread-state/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
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
|
-
|
|
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 ? `"${(
|
|
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 ? `"${(
|
|
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 ? (
|
|
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 =
|
|
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 ? `'${(
|
|
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 ? (
|
|
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 ? (
|
|
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 ? (
|
|
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 ? `"${(
|
|
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 ? (
|
|
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 ? (
|
|
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 = `"${(
|
|
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 ? `"${(
|
|
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 ? (
|
|
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 ? (
|
|
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 ? (
|
|
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 ? (
|
|
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 ? (
|
|
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 `"${(
|
|
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 `"${(
|
|
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 "${(
|
|
14723
|
+
return `CREATE SCHEMA IF NOT EXISTS "${parseSchemaName(schema)}"`;
|
|
14695
14724
|
}
|
|
14696
14725
|
/**
|
|
14697
14726
|
* Postgres declarative partitioning and Timescale hypertables are mutually
|
|
@@ -19231,7 +19260,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
|
|
|
19231
19260
|
*/
|
|
19232
19261
|
static getExportDDL(schemaName) {
|
|
19233
19262
|
const statements = [];
|
|
19234
|
-
const parsedSchema = schemaName ? (
|
|
19263
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
19235
19264
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19236
19265
|
for (const tableName of PromptBlocksPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
19237
19266
|
tableName,
|
|
@@ -19243,7 +19272,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
|
|
|
19243
19272
|
return statements;
|
|
19244
19273
|
}
|
|
19245
19274
|
getDefaultIndexDefinitions() {
|
|
19246
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19275
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19247
19276
|
return PromptBlocksPG.getDefaultIndexDefs(schemaPrefix);
|
|
19248
19277
|
}
|
|
19249
19278
|
async createDefaultIndexes() {
|
|
@@ -19878,7 +19907,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
|
|
|
19878
19907
|
* so its supporting index is not part of the default index set.
|
|
19879
19908
|
*/
|
|
19880
19909
|
async ensureRetentionIndexes(policies) {
|
|
19881
|
-
const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19910
|
+
const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19882
19911
|
for (const [key, entry] of Object.entries(SchedulesPG.retentionTables)) {
|
|
19883
19912
|
if (!entry.indexed || !policies[key]) continue;
|
|
19884
19913
|
try {
|
|
@@ -19926,7 +19955,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
|
|
|
19926
19955
|
}];
|
|
19927
19956
|
}
|
|
19928
19957
|
getDefaultIndexDefinitions() {
|
|
19929
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19958
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19930
19959
|
return SchedulesPG.getDefaultIndexDefs(schemaPrefix);
|
|
19931
19960
|
}
|
|
19932
19961
|
async createDefaultIndexes() {
|
|
@@ -19947,7 +19976,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
|
|
|
19947
19976
|
}
|
|
19948
19977
|
static getExportDDL(schemaName) {
|
|
19949
19978
|
const statements = [];
|
|
19950
|
-
const parsedSchema = schemaName ? (
|
|
19979
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
19951
19980
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19952
19981
|
statements.push(generateTableSQL({
|
|
19953
19982
|
tableName: _mastra_core_storage.TABLE_SCHEDULES,
|
|
@@ -19969,7 +19998,7 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
|
|
|
19969
19998
|
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_SCHEDULES });
|
|
19970
19999
|
}
|
|
19971
20000
|
#table(tableName) {
|
|
19972
|
-
return getTableName$2(tableName, getSchemaName$2((
|
|
20001
|
+
return getTableName$2(tableName, getSchemaName$2(parseSchemaName(this.#schema)));
|
|
19973
20002
|
}
|
|
19974
20003
|
async createSchedule(schedule) {
|
|
19975
20004
|
if (await this.#getSchedule(this.#client, schedule.id)) throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
@@ -20174,7 +20203,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
|
|
|
20174
20203
|
*/
|
|
20175
20204
|
static getExportDDL(schemaName) {
|
|
20176
20205
|
const statements = [];
|
|
20177
|
-
const parsedSchema = schemaName ? (
|
|
20206
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
20178
20207
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
20179
20208
|
for (const tableName of ScorerDefinitionsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
20180
20209
|
tableName,
|
|
@@ -20186,7 +20215,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
|
|
|
20186
20215
|
return statements;
|
|
20187
20216
|
}
|
|
20188
20217
|
getDefaultIndexDefinitions() {
|
|
20189
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20218
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20190
20219
|
return ScorerDefinitionsPG.getDefaultIndexDefs(schemaPrefix);
|
|
20191
20220
|
}
|
|
20192
20221
|
async createDefaultIndexes() {
|
|
@@ -20819,7 +20848,7 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
|
|
|
20819
20848
|
* so its supporting index is not part of the default index set.
|
|
20820
20849
|
*/
|
|
20821
20850
|
async ensureRetentionIndexes(policies) {
|
|
20822
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20851
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20823
20852
|
for (const [key, entry] of Object.entries(ScoresPG.retentionTables)) {
|
|
20824
20853
|
if (!entry.indexed || !policies[key]) continue;
|
|
20825
20854
|
try {
|
|
@@ -20854,7 +20883,7 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
|
|
|
20854
20883
|
*/
|
|
20855
20884
|
static getExportDDL(schemaName) {
|
|
20856
20885
|
const statements = [];
|
|
20857
|
-
const parsedSchema = schemaName ? (
|
|
20886
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
20858
20887
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
20859
20888
|
statements.push(generateTableSQL({
|
|
20860
20889
|
tableName: _mastra_core_storage.TABLE_SCORERS,
|
|
@@ -20869,7 +20898,7 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
|
|
|
20869
20898
|
* Returns default index definitions for this instance's schema.
|
|
20870
20899
|
*/
|
|
20871
20900
|
getDefaultIndexDefinitions() {
|
|
20872
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20901
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20873
20902
|
return ScoresPG.getDefaultIndexDefs(schemaPrefix);
|
|
20874
20903
|
}
|
|
20875
20904
|
/**
|
|
@@ -21232,7 +21261,7 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
21232
21261
|
}
|
|
21233
21262
|
static getExportDDL(schemaName) {
|
|
21234
21263
|
const statements = [];
|
|
21235
|
-
const parsedSchema = schemaName ? (
|
|
21264
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
21236
21265
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
21237
21266
|
for (const tableName of SkillsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
21238
21267
|
tableName,
|
|
@@ -21244,7 +21273,7 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
21244
21273
|
return statements;
|
|
21245
21274
|
}
|
|
21246
21275
|
getDefaultIndexDefinitions() {
|
|
21247
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
21276
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
21248
21277
|
return SkillsPG.getDefaultIndexDefs(schemaPrefix);
|
|
21249
21278
|
}
|
|
21250
21279
|
async createDefaultIndexes() {
|
|
@@ -21939,7 +21968,7 @@ var ThreadStatePG = class ThreadStatePG extends _mastra_core_storage.ThreadState
|
|
|
21939
21968
|
* a failure here leaves pruning correct, just slower.
|
|
21940
21969
|
*/
|
|
21941
21970
|
async #ensureRetentionIndexes(policies) {
|
|
21942
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
21971
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
21943
21972
|
for (const [key, entry] of Object.entries(ThreadStatePG.retentionTables)) {
|
|
21944
21973
|
if (!entry.indexed || !policies[key]) continue;
|
|
21945
21974
|
try {
|
|
@@ -22105,7 +22134,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends _mastra_
|
|
|
22105
22134
|
}
|
|
22106
22135
|
static getExportDDL(schemaName) {
|
|
22107
22136
|
const statements = [];
|
|
22108
|
-
const parsedSchema = schemaName ? (
|
|
22137
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
22109
22138
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
22110
22139
|
statements.push(generateTableSQL({
|
|
22111
22140
|
tableName: _mastra_core_storage.TABLE_TOOL_PROVIDER_CONNECTIONS,
|
|
@@ -22122,7 +22151,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends _mastra_
|
|
|
22122
22151
|
return statements;
|
|
22123
22152
|
}
|
|
22124
22153
|
getDefaultIndexDefinitions() {
|
|
22125
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22154
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22126
22155
|
return ToolProviderConnectionsPG.getDefaultIndexDefs(schemaPrefix);
|
|
22127
22156
|
}
|
|
22128
22157
|
async createDefaultIndexes() {
|
|
@@ -22354,7 +22383,7 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends _mastra_core_sto
|
|
|
22354
22383
|
}
|
|
22355
22384
|
getDefaultIndexDefinitions() {
|
|
22356
22385
|
return [{
|
|
22357
|
-
name: `${this.#schema !== "public" ? `${this.#schema}_` : ""}idx_workflow_definitions_status`,
|
|
22386
|
+
name: `${this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : ""}idx_workflow_definitions_status`,
|
|
22358
22387
|
table: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
22359
22388
|
columns: ["status"]
|
|
22360
22389
|
}];
|
|
@@ -22631,7 +22660,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
22631
22660
|
*/
|
|
22632
22661
|
static getExportDDL(schemaName) {
|
|
22633
22662
|
const statements = [];
|
|
22634
|
-
const parsedSchema = schemaName ? (
|
|
22663
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
22635
22664
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
22636
22665
|
statements.push(generateTableSQL({
|
|
22637
22666
|
tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
@@ -22648,7 +22677,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
22648
22677
|
* Returns default index definitions for the workflows domain tables.
|
|
22649
22678
|
*/
|
|
22650
22679
|
getDefaultIndexDefinitions() {
|
|
22651
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22680
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22652
22681
|
return WorkflowsPG.getDefaultIndexDefs(schemaPrefix);
|
|
22653
22682
|
}
|
|
22654
22683
|
/**
|
|
@@ -22698,7 +22727,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
22698
22727
|
* so its supporting index is not part of the default index set.
|
|
22699
22728
|
*/
|
|
22700
22729
|
async ensureRetentionIndexes(policies) {
|
|
22701
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22730
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22702
22731
|
for (const [key, entry] of Object.entries(WorkflowsPG.retentionTables)) {
|
|
22703
22732
|
if (!entry.indexed || !policies[key]) continue;
|
|
22704
22733
|
try {
|
|
@@ -23076,7 +23105,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23076
23105
|
}
|
|
23077
23106
|
static getExportDDL(schemaName) {
|
|
23078
23107
|
const statements = [];
|
|
23079
|
-
const parsedSchema = schemaName ? (
|
|
23108
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
23080
23109
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
23081
23110
|
for (const tableName of WorkspacesPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
23082
23111
|
tableName,
|
|
@@ -23088,7 +23117,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23088
23117
|
return statements;
|
|
23089
23118
|
}
|
|
23090
23119
|
getDefaultIndexDefinitions() {
|
|
23091
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
23120
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
23092
23121
|
return WorkspacesPG.getDefaultIndexDefs(schemaPrefix);
|
|
23093
23122
|
}
|
|
23094
23123
|
async createDefaultIndexes() {
|
|
@@ -24216,7 +24245,7 @@ var PostgresStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
24216
24245
|
disableInit: config.disableInit,
|
|
24217
24246
|
retention: config.retention
|
|
24218
24247
|
});
|
|
24219
|
-
this.schema = (
|
|
24248
|
+
this.schema = parseSchemaName(config.schemaName || "public");
|
|
24220
24249
|
if (isPoolConfig(config)) {
|
|
24221
24250
|
this.#writePool = config.pool;
|
|
24222
24251
|
this.#ownsWritePool = false;
|