@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/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
|
|
@@ -19207,7 +19236,7 @@ var PromptBlocksPG = class PromptBlocksPG extends PromptBlocksStorage {
|
|
|
19207
19236
|
*/
|
|
19208
19237
|
static getExportDDL(schemaName) {
|
|
19209
19238
|
const statements = [];
|
|
19210
|
-
const parsedSchema = schemaName ?
|
|
19239
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
19211
19240
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19212
19241
|
for (const tableName of PromptBlocksPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
19213
19242
|
tableName,
|
|
@@ -19219,7 +19248,7 @@ var PromptBlocksPG = class PromptBlocksPG extends PromptBlocksStorage {
|
|
|
19219
19248
|
return statements;
|
|
19220
19249
|
}
|
|
19221
19250
|
getDefaultIndexDefinitions() {
|
|
19222
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19251
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19223
19252
|
return PromptBlocksPG.getDefaultIndexDefs(schemaPrefix);
|
|
19224
19253
|
}
|
|
19225
19254
|
async createDefaultIndexes() {
|
|
@@ -19854,7 +19883,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19854
19883
|
* so its supporting index is not part of the default index set.
|
|
19855
19884
|
*/
|
|
19856
19885
|
async ensureRetentionIndexes(policies) {
|
|
19857
|
-
const prefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19886
|
+
const prefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19858
19887
|
for (const [key, entry] of Object.entries(SchedulesPG.retentionTables)) {
|
|
19859
19888
|
if (!entry.indexed || !policies[key]) continue;
|
|
19860
19889
|
try {
|
|
@@ -19902,7 +19931,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19902
19931
|
}];
|
|
19903
19932
|
}
|
|
19904
19933
|
getDefaultIndexDefinitions() {
|
|
19905
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19934
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
19906
19935
|
return SchedulesPG.getDefaultIndexDefs(schemaPrefix);
|
|
19907
19936
|
}
|
|
19908
19937
|
async createDefaultIndexes() {
|
|
@@ -19923,7 +19952,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19923
19952
|
}
|
|
19924
19953
|
static getExportDDL(schemaName) {
|
|
19925
19954
|
const statements = [];
|
|
19926
|
-
const parsedSchema = schemaName ?
|
|
19955
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
19927
19956
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19928
19957
|
statements.push(generateTableSQL({
|
|
19929
19958
|
tableName: TABLE_SCHEDULES,
|
|
@@ -19945,7 +19974,7 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
19945
19974
|
await this.#db.clearTable({ tableName: TABLE_SCHEDULES });
|
|
19946
19975
|
}
|
|
19947
19976
|
#table(tableName) {
|
|
19948
|
-
return getTableName$2(tableName, getSchemaName$2(
|
|
19977
|
+
return getTableName$2(tableName, getSchemaName$2(parseSchemaName(this.#schema)));
|
|
19949
19978
|
}
|
|
19950
19979
|
async createSchedule(schedule) {
|
|
19951
19980
|
if (await this.#getSchedule(this.#client, schedule.id)) throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
@@ -20150,7 +20179,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends ScorerDefinitionsSto
|
|
|
20150
20179
|
*/
|
|
20151
20180
|
static getExportDDL(schemaName) {
|
|
20152
20181
|
const statements = [];
|
|
20153
|
-
const parsedSchema = schemaName ?
|
|
20182
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
20154
20183
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
20155
20184
|
for (const tableName of ScorerDefinitionsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
20156
20185
|
tableName,
|
|
@@ -20162,7 +20191,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends ScorerDefinitionsSto
|
|
|
20162
20191
|
return statements;
|
|
20163
20192
|
}
|
|
20164
20193
|
getDefaultIndexDefinitions() {
|
|
20165
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20194
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20166
20195
|
return ScorerDefinitionsPG.getDefaultIndexDefs(schemaPrefix);
|
|
20167
20196
|
}
|
|
20168
20197
|
async createDefaultIndexes() {
|
|
@@ -20795,7 +20824,7 @@ var ScoresPG = class ScoresPG extends ScoresStorage {
|
|
|
20795
20824
|
* so its supporting index is not part of the default index set.
|
|
20796
20825
|
*/
|
|
20797
20826
|
async ensureRetentionIndexes(policies) {
|
|
20798
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20827
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20799
20828
|
for (const [key, entry] of Object.entries(ScoresPG.retentionTables)) {
|
|
20800
20829
|
if (!entry.indexed || !policies[key]) continue;
|
|
20801
20830
|
try {
|
|
@@ -20830,7 +20859,7 @@ var ScoresPG = class ScoresPG extends ScoresStorage {
|
|
|
20830
20859
|
*/
|
|
20831
20860
|
static getExportDDL(schemaName) {
|
|
20832
20861
|
const statements = [];
|
|
20833
|
-
const parsedSchema = schemaName ?
|
|
20862
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
20834
20863
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
20835
20864
|
statements.push(generateTableSQL({
|
|
20836
20865
|
tableName: TABLE_SCORERS,
|
|
@@ -20845,7 +20874,7 @@ var ScoresPG = class ScoresPG extends ScoresStorage {
|
|
|
20845
20874
|
* Returns default index definitions for this instance's schema.
|
|
20846
20875
|
*/
|
|
20847
20876
|
getDefaultIndexDefinitions() {
|
|
20848
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
20877
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
20849
20878
|
return ScoresPG.getDefaultIndexDefs(schemaPrefix);
|
|
20850
20879
|
}
|
|
20851
20880
|
/**
|
|
@@ -21208,7 +21237,7 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21208
21237
|
}
|
|
21209
21238
|
static getExportDDL(schemaName) {
|
|
21210
21239
|
const statements = [];
|
|
21211
|
-
const parsedSchema = schemaName ?
|
|
21240
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
21212
21241
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
21213
21242
|
for (const tableName of SkillsPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
21214
21243
|
tableName,
|
|
@@ -21220,7 +21249,7 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21220
21249
|
return statements;
|
|
21221
21250
|
}
|
|
21222
21251
|
getDefaultIndexDefinitions() {
|
|
21223
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
21252
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
21224
21253
|
return SkillsPG.getDefaultIndexDefs(schemaPrefix);
|
|
21225
21254
|
}
|
|
21226
21255
|
async createDefaultIndexes() {
|
|
@@ -21915,7 +21944,7 @@ var ThreadStatePG = class ThreadStatePG extends ThreadStateStorage {
|
|
|
21915
21944
|
* a failure here leaves pruning correct, just slower.
|
|
21916
21945
|
*/
|
|
21917
21946
|
async #ensureRetentionIndexes(policies) {
|
|
21918
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
21947
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
21919
21948
|
for (const [key, entry] of Object.entries(ThreadStatePG.retentionTables)) {
|
|
21920
21949
|
if (!entry.indexed || !policies[key]) continue;
|
|
21921
21950
|
try {
|
|
@@ -22081,7 +22110,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends ToolProv
|
|
|
22081
22110
|
}
|
|
22082
22111
|
static getExportDDL(schemaName) {
|
|
22083
22112
|
const statements = [];
|
|
22084
|
-
const parsedSchema = schemaName ?
|
|
22113
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
22085
22114
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
22086
22115
|
statements.push(generateTableSQL({
|
|
22087
22116
|
tableName: TABLE_TOOL_PROVIDER_CONNECTIONS,
|
|
@@ -22098,7 +22127,7 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends ToolProv
|
|
|
22098
22127
|
return statements;
|
|
22099
22128
|
}
|
|
22100
22129
|
getDefaultIndexDefinitions() {
|
|
22101
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22130
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22102
22131
|
return ToolProviderConnectionsPG.getDefaultIndexDefs(schemaPrefix);
|
|
22103
22132
|
}
|
|
22104
22133
|
async createDefaultIndexes() {
|
|
@@ -22330,7 +22359,7 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends WorkflowDefiniti
|
|
|
22330
22359
|
}
|
|
22331
22360
|
getDefaultIndexDefinitions() {
|
|
22332
22361
|
return [{
|
|
22333
|
-
name: `${this.#schema !== "public" ? `${this.#schema}_` : ""}idx_workflow_definitions_status`,
|
|
22362
|
+
name: `${this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : ""}idx_workflow_definitions_status`,
|
|
22334
22363
|
table: TABLE_WORKFLOW_DEFINITIONS,
|
|
22335
22364
|
columns: ["status"]
|
|
22336
22365
|
}];
|
|
@@ -22607,7 +22636,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
22607
22636
|
*/
|
|
22608
22637
|
static getExportDDL(schemaName) {
|
|
22609
22638
|
const statements = [];
|
|
22610
|
-
const parsedSchema = schemaName ?
|
|
22639
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
22611
22640
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
22612
22641
|
statements.push(generateTableSQL({
|
|
22613
22642
|
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
@@ -22624,7 +22653,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
22624
22653
|
* Returns default index definitions for the workflows domain tables.
|
|
22625
22654
|
*/
|
|
22626
22655
|
getDefaultIndexDefinitions() {
|
|
22627
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22656
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22628
22657
|
return WorkflowsPG.getDefaultIndexDefs(schemaPrefix);
|
|
22629
22658
|
}
|
|
22630
22659
|
/**
|
|
@@ -22674,7 +22703,7 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
22674
22703
|
* so its supporting index is not part of the default index set.
|
|
22675
22704
|
*/
|
|
22676
22705
|
async ensureRetentionIndexes(policies) {
|
|
22677
|
-
const prefix = this.#schema && this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
22706
|
+
const prefix = this.#schema && this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
22678
22707
|
for (const [key, entry] of Object.entries(WorkflowsPG.retentionTables)) {
|
|
22679
22708
|
if (!entry.indexed || !policies[key]) continue;
|
|
22680
22709
|
try {
|
|
@@ -23052,7 +23081,7 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23052
23081
|
}
|
|
23053
23082
|
static getExportDDL(schemaName) {
|
|
23054
23083
|
const statements = [];
|
|
23055
|
-
const parsedSchema = schemaName ?
|
|
23084
|
+
const parsedSchema = schemaName ? schemaNamePrefix(schemaName) : "";
|
|
23056
23085
|
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
23057
23086
|
for (const tableName of WorkspacesPG.MANAGED_TABLES) statements.push(generateTableSQL({
|
|
23058
23087
|
tableName,
|
|
@@ -23064,7 +23093,7 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23064
23093
|
return statements;
|
|
23065
23094
|
}
|
|
23066
23095
|
getDefaultIndexDefinitions() {
|
|
23067
|
-
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
23096
|
+
const schemaPrefix = this.#schema !== "public" ? `${schemaNamePrefix(this.#schema)}_` : "";
|
|
23068
23097
|
return WorkspacesPG.getDefaultIndexDefs(schemaPrefix);
|
|
23069
23098
|
}
|
|
23070
23099
|
async createDefaultIndexes() {
|
|
@@ -24192,7 +24221,7 @@ var PostgresStore = class extends MastraCompositeStore {
|
|
|
24192
24221
|
disableInit: config.disableInit,
|
|
24193
24222
|
retention: config.retention
|
|
24194
24223
|
});
|
|
24195
|
-
this.schema =
|
|
24224
|
+
this.schema = parseSchemaName(config.schemaName || "public");
|
|
24196
24225
|
if (isPoolConfig(config)) {
|
|
24197
24226
|
this.#writePool = config.pool;
|
|
24198
24227
|
this.#ownsWritePool = false;
|