@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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-rag-vector-databases.md +23 -0
- package/dist/index.cjs +102 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +102 -59
- 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/observability/v-next/index.d.ts +1 -1
- package/dist/storage/domains/observability/v-next/index.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/index.js
CHANGED
|
@@ -94,6 +94,34 @@ function buildConnectionStringPoolConfig(config, defaults) {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
|
+
//#region src/shared/schema-name.ts
|
|
98
|
+
const POSTGRES_IDENTIFIER_MAX_BYTES = 63;
|
|
99
|
+
const UNSAFE_SCHEMA_NAME_CHARS = /["'\\$\u0000-\u001f\u007f]/;
|
|
100
|
+
/**
|
|
101
|
+
* Validates a PostgreSQL schema name.
|
|
102
|
+
*
|
|
103
|
+
* Schema names are always double-quoted in generated SQL, so PostgreSQL accepts any name
|
|
104
|
+
* that fits the identifier limit (for example `my-tenant`). Quotes, backslashes, `$` and
|
|
105
|
+
* control characters are rejected so the name can never break out of a quoted identifier,
|
|
106
|
+
* a string literal, or a dollar-quoted block.
|
|
107
|
+
*/
|
|
108
|
+
function parseSchemaName(name, kind = "schema name") {
|
|
109
|
+
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.`);
|
|
110
|
+
return name;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Turns a schema name into a string that is safe to use as part of an unquoted identifier,
|
|
114
|
+
* such as the schema prefix of an index or constraint name.
|
|
115
|
+
*
|
|
116
|
+
* Names that are already plain identifiers (letters, digits, underscores) are returned
|
|
117
|
+
* unchanged, so existing index and constraint names keep working. Any other character
|
|
118
|
+
* becomes `_`, e.g. `my-tenant` -> `my_tenant`.
|
|
119
|
+
*/
|
|
120
|
+
function schemaNamePrefix(name) {
|
|
121
|
+
const sanitized = parseSchemaName(name).replace(/[^A-Za-z0-9_]/g, "_");
|
|
122
|
+
return /^[0-9]/.test(sanitized) ? `_${sanitized}` : sanitized;
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
97
125
|
//#region src/vector/filter.ts
|
|
98
126
|
/**
|
|
99
127
|
* Translates MongoDB-style filters to PG compatible filters.
|
|
@@ -718,7 +746,8 @@ var PgVector = class extends MastraVector {
|
|
|
718
746
|
if (vectorType === "bit") return dimension ? `bit(${dimension})` : "bit";
|
|
719
747
|
if (this.vectorExtensionSchema) {
|
|
720
748
|
if (this.vectorExtensionSchema === "pg_catalog") return vectorType;
|
|
721
|
-
|
|
749
|
+
const extensionSchema = parseSchemaName(this.vectorExtensionSchema, "vector extension schema");
|
|
750
|
+
return `${/^[A-Za-z_][A-Za-z0-9_]*$/.test(extensionSchema) ? extensionSchema : `"${extensionSchema}"`}.${vectorType}`;
|
|
722
751
|
}
|
|
723
752
|
return vectorType;
|
|
724
753
|
}
|
|
@@ -796,7 +825,7 @@ var PgVector = class extends MastraVector {
|
|
|
796
825
|
};
|
|
797
826
|
}
|
|
798
827
|
getSchemaName() {
|
|
799
|
-
return this.schema ? `"${
|
|
828
|
+
return this.schema ? `"${parseSchemaName(this.schema)}"` : void 0;
|
|
800
829
|
}
|
|
801
830
|
async ensureNamespaceSchema(indexName, client) {
|
|
802
831
|
const { tableName, parsedIndexName } = this.getTableName(indexName);
|
|
@@ -2551,7 +2580,7 @@ function resolvePgConfig(config) {
|
|
|
2551
2580
|
};
|
|
2552
2581
|
}
|
|
2553
2582
|
function getSchemaName$6(schema) {
|
|
2554
|
-
return schema ? `"${
|
|
2583
|
+
return schema ? `"${parseSchemaName(schema)}"` : "\"public\"";
|
|
2555
2584
|
}
|
|
2556
2585
|
function getTableName$6({ indexName, schemaName }) {
|
|
2557
2586
|
const quotedIndexName = `"${parseSqlIdentifier(indexName, "index name")}"`;
|
|
@@ -2590,7 +2619,7 @@ function generateTableSQL({ tableName, schema, schemaName, compositePrimaryKey,
|
|
|
2590
2619
|
...timeZColumns,
|
|
2591
2620
|
...tableConstraints
|
|
2592
2621
|
].join(",\n");
|
|
2593
|
-
const parsedSchemaName = schemaName ?
|
|
2622
|
+
const parsedSchemaName = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
2594
2623
|
const workflowSnapshotConstraint = buildConstraintName({
|
|
2595
2624
|
baseName: "mastra_workflow_snapshot_workflow_name_run_id_key",
|
|
2596
2625
|
schemaName: parsedSchemaName || void 0
|
|
@@ -2600,7 +2629,7 @@ function generateTableSQL({ tableName, schema, schemaName, compositePrimaryKey,
|
|
|
2600
2629
|
schemaName: parsedSchemaName || void 0
|
|
2601
2630
|
});
|
|
2602
2631
|
const quotedSchemaName = getSchemaName$6(schemaName);
|
|
2603
|
-
const schemaFilter =
|
|
2632
|
+
const schemaFilter = schemaName ? parseSchemaName(schemaName) : "public";
|
|
2604
2633
|
return `
|
|
2605
2634
|
CREATE TABLE IF NOT EXISTS ${getTableName$6({
|
|
2606
2635
|
indexName: tableName,
|
|
@@ -2726,7 +2755,7 @@ BEGIN
|
|
|
2726
2755
|
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
2727
2756
|
WHERE tg.tgname = ${`'${parsedTriggerName}'`}
|
|
2728
2757
|
AND c.relname = ${`'${parseSqlIdentifier(tableName, "table name")}'`}
|
|
2729
|
-
AND n.nspname = ${schemaName ? `'${
|
|
2758
|
+
AND n.nspname = ${schemaName ? `'${parseSchemaName(schemaName)}'` : `'public'`}
|
|
2730
2759
|
AND NOT tg.tgisinternal
|
|
2731
2760
|
AND tg.tgtype = 23
|
|
2732
2761
|
AND tg.tgfoid = '${functionName}()'::regprocedure
|
|
@@ -2795,7 +2824,7 @@ var PgDB = class extends MastraBase {
|
|
|
2795
2824
|
if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
|
|
2796
2825
|
const constraintName = buildConstraintName({
|
|
2797
2826
|
baseName: "mastra_workflow_snapshot_workflow_name_run_id_key",
|
|
2798
|
-
schemaName: this.schemaName ?
|
|
2827
|
+
schemaName: this.schemaName ? schemaNamePrefix(this.schemaName) : void 0
|
|
2799
2828
|
}).toLowerCase();
|
|
2800
2829
|
return snapshot.indexes.has(constraintName) && snapshot.replicaIdentityIndexes.has(constraintName);
|
|
2801
2830
|
}
|
|
@@ -3400,7 +3429,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
3400
3429
|
async spansPrimaryKeyExists() {
|
|
3401
3430
|
const constraintName = buildConstraintName({
|
|
3402
3431
|
baseName: "mastra_ai_spans_traceid_spanid_pk",
|
|
3403
|
-
schemaName: (this.schemaName ?
|
|
3432
|
+
schemaName: (this.schemaName ? schemaNamePrefix(this.schemaName) : "") || void 0
|
|
3404
3433
|
});
|
|
3405
3434
|
const schemaFilter = this.schemaName || "public";
|
|
3406
3435
|
const snapshot = this.schemaSnapshot;
|
|
@@ -3422,7 +3451,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
3422
3451
|
});
|
|
3423
3452
|
const constraintName = buildConstraintName({
|
|
3424
3453
|
baseName: "mastra_ai_spans_traceid_spanid_pk",
|
|
3425
|
-
schemaName: (this.schemaName ?
|
|
3454
|
+
schemaName: (this.schemaName ? schemaNamePrefix(this.schemaName) : "") || void 0
|
|
3426
3455
|
});
|
|
3427
3456
|
const schemaFilter = this.schemaName || "public";
|
|
3428
3457
|
try {
|
|
@@ -4015,7 +4044,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
4015
4044
|
//#endregion
|
|
4016
4045
|
//#region src/storage/domains/utils.ts
|
|
4017
4046
|
function getSchemaName$5(schema) {
|
|
4018
|
-
return schema ? `"${
|
|
4047
|
+
return schema ? `"${parseSchemaName(schema)}"` : void 0;
|
|
4019
4048
|
}
|
|
4020
4049
|
function getTableName$5({ indexName, schemaName }) {
|
|
4021
4050
|
const quotedIndexName = `"${parseSqlIdentifier(indexName, "index name")}"`;
|
|
@@ -5069,7 +5098,7 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5069
5098
|
* so its supporting index is not part of the default index set.
|
|
5070
5099
|
*/
|
|
5071
5100
|
async ensureRetentionIndexes(policies) {
|
|
5072
|
-
const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
5101
|
+
const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
5073
5102
|
for (const [key, entry] of Object.entries(BackgroundTasksPG.retentionTables)) {
|
|
5074
5103
|
if (!entry.indexed || !policies[key]) continue;
|
|
5075
5104
|
try {
|
|
@@ -5124,7 +5153,7 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5124
5153
|
}
|
|
5125
5154
|
static getExportDDL(schemaName) {
|
|
5126
5155
|
const statements = [];
|
|
5127
|
-
const parsedSchema = schemaName ?
|
|
5156
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
5128
5157
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
5129
5158
|
statements.push(generateTableSQL({
|
|
5130
5159
|
tableName: TABLE_BACKGROUND_TASKS,
|
|
@@ -5136,7 +5165,7 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5136
5165
|
return statements;
|
|
5137
5166
|
}
|
|
5138
5167
|
getDefaultIndexDefinitions() {
|
|
5139
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
5168
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
5140
5169
|
return BackgroundTasksPG.getDefaultIndexDefs(schemaPrefix);
|
|
5141
5170
|
}
|
|
5142
5171
|
async createDefaultIndexes() {
|
|
@@ -5498,7 +5527,7 @@ var ChannelsPG = class ChannelsPG extends ChannelsStorage {
|
|
|
5498
5527
|
}
|
|
5499
5528
|
static getExportDDL(schemaName) {
|
|
5500
5529
|
const statements = [];
|
|
5501
|
-
const parsedSchema = schemaName ?
|
|
5530
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
5502
5531
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
5503
5532
|
for (const tableName of ChannelsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
5504
5533
|
tableName,
|
|
@@ -5510,7 +5539,7 @@ var ChannelsPG = class ChannelsPG extends ChannelsStorage {
|
|
|
5510
5539
|
return statements;
|
|
5511
5540
|
}
|
|
5512
5541
|
getDefaultIndexDefinitions() {
|
|
5513
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
5542
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
5514
5543
|
return ChannelsPG.getDefaultIndexDefs(schemaPrefix);
|
|
5515
5544
|
}
|
|
5516
5545
|
async createDefaultIndexes() {
|
|
@@ -7022,7 +7051,7 @@ var ExperimentsPG = class ExperimentsPG extends ExperimentsStorage {
|
|
|
7022
7051
|
* so its supporting index is not part of the default index set.
|
|
7023
7052
|
*/
|
|
7024
7053
|
async ensureRetentionIndexes(policies) {
|
|
7025
|
-
const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
7054
|
+
const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
7026
7055
|
for (const [key, entry] of Object.entries(ExperimentsPG.retentionTables)) {
|
|
7027
7056
|
if (!entry.indexed || !policies[key]) continue;
|
|
7028
7057
|
try {
|
|
@@ -8190,7 +8219,7 @@ function postgresSql(sql, schemaName) {
|
|
|
8190
8219
|
return transformed;
|
|
8191
8220
|
});
|
|
8192
8221
|
if (schemaName) {
|
|
8193
|
-
const quotedSchema = `"${
|
|
8222
|
+
const quotedSchema = `"${parseSchemaName(schemaName)}"`;
|
|
8194
8223
|
normalized = transformSqlCode(normalized, (code) => {
|
|
8195
8224
|
let transformed = code;
|
|
8196
8225
|
for (const table of [
|
|
@@ -8303,7 +8332,7 @@ function parseOutbox(row) {
|
|
|
8303
8332
|
function knowledgeIndexes(schemaName) {
|
|
8304
8333
|
const table = (name) => {
|
|
8305
8334
|
const quotedName = `"${parseSqlIdentifier(name, "table name")}"`;
|
|
8306
|
-
return schemaName ? `"${
|
|
8335
|
+
return schemaName ? `"${parseSchemaName(schemaName)}".${quotedName}` : quotedName;
|
|
8307
8336
|
};
|
|
8308
8337
|
return [
|
|
8309
8338
|
{
|
|
@@ -9207,7 +9236,7 @@ var MCPClientsPG = class MCPClientsPG extends MCPClientsStorage {
|
|
|
9207
9236
|
}
|
|
9208
9237
|
static getExportDDL(schemaName) {
|
|
9209
9238
|
const statements = [];
|
|
9210
|
-
const parsedSchema = schemaName ?
|
|
9239
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
9211
9240
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
9212
9241
|
for (const tableName of MCPClientsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
9213
9242
|
tableName,
|
|
@@ -9219,7 +9248,7 @@ var MCPClientsPG = class MCPClientsPG extends MCPClientsStorage {
|
|
|
9219
9248
|
return statements;
|
|
9220
9249
|
}
|
|
9221
9250
|
getDefaultIndexDefinitions() {
|
|
9222
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
9251
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
9223
9252
|
return MCPClientsPG.getDefaultIndexDefs(schemaPrefix);
|
|
9224
9253
|
}
|
|
9225
9254
|
async createDefaultIndexes() {
|
|
@@ -9775,7 +9804,7 @@ var MCPServersPG = class MCPServersPG extends MCPServersStorage {
|
|
|
9775
9804
|
}
|
|
9776
9805
|
static getExportDDL(schemaName) {
|
|
9777
9806
|
const statements = [];
|
|
9778
|
-
const parsedSchema = schemaName ?
|
|
9807
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
9779
9808
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
9780
9809
|
for (const tableName of MCPServersPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
9781
9810
|
tableName,
|
|
@@ -9787,7 +9816,7 @@ var MCPServersPG = class MCPServersPG extends MCPServersStorage {
|
|
|
9787
9816
|
return statements;
|
|
9788
9817
|
}
|
|
9789
9818
|
getDefaultIndexDefinitions() {
|
|
9790
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
9819
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
9791
9820
|
return MCPServersPG.getDefaultIndexDefs(schemaPrefix);
|
|
9792
9821
|
}
|
|
9793
9822
|
async createDefaultIndexes() {
|
|
@@ -10497,7 +10526,7 @@ var MemoryPG = class MemoryPG extends MemoryStorage {
|
|
|
10497
10526
|
* so its supporting index is not part of the default index set.
|
|
10498
10527
|
*/
|
|
10499
10528
|
async ensureRetentionIndexes(policies) {
|
|
10500
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
10529
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
10501
10530
|
for (const [key, entry] of Object.entries(MemoryPG.retentionTables)) {
|
|
10502
10531
|
if (!entry.indexed || !policies[key]) continue;
|
|
10503
10532
|
try {
|
|
@@ -10532,7 +10561,7 @@ var MemoryPG = class MemoryPG extends MemoryStorage {
|
|
|
10532
10561
|
*/
|
|
10533
10562
|
static getExportDDL(schemaName) {
|
|
10534
10563
|
const statements = [];
|
|
10535
|
-
const parsedSchema = schemaName ?
|
|
10564
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
10536
10565
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
10537
10566
|
const quotedSchemaName = getSchemaName$6(schemaName);
|
|
10538
10567
|
for (const tableName of [
|
|
@@ -10567,7 +10596,7 @@ var MemoryPG = class MemoryPG extends MemoryStorage {
|
|
|
10567
10596
|
* Returns default index definitions for this instance's schema.
|
|
10568
10597
|
*/
|
|
10569
10598
|
getDefaultIndexDefinitions() {
|
|
10570
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
10599
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
10571
10600
|
return MemoryPG.getDefaultIndexDefs(schemaPrefix);
|
|
10572
10601
|
}
|
|
10573
10602
|
/**
|
|
@@ -12975,7 +13004,7 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
12975
13004
|
* so its supporting index is not part of the default index set.
|
|
12976
13005
|
*/
|
|
12977
13006
|
async ensureRetentionIndexes(policies) {
|
|
12978
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
13007
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
12979
13008
|
for (const [key, entry] of Object.entries(NotificationsPG.retentionTables)) {
|
|
12980
13009
|
if (!entry.indexed || !policies[key]) continue;
|
|
12981
13010
|
try {
|
|
@@ -13042,7 +13071,7 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
13042
13071
|
}
|
|
13043
13072
|
static getExportDDL(schemaName) {
|
|
13044
13073
|
const statements = [];
|
|
13045
|
-
const parsedSchema = schemaName ?
|
|
13074
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
13046
13075
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
13047
13076
|
statements.push(generateTableSQL({
|
|
13048
13077
|
tableName: TABLE_NOTIFICATIONS,
|
|
@@ -13054,7 +13083,7 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
13054
13083
|
return statements;
|
|
13055
13084
|
}
|
|
13056
13085
|
getDefaultIndexDefinitions() {
|
|
13057
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
13086
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
13058
13087
|
return NotificationsPG.getDefaultIndexDefs(schemaPrefix);
|
|
13059
13088
|
}
|
|
13060
13089
|
async createDefaultIndexes() {
|
|
@@ -13351,7 +13380,7 @@ var ObservabilityPG = class ObservabilityPG extends ObservabilityStorage {
|
|
|
13351
13380
|
* so its supporting index is not part of the default index set.
|
|
13352
13381
|
*/
|
|
13353
13382
|
async ensureRetentionIndexes(policies) {
|
|
13354
|
-
const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
13383
|
+
const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
13355
13384
|
for (const [key, entry] of Object.entries(ObservabilityPG.retentionTables)) {
|
|
13356
13385
|
if (!entry.indexed || !policies[key]) continue;
|
|
13357
13386
|
try {
|
|
@@ -13432,7 +13461,7 @@ var ObservabilityPG = class ObservabilityPG extends ObservabilityStorage {
|
|
|
13432
13461
|
*/
|
|
13433
13462
|
static getExportDDL(schemaName) {
|
|
13434
13463
|
const statements = [];
|
|
13435
|
-
const parsedSchema = schemaName ?
|
|
13464
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
13436
13465
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
13437
13466
|
statements.push(generateTableSQL({
|
|
13438
13467
|
tableName: TABLE_SPANS,
|
|
@@ -13448,7 +13477,7 @@ var ObservabilityPG = class ObservabilityPG extends ObservabilityStorage {
|
|
|
13448
13477
|
* Returns default index definitions for this instance's schema.
|
|
13449
13478
|
*/
|
|
13450
13479
|
getDefaultIndexDefinitions() {
|
|
13451
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
13480
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
13452
13481
|
return ObservabilityPG.getDefaultIndexDefs(schemaPrefix);
|
|
13453
13482
|
}
|
|
13454
13483
|
/**
|
|
@@ -14659,15 +14688,15 @@ const SIGNAL_TIME_COLUMN = {
|
|
|
14659
14688
|
};
|
|
14660
14689
|
/** Returns a fully-qualified, double-quoted table name. */
|
|
14661
14690
|
function qualifiedTable(schema, table) {
|
|
14662
|
-
return `"${
|
|
14691
|
+
return `"${parseSchemaName(schema)}"."${parseSqlIdentifier(table, "table name")}"`;
|
|
14663
14692
|
}
|
|
14664
14693
|
/** Returns a parsed, quoted, schema-prefixed object name (constraint, index, etc.). */
|
|
14665
14694
|
function qualifiedName(schema, name) {
|
|
14666
|
-
return `"${
|
|
14695
|
+
return `"${parseSchemaName(schema)}"."${parseSqlIdentifier(name, "object name")}"`;
|
|
14667
14696
|
}
|
|
14668
14697
|
/** Schema CREATE. Safe to run repeatedly before table DDL. */
|
|
14669
14698
|
function schemaDDL(schema) {
|
|
14670
|
-
return `CREATE SCHEMA IF NOT EXISTS "${
|
|
14699
|
+
return `CREATE SCHEMA IF NOT EXISTS "${parseSchemaName(schema)}"`;
|
|
14671
14700
|
}
|
|
14672
14701
|
/**
|
|
14673
14702
|
* Postgres declarative partitioning and Timescale hypertables are mutually
|
|
@@ -18957,21 +18986,35 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
18957
18986
|
if (!deltaPollingFeatureEnabled()) return [
|
|
18958
18987
|
"metrics",
|
|
18959
18988
|
"logs",
|
|
18989
|
+
"entity-type-discovery",
|
|
18990
|
+
"entity-name-discovery",
|
|
18991
|
+
"service-name-discovery",
|
|
18992
|
+
"environment-discovery",
|
|
18993
|
+
"tag-discovery",
|
|
18994
|
+
"metric-discovery",
|
|
18960
18995
|
"trace-query",
|
|
18961
18996
|
"trace-query-root-duration",
|
|
18962
18997
|
"trace-query-discovery",
|
|
18963
18998
|
"thread-query",
|
|
18964
|
-
"trace-query-tenant-scope"
|
|
18999
|
+
"trace-query-tenant-scope",
|
|
19000
|
+
"feedback"
|
|
18965
19001
|
];
|
|
18966
19002
|
return [
|
|
18967
19003
|
"metrics",
|
|
18968
19004
|
"logs",
|
|
19005
|
+
"entity-type-discovery",
|
|
19006
|
+
"entity-name-discovery",
|
|
19007
|
+
"service-name-discovery",
|
|
19008
|
+
"environment-discovery",
|
|
19009
|
+
"tag-discovery",
|
|
19010
|
+
"metric-discovery",
|
|
18969
19011
|
"delta-polling",
|
|
18970
19012
|
"trace-query",
|
|
18971
19013
|
"trace-query-root-duration",
|
|
18972
19014
|
"trace-query-discovery",
|
|
18973
19015
|
"thread-query",
|
|
18974
|
-
"trace-query-tenant-scope"
|
|
19016
|
+
"trace-query-tenant-scope",
|
|
19017
|
+
"feedback"
|
|
18975
19018
|
];
|
|
18976
19019
|
}
|
|
18977
19020
|
async #run(op, fn, details) {
|
|
@@ -19193,7 +19236,7 @@ var PromptBlocksPG = class PromptBlocksPG extends PromptBlocksStorage {
|
|
|
19193
19236
|
*/
|
|
19194
19237
|
static getExportDDL(schemaName) {
|
|
19195
19238
|
const statements = [];
|
|
19196
|
-
const parsedSchema = schemaName ?
|
|
19239
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
19197
19240
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19198
19241
|
for (const tableName of PromptBlocksPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
19199
19242
|
tableName,
|
|
@@ -19205,7 +19248,7 @@ var PromptBlocksPG = class PromptBlocksPG extends PromptBlocksStorage {
|
|
|
19205
19248
|
return statements;
|
|
19206
19249
|
}
|
|
19207
19250
|
getDefaultIndexDefinitions() {
|
|
19208
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19251
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19209
19252
|
return PromptBlocksPG.getDefaultIndexDefs(schemaPrefix);
|
|
19210
19253
|
}
|
|
19211
19254
|
async createDefaultIndexes() {
|
|
@@ -19840,7 +19883,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19840
19883
|
* so its supporting index is not part of the default index set.
|
|
19841
19884
|
*/
|
|
19842
19885
|
async ensureRetentionIndexes(policies) {
|
|
19843
|
-
const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19886
|
+
const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19844
19887
|
for (const [key, entry] of Object.entries(SchedulesPG.retentionTables)) {
|
|
19845
19888
|
if (!entry.indexed || !policies[key]) continue;
|
|
19846
19889
|
try {
|
|
@@ -19888,7 +19931,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19888
19931
|
}];
|
|
19889
19932
|
}
|
|
19890
19933
|
getDefaultIndexDefinitions() {
|
|
19891
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19934
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19892
19935
|
return SchedulesPG.getDefaultIndexDefs(schemaPrefix);
|
|
19893
19936
|
}
|
|
19894
19937
|
async createDefaultIndexes() {
|
|
@@ -19909,7 +19952,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19909
19952
|
}
|
|
19910
19953
|
static getExportDDL(schemaName) {
|
|
19911
19954
|
const statements = [];
|
|
19912
|
-
const parsedSchema = schemaName ?
|
|
19955
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
19913
19956
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19914
19957
|
statements.push(generateTableSQL({
|
|
19915
19958
|
tableName: TABLE_SCHEDULES,
|
|
@@ -19931,7 +19974,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19931
19974
|
await this.#db.clearTable({ tableName: TABLE_SCHEDULES });
|
|
19932
19975
|
}
|
|
19933
19976
|
#table(tableName) {
|
|
19934
|
-
return getTableName$2(tableName, getSchemaName$2(
|
|
19977
|
+
return getTableName$2(tableName, getSchemaName$2(parseSchemaName(this.#schema)));
|
|
19935
19978
|
}
|
|
19936
19979
|
async createSchedule(schedule) {
|
|
19937
19980
|
if (await this.#getSchedule(this.#client, schedule.id)) throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
@@ -20136,7 +20179,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends ScorerDefinitionsSto
|
|
|
20136
20179
|
*/
|
|
20137
20180
|
static getExportDDL(schemaName) {
|
|
20138
20181
|
const statements = [];
|
|
20139
|
-
const parsedSchema = schemaName ?
|
|
20182
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
20140
20183
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
20141
20184
|
for (const tableName of ScorerDefinitionsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
20142
20185
|
tableName,
|
|
@@ -20148,7 +20191,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends ScorerDefinitionsSto
|
|
|
20148
20191
|
return statements;
|
|
20149
20192
|
}
|
|
20150
20193
|
getDefaultIndexDefinitions() {
|
|
20151
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20194
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20152
20195
|
return ScorerDefinitionsPG.getDefaultIndexDefs(schemaPrefix);
|
|
20153
20196
|
}
|
|
20154
20197
|
async createDefaultIndexes() {
|
|
@@ -20781,7 +20824,7 @@ var ScoresPG = class ScoresPG extends ScoresStorage {
|
|
|
20781
20824
|
* so its supporting index is not part of the default index set.
|
|
20782
20825
|
*/
|
|
20783
20826
|
async ensureRetentionIndexes(policies) {
|
|
20784
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20827
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20785
20828
|
for (const [key, entry] of Object.entries(ScoresPG.retentionTables)) {
|
|
20786
20829
|
if (!entry.indexed || !policies[key]) continue;
|
|
20787
20830
|
try {
|
|
@@ -20816,7 +20859,7 @@ var ScoresPG = class ScoresPG extends ScoresStorage {
|
|
|
20816
20859
|
*/
|
|
20817
20860
|
static getExportDDL(schemaName) {
|
|
20818
20861
|
const statements = [];
|
|
20819
|
-
const parsedSchema = schemaName ?
|
|
20862
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
20820
20863
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
20821
20864
|
statements.push(generateTableSQL({
|
|
20822
20865
|
tableName: TABLE_SCORERS,
|
|
@@ -20831,7 +20874,7 @@ var ScoresPG = class ScoresPG extends ScoresStorage {
|
|
|
20831
20874
|
* Returns default index definitions for this instance's schema.
|
|
20832
20875
|
*/
|
|
20833
20876
|
getDefaultIndexDefinitions() {
|
|
20834
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20877
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20835
20878
|
return ScoresPG.getDefaultIndexDefs(schemaPrefix);
|
|
20836
20879
|
}
|
|
20837
20880
|
/**
|
|
@@ -21194,7 +21237,7 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21194
21237
|
}
|
|
21195
21238
|
static getExportDDL(schemaName) {
|
|
21196
21239
|
const statements = [];
|
|
21197
|
-
const parsedSchema = schemaName ?
|
|
21240
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
21198
21241
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
21199
21242
|
for (const tableName of SkillsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
21200
21243
|
tableName,
|
|
@@ -21206,7 +21249,7 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21206
21249
|
return statements;
|
|
21207
21250
|
}
|
|
21208
21251
|
getDefaultIndexDefinitions() {
|
|
21209
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
21252
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
21210
21253
|
return SkillsPG.getDefaultIndexDefs(schemaPrefix);
|
|
21211
21254
|
}
|
|
21212
21255
|
async createDefaultIndexes() {
|
|
@@ -21901,7 +21944,7 @@ var ThreadStatePG = class ThreadStatePG extends ThreadStateStorage {
|
|
|
21901
21944
|
* a failure here leaves pruning correct, just slower.
|
|
21902
21945
|
*/
|
|
21903
21946
|
async #ensureRetentionIndexes(policies) {
|
|
21904
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
21947
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
21905
21948
|
for (const [key, entry] of Object.entries(ThreadStatePG.retentionTables)) {
|
|
21906
21949
|
if (!entry.indexed || !policies[key]) continue;
|
|
21907
21950
|
try {
|
|
@@ -22067,7 +22110,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends ToolProv
|
|
|
22067
22110
|
}
|
|
22068
22111
|
static getExportDDL(schemaName) {
|
|
22069
22112
|
const statements = [];
|
|
22070
|
-
const parsedSchema = schemaName ?
|
|
22113
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
22071
22114
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
22072
22115
|
statements.push(generateTableSQL({
|
|
22073
22116
|
tableName: TABLE_TOOL_PROVIDER_CONNECTIONS,
|
|
@@ -22084,7 +22127,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends ToolProv
|
|
|
22084
22127
|
return statements;
|
|
22085
22128
|
}
|
|
22086
22129
|
getDefaultIndexDefinitions() {
|
|
22087
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22130
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22088
22131
|
return ToolProviderConnectionsPG.getDefaultIndexDefs(schemaPrefix);
|
|
22089
22132
|
}
|
|
22090
22133
|
async createDefaultIndexes() {
|
|
@@ -22316,7 +22359,7 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends WorkflowDefiniti
|
|
|
22316
22359
|
}
|
|
22317
22360
|
getDefaultIndexDefinitions() {
|
|
22318
22361
|
return [{
|
|
22319
|
-
name: `${this.#schema !== "public" ? `${this.#schema}_` : ""}idx_workflow_definitions_status`,
|
|
22362
|
+
name: `${this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : ""}idx_workflow_definitions_status`,
|
|
22320
22363
|
table: TABLE_WORKFLOW_DEFINITIONS,
|
|
22321
22364
|
columns: ["status"]
|
|
22322
22365
|
}];
|
|
@@ -22593,7 +22636,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
22593
22636
|
*/
|
|
22594
22637
|
static getExportDDL(schemaName) {
|
|
22595
22638
|
const statements = [];
|
|
22596
|
-
const parsedSchema = schemaName ?
|
|
22639
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
22597
22640
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
22598
22641
|
statements.push(generateTableSQL({
|
|
22599
22642
|
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
@@ -22610,7 +22653,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
22610
22653
|
* Returns default index definitions for the workflows domain tables.
|
|
22611
22654
|
*/
|
|
22612
22655
|
getDefaultIndexDefinitions() {
|
|
22613
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22656
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22614
22657
|
return WorkflowsPG.getDefaultIndexDefs(schemaPrefix);
|
|
22615
22658
|
}
|
|
22616
22659
|
/**
|
|
@@ -22660,7 +22703,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
22660
22703
|
* so its supporting index is not part of the default index set.
|
|
22661
22704
|
*/
|
|
22662
22705
|
async ensureRetentionIndexes(policies) {
|
|
22663
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22706
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22664
22707
|
for (const [key, entry] of Object.entries(WorkflowsPG.retentionTables)) {
|
|
22665
22708
|
if (!entry.indexed || !policies[key]) continue;
|
|
22666
22709
|
try {
|
|
@@ -23038,7 +23081,7 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23038
23081
|
}
|
|
23039
23082
|
static getExportDDL(schemaName) {
|
|
23040
23083
|
const statements = [];
|
|
23041
|
-
const parsedSchema = schemaName ?
|
|
23084
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
23042
23085
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
23043
23086
|
for (const tableName of WorkspacesPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
23044
23087
|
tableName,
|
|
@@ -23050,7 +23093,7 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23050
23093
|
return statements;
|
|
23051
23094
|
}
|
|
23052
23095
|
getDefaultIndexDefinitions() {
|
|
23053
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
23096
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
23054
23097
|
return WorkspacesPG.getDefaultIndexDefs(schemaPrefix);
|
|
23055
23098
|
}
|
|
23056
23099
|
async createDefaultIndexes() {
|
|
@@ -24178,7 +24221,7 @@ var PostgresStore = class extends MastraCompositeStore {
|
|
|
24178
24221
|
disableInit: config.disableInit,
|
|
24179
24222
|
retention: config.retention
|
|
24180
24223
|
});
|
|
24181
|
-
this.schema =
|
|
24224
|
+
this.schema = parseSchemaName(config.schemaName || "public");
|
|
24182
24225
|
if (isPoolConfig(config)) {
|
|
24183
24226
|
this.#writePool = config.pool;
|
|
24184
24227
|
this.#ownsWritePool = false;
|