@mastra/pg 1.9.4 → 1.10.0-alpha.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/CHANGELOG.md +28 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +302 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +303 -23
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +22 -0
- package/dist/storage/domains/schedules/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.10.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Extend the schedules storage schema to support owned schedules and richer trigger audit. This is a breaking schema change to `mastra_schedules` and `mastra_schedule_triggers`; scheduled workflows are still in alpha so no compat shim is provided. ([#16166](https://github.com/mastra-ai/mastra/pull/16166))
|
|
8
|
+
- `Schedule` gains optional `ownerType` / `ownerId` so a schedule row can be attributed to an owning subsystem (e.g. an agent that owns a heartbeat schedule). Workflow schedules leave both fields unset.
|
|
9
|
+
- `ScheduleTrigger.status` is renamed to `outcome` and the type is widened to `ScheduleTriggerOutcome` so future outcome values can be added without another rename.
|
|
10
|
+
- `ScheduleTrigger` gains a stable `id` primary key and new `triggerKind`, `parentTriggerId`, and `metadata` fields. `triggerKind` distinguishes `schedule-fire` rows from later `queue-drain` rows (used by upcoming heartbeat work); `parentTriggerId` links related rows; `metadata` carries outcome-specific context.
|
|
11
|
+
- The libsql, pg, and mongodb adapters all add the new columns/indexes. Their `@mastra/core` peer dependency is tightened to `>=1.32.0-0 <2.0.0-0` so installing a new storage adapter against an older core (or vice-versa) surfaces a peer-dependency warning at install time instead of silently writing/reading the wrong field.
|
|
12
|
+
- Scheduler producer, server schemas/handler, and client SDK types are updated to use the new fields. The `triggers` response on `GET /api/schedules/:id/triggers` now returns `outcome` instead of `status`.
|
|
13
|
+
- The bundled Studio (Mastra CLI) is updated to read `outcome` so the schedule detail page keeps polling and rendering publish-failure rows correctly.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0)]:
|
|
18
|
+
- @mastra/core@1.32.0-alpha.3
|
|
19
|
+
|
|
20
|
+
## 1.10.0-alpha.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- Added the `schedules` storage domain so Postgres-backed Mastra apps can use scheduled workflows. Creates `mastra_schedules` and `mastra_schedule_triggers` tables on init, with default indexes on `(status, next_fire_at)` for due-schedule polling and `(schedule_id, actual_fire_at)` for trigger-history queries. ([#15830](https://github.com/mastra-ai/mastra/pull/15830))
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
|
|
29
|
+
- @mastra/core@1.32.0-alpha.1
|
|
30
|
+
|
|
3
31
|
## 1.9.4
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -11377,6 +11377,284 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
|
|
|
11377
11377
|
};
|
|
11378
11378
|
}
|
|
11379
11379
|
};
|
|
11380
|
+
function getSchemaName5(schema) {
|
|
11381
|
+
return schema ? `"${schema}"` : '"public"';
|
|
11382
|
+
}
|
|
11383
|
+
function getTableName5(table, schema) {
|
|
11384
|
+
const quoted = `"${table}"`;
|
|
11385
|
+
return schema ? `${schema}.${quoted}` : quoted;
|
|
11386
|
+
}
|
|
11387
|
+
function parseJson2(val) {
|
|
11388
|
+
if (val == null) return void 0;
|
|
11389
|
+
if (typeof val === "string") {
|
|
11390
|
+
try {
|
|
11391
|
+
return JSON.parse(val);
|
|
11392
|
+
} catch {
|
|
11393
|
+
return val;
|
|
11394
|
+
}
|
|
11395
|
+
}
|
|
11396
|
+
return val;
|
|
11397
|
+
}
|
|
11398
|
+
function toNumber(val) {
|
|
11399
|
+
if (typeof val === "bigint") return Number(val);
|
|
11400
|
+
return Number(val);
|
|
11401
|
+
}
|
|
11402
|
+
function rowToSchedule(row) {
|
|
11403
|
+
const target = parseJson2(row.target);
|
|
11404
|
+
if (!target) {
|
|
11405
|
+
throw new Error(`Schedule row ${row.id} has invalid target`);
|
|
11406
|
+
}
|
|
11407
|
+
const schedule = {
|
|
11408
|
+
id: String(row.id),
|
|
11409
|
+
target,
|
|
11410
|
+
cron: String(row.cron),
|
|
11411
|
+
status: String(row.status),
|
|
11412
|
+
nextFireAt: toNumber(row.next_fire_at),
|
|
11413
|
+
createdAt: toNumber(row.created_at),
|
|
11414
|
+
updatedAt: toNumber(row.updated_at)
|
|
11415
|
+
};
|
|
11416
|
+
if (row.timezone != null) schedule.timezone = String(row.timezone);
|
|
11417
|
+
if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
|
|
11418
|
+
if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
|
|
11419
|
+
const metadata = parseJson2(row.metadata);
|
|
11420
|
+
if (metadata !== void 0) schedule.metadata = metadata;
|
|
11421
|
+
if (row.owner_type != null) schedule.ownerType = String(row.owner_type);
|
|
11422
|
+
if (row.owner_id != null) schedule.ownerId = String(row.owner_id);
|
|
11423
|
+
return schedule;
|
|
11424
|
+
}
|
|
11425
|
+
function rowToTrigger(row) {
|
|
11426
|
+
const trigger = {
|
|
11427
|
+
id: row.id != null ? String(row.id) : void 0,
|
|
11428
|
+
scheduleId: String(row.schedule_id),
|
|
11429
|
+
runId: row.run_id != null ? String(row.run_id) : null,
|
|
11430
|
+
scheduledFireAt: toNumber(row.scheduled_fire_at),
|
|
11431
|
+
actualFireAt: toNumber(row.actual_fire_at),
|
|
11432
|
+
outcome: String(row.outcome),
|
|
11433
|
+
triggerKind: row.trigger_kind != null ? String(row.trigger_kind) : "schedule-fire"
|
|
11434
|
+
};
|
|
11435
|
+
if (row.error != null) trigger.error = String(row.error);
|
|
11436
|
+
if (row.parent_trigger_id != null) trigger.parentTriggerId = String(row.parent_trigger_id);
|
|
11437
|
+
const metadata = parseJson2(row.metadata);
|
|
11438
|
+
if (metadata !== void 0) trigger.metadata = metadata;
|
|
11439
|
+
return trigger;
|
|
11440
|
+
}
|
|
11441
|
+
var SchedulesPG = class extends storage.SchedulesStorage {
|
|
11442
|
+
#db;
|
|
11443
|
+
#client;
|
|
11444
|
+
#schema;
|
|
11445
|
+
/** Tables managed by this domain */
|
|
11446
|
+
static MANAGED_TABLES = [storage.TABLE_SCHEDULES, storage.TABLE_SCHEDULE_TRIGGERS];
|
|
11447
|
+
constructor(config) {
|
|
11448
|
+
super();
|
|
11449
|
+
const { client, schemaName, skipDefaultIndexes } = resolvePgConfig(config);
|
|
11450
|
+
this.#client = client;
|
|
11451
|
+
this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
|
|
11452
|
+
this.#schema = schemaName || "public";
|
|
11453
|
+
}
|
|
11454
|
+
async init() {
|
|
11455
|
+
await this.#db.createTable({
|
|
11456
|
+
tableName: storage.TABLE_SCHEDULES,
|
|
11457
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULES]
|
|
11458
|
+
});
|
|
11459
|
+
await this.#db.createTable({
|
|
11460
|
+
tableName: storage.TABLE_SCHEDULE_TRIGGERS,
|
|
11461
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULE_TRIGGERS]
|
|
11462
|
+
});
|
|
11463
|
+
}
|
|
11464
|
+
static getExportDDL(schemaName) {
|
|
11465
|
+
return [
|
|
11466
|
+
generateTableSQL({
|
|
11467
|
+
tableName: storage.TABLE_SCHEDULES,
|
|
11468
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULES],
|
|
11469
|
+
schemaName,
|
|
11470
|
+
includeAllConstraints: true
|
|
11471
|
+
}),
|
|
11472
|
+
generateTableSQL({
|
|
11473
|
+
tableName: storage.TABLE_SCHEDULE_TRIGGERS,
|
|
11474
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULE_TRIGGERS],
|
|
11475
|
+
schemaName,
|
|
11476
|
+
includeAllConstraints: true
|
|
11477
|
+
})
|
|
11478
|
+
];
|
|
11479
|
+
}
|
|
11480
|
+
async dangerouslyClearAll() {
|
|
11481
|
+
await this.#db.clearTable({ tableName: storage.TABLE_SCHEDULE_TRIGGERS });
|
|
11482
|
+
await this.#db.clearTable({ tableName: storage.TABLE_SCHEDULES });
|
|
11483
|
+
}
|
|
11484
|
+
#table(tableName) {
|
|
11485
|
+
const schema = utils.parseSqlIdentifier(this.#schema, "schema name");
|
|
11486
|
+
return getTableName5(tableName, getSchemaName5(schema));
|
|
11487
|
+
}
|
|
11488
|
+
async createSchedule(schedule) {
|
|
11489
|
+
const existing = await this.getSchedule(schedule.id);
|
|
11490
|
+
if (existing) {
|
|
11491
|
+
throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
11492
|
+
}
|
|
11493
|
+
await this.#db.insert({
|
|
11494
|
+
tableName: storage.TABLE_SCHEDULES,
|
|
11495
|
+
record: {
|
|
11496
|
+
id: schedule.id,
|
|
11497
|
+
target: schedule.target,
|
|
11498
|
+
cron: schedule.cron,
|
|
11499
|
+
timezone: schedule.timezone ?? null,
|
|
11500
|
+
status: schedule.status,
|
|
11501
|
+
next_fire_at: schedule.nextFireAt,
|
|
11502
|
+
last_fire_at: schedule.lastFireAt ?? null,
|
|
11503
|
+
last_run_id: schedule.lastRunId ?? null,
|
|
11504
|
+
created_at: schedule.createdAt,
|
|
11505
|
+
updated_at: schedule.updatedAt,
|
|
11506
|
+
metadata: schedule.metadata ?? null,
|
|
11507
|
+
owner_type: schedule.ownerType ?? null,
|
|
11508
|
+
owner_id: schedule.ownerId ?? null
|
|
11509
|
+
}
|
|
11510
|
+
});
|
|
11511
|
+
return schedule;
|
|
11512
|
+
}
|
|
11513
|
+
async getSchedule(id) {
|
|
11514
|
+
const row = await this.#client.oneOrNone(
|
|
11515
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULES)} WHERE id = $1`,
|
|
11516
|
+
[id]
|
|
11517
|
+
);
|
|
11518
|
+
return row ? rowToSchedule(row) : null;
|
|
11519
|
+
}
|
|
11520
|
+
async listSchedules(filter) {
|
|
11521
|
+
const conditions = [];
|
|
11522
|
+
const params = [];
|
|
11523
|
+
if (filter?.status) {
|
|
11524
|
+
params.push(filter.status);
|
|
11525
|
+
conditions.push(`status = $${params.length}`);
|
|
11526
|
+
}
|
|
11527
|
+
if (filter?.workflowId) {
|
|
11528
|
+
params.push(filter.workflowId);
|
|
11529
|
+
conditions.push(`target->>'workflowId' = $${params.length}`);
|
|
11530
|
+
}
|
|
11531
|
+
if (filter?.ownerType !== void 0) {
|
|
11532
|
+
if (filter.ownerType === null) {
|
|
11533
|
+
conditions.push("owner_type IS NULL");
|
|
11534
|
+
} else {
|
|
11535
|
+
params.push(filter.ownerType);
|
|
11536
|
+
conditions.push(`owner_type = $${params.length}`);
|
|
11537
|
+
}
|
|
11538
|
+
}
|
|
11539
|
+
if (filter?.ownerId !== void 0) {
|
|
11540
|
+
if (filter.ownerId === null) {
|
|
11541
|
+
conditions.push("owner_id IS NULL");
|
|
11542
|
+
} else {
|
|
11543
|
+
params.push(filter.ownerId);
|
|
11544
|
+
conditions.push(`owner_id = $${params.length}`);
|
|
11545
|
+
}
|
|
11546
|
+
}
|
|
11547
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
11548
|
+
const rows = await this.#client.manyOrNone(
|
|
11549
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULES)} ${where} ORDER BY created_at ASC`,
|
|
11550
|
+
params
|
|
11551
|
+
);
|
|
11552
|
+
return rows.map(rowToSchedule);
|
|
11553
|
+
}
|
|
11554
|
+
async listDueSchedules(now, limit) {
|
|
11555
|
+
const cap = limit ?? 100;
|
|
11556
|
+
const rows = await this.#client.manyOrNone(
|
|
11557
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULES)}
|
|
11558
|
+
WHERE status = $1 AND next_fire_at <= $2
|
|
11559
|
+
ORDER BY next_fire_at ASC
|
|
11560
|
+
LIMIT $3`,
|
|
11561
|
+
["active", now, cap]
|
|
11562
|
+
);
|
|
11563
|
+
return rows.map(rowToSchedule);
|
|
11564
|
+
}
|
|
11565
|
+
async updateSchedule(id, patch) {
|
|
11566
|
+
const setClauses = [];
|
|
11567
|
+
const params = [];
|
|
11568
|
+
const push = (frag, value) => {
|
|
11569
|
+
params.push(value);
|
|
11570
|
+
setClauses.push(frag.replace("?", `$${params.length}`));
|
|
11571
|
+
};
|
|
11572
|
+
if ("cron" in patch && patch.cron !== void 0) push("cron = ?", patch.cron);
|
|
11573
|
+
if ("timezone" in patch) push("timezone = ?", patch.timezone ?? null);
|
|
11574
|
+
if ("status" in patch && patch.status !== void 0) push("status = ?", patch.status);
|
|
11575
|
+
if ("nextFireAt" in patch && patch.nextFireAt !== void 0) push("next_fire_at = ?", patch.nextFireAt);
|
|
11576
|
+
if ("target" in patch && patch.target !== void 0) {
|
|
11577
|
+
push("target = ?::jsonb", JSON.stringify(patch.target));
|
|
11578
|
+
}
|
|
11579
|
+
if ("metadata" in patch) {
|
|
11580
|
+
push("metadata = ?::jsonb", patch.metadata != null ? JSON.stringify(patch.metadata) : null);
|
|
11581
|
+
}
|
|
11582
|
+
if ("ownerType" in patch) push("owner_type = ?", patch.ownerType ?? null);
|
|
11583
|
+
if ("ownerId" in patch) push("owner_id = ?", patch.ownerId ?? null);
|
|
11584
|
+
push("updated_at = ?", Date.now());
|
|
11585
|
+
if (setClauses.length === 1) {
|
|
11586
|
+
const existing = await this.getSchedule(id);
|
|
11587
|
+
if (!existing) throw new Error(`Schedule ${id} not found`);
|
|
11588
|
+
return existing;
|
|
11589
|
+
}
|
|
11590
|
+
params.push(id);
|
|
11591
|
+
await this.#client.none(
|
|
11592
|
+
`UPDATE ${this.#table(storage.TABLE_SCHEDULES)} SET ${setClauses.join(", ")} WHERE id = $${params.length}`,
|
|
11593
|
+
params
|
|
11594
|
+
);
|
|
11595
|
+
const updated = await this.getSchedule(id);
|
|
11596
|
+
if (!updated) throw new Error(`Schedule ${id} not found`);
|
|
11597
|
+
return updated;
|
|
11598
|
+
}
|
|
11599
|
+
async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
|
|
11600
|
+
const result = await this.#client.query(
|
|
11601
|
+
`UPDATE ${this.#table(storage.TABLE_SCHEDULES)}
|
|
11602
|
+
SET next_fire_at = $1, last_fire_at = $2, last_run_id = $3, updated_at = $4
|
|
11603
|
+
WHERE id = $5 AND next_fire_at = $6 AND status = $7`,
|
|
11604
|
+
[newNextFireAt, lastFireAt, lastRunId, Date.now(), id, expectedNextFireAt, "active"]
|
|
11605
|
+
);
|
|
11606
|
+
return (result.rowCount ?? 0) > 0;
|
|
11607
|
+
}
|
|
11608
|
+
async deleteSchedule(id) {
|
|
11609
|
+
await this.#client.none(`DELETE FROM ${this.#table(storage.TABLE_SCHEDULE_TRIGGERS)} WHERE schedule_id = $1`, [id]);
|
|
11610
|
+
await this.#client.none(`DELETE FROM ${this.#table(storage.TABLE_SCHEDULES)} WHERE id = $1`, [id]);
|
|
11611
|
+
}
|
|
11612
|
+
async recordTrigger(trigger) {
|
|
11613
|
+
const id = trigger.id ?? crypto.randomUUID();
|
|
11614
|
+
await this.#db.insert({
|
|
11615
|
+
tableName: storage.TABLE_SCHEDULE_TRIGGERS,
|
|
11616
|
+
record: {
|
|
11617
|
+
id,
|
|
11618
|
+
schedule_id: trigger.scheduleId,
|
|
11619
|
+
run_id: trigger.runId,
|
|
11620
|
+
scheduled_fire_at: trigger.scheduledFireAt,
|
|
11621
|
+
actual_fire_at: trigger.actualFireAt,
|
|
11622
|
+
outcome: trigger.outcome,
|
|
11623
|
+
error: trigger.error ?? null,
|
|
11624
|
+
trigger_kind: trigger.triggerKind ?? "schedule-fire",
|
|
11625
|
+
parent_trigger_id: trigger.parentTriggerId ?? null,
|
|
11626
|
+
metadata: trigger.metadata ?? null
|
|
11627
|
+
}
|
|
11628
|
+
});
|
|
11629
|
+
}
|
|
11630
|
+
async listTriggers(scheduleId, opts) {
|
|
11631
|
+
const conditions = [];
|
|
11632
|
+
const params = [];
|
|
11633
|
+
params.push(scheduleId);
|
|
11634
|
+
conditions.push(`schedule_id = $${params.length}`);
|
|
11635
|
+
if (opts?.fromActualFireAt != null) {
|
|
11636
|
+
params.push(opts.fromActualFireAt);
|
|
11637
|
+
conditions.push(`actual_fire_at >= $${params.length}`);
|
|
11638
|
+
}
|
|
11639
|
+
if (opts?.toActualFireAt != null) {
|
|
11640
|
+
params.push(opts.toActualFireAt);
|
|
11641
|
+
conditions.push(`actual_fire_at < $${params.length}`);
|
|
11642
|
+
}
|
|
11643
|
+
let limitClause = "";
|
|
11644
|
+
if (opts?.limit != null) {
|
|
11645
|
+
params.push(Math.floor(opts.limit));
|
|
11646
|
+
limitClause = `LIMIT $${params.length}`;
|
|
11647
|
+
}
|
|
11648
|
+
const rows = await this.#client.manyOrNone(
|
|
11649
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULE_TRIGGERS)}
|
|
11650
|
+
WHERE ${conditions.join(" AND ")}
|
|
11651
|
+
ORDER BY actual_fire_at DESC
|
|
11652
|
+
${limitClause}`,
|
|
11653
|
+
params
|
|
11654
|
+
);
|
|
11655
|
+
return rows.map(rowToTrigger);
|
|
11656
|
+
}
|
|
11657
|
+
};
|
|
11380
11658
|
var SNAPSHOT_FIELDS4 = [
|
|
11381
11659
|
"name",
|
|
11382
11660
|
"description",
|
|
@@ -12044,10 +12322,10 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
|
|
|
12044
12322
|
};
|
|
12045
12323
|
}
|
|
12046
12324
|
};
|
|
12047
|
-
function
|
|
12325
|
+
function getSchemaName6(schema) {
|
|
12048
12326
|
return schema ? `"${schema}"` : '"public"';
|
|
12049
12327
|
}
|
|
12050
|
-
function
|
|
12328
|
+
function getTableName6({ indexName, schemaName }) {
|
|
12051
12329
|
const quotedIndexName = `"${indexName}"`;
|
|
12052
12330
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
12053
12331
|
}
|
|
@@ -12161,7 +12439,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12161
12439
|
async getScoreById({ id }) {
|
|
12162
12440
|
try {
|
|
12163
12441
|
const result = await this.#db.client.oneOrNone(
|
|
12164
|
-
`SELECT * FROM ${
|
|
12442
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE id = $1`,
|
|
12165
12443
|
[id]
|
|
12166
12444
|
);
|
|
12167
12445
|
return result ? transformScoreRow(result) : null;
|
|
@@ -12201,7 +12479,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12201
12479
|
}
|
|
12202
12480
|
const whereClause = conditions.join(" AND ");
|
|
12203
12481
|
const total = await this.#db.client.oneOrNone(
|
|
12204
|
-
`SELECT COUNT(*) FROM ${
|
|
12482
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause}`,
|
|
12205
12483
|
queryParams
|
|
12206
12484
|
);
|
|
12207
12485
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12221,7 +12499,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12221
12499
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12222
12500
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12223
12501
|
const result = await this.#db.client.manyOrNone(
|
|
12224
|
-
`SELECT * FROM ${
|
|
12502
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
|
|
12225
12503
|
[...queryParams, limitValue, start]
|
|
12226
12504
|
);
|
|
12227
12505
|
return {
|
|
@@ -12316,7 +12594,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12316
12594
|
}) {
|
|
12317
12595
|
try {
|
|
12318
12596
|
const total = await this.#db.client.oneOrNone(
|
|
12319
|
-
`SELECT COUNT(*) FROM ${
|
|
12597
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1`,
|
|
12320
12598
|
[runId]
|
|
12321
12599
|
);
|
|
12322
12600
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12336,7 +12614,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12336
12614
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12337
12615
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12338
12616
|
const result = await this.#db.client.manyOrNone(
|
|
12339
|
-
`SELECT * FROM ${
|
|
12617
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
|
|
12340
12618
|
[runId, limitValue, start]
|
|
12341
12619
|
);
|
|
12342
12620
|
return {
|
|
@@ -12366,7 +12644,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12366
12644
|
}) {
|
|
12367
12645
|
try {
|
|
12368
12646
|
const total = await this.#db.client.oneOrNone(
|
|
12369
|
-
`SELECT COUNT(*) FROM ${
|
|
12647
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
|
|
12370
12648
|
[entityId, entityType]
|
|
12371
12649
|
);
|
|
12372
12650
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12386,7 +12664,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12386
12664
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12387
12665
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12388
12666
|
const result = await this.#db.client.manyOrNone(
|
|
12389
|
-
`SELECT * FROM ${
|
|
12667
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
|
|
12390
12668
|
[entityId, entityType, limitValue, start]
|
|
12391
12669
|
);
|
|
12392
12670
|
return {
|
|
@@ -12415,7 +12693,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12415
12693
|
pagination
|
|
12416
12694
|
}) {
|
|
12417
12695
|
try {
|
|
12418
|
-
const tableName =
|
|
12696
|
+
const tableName = getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) });
|
|
12419
12697
|
const countSQLResult = await this.#db.client.oneOrNone(
|
|
12420
12698
|
`SELECT COUNT(*) as count FROM ${tableName} WHERE "traceId" = $1 AND "spanId" = $2`,
|
|
12421
12699
|
[traceId, spanId]
|
|
@@ -13118,10 +13396,10 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
|
|
|
13118
13396
|
};
|
|
13119
13397
|
}
|
|
13120
13398
|
};
|
|
13121
|
-
function
|
|
13399
|
+
function getSchemaName7(schema) {
|
|
13122
13400
|
return schema ? `"${schema}"` : '"public"';
|
|
13123
13401
|
}
|
|
13124
|
-
function
|
|
13402
|
+
function getTableName7({ indexName, schemaName }) {
|
|
13125
13403
|
const quotedIndexName = `"${indexName}"`;
|
|
13126
13404
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
13127
13405
|
}
|
|
@@ -13233,7 +13511,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13233
13511
|
}) {
|
|
13234
13512
|
try {
|
|
13235
13513
|
return await this.#db.client.tx(async (t) => {
|
|
13236
|
-
const tableName =
|
|
13514
|
+
const tableName = getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
|
|
13237
13515
|
const existingSnapshotResult = await t.oneOrNone(
|
|
13238
13516
|
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
13239
13517
|
[workflowName, runId]
|
|
@@ -13294,7 +13572,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13294
13572
|
}) {
|
|
13295
13573
|
try {
|
|
13296
13574
|
return await this.#db.client.tx(async (t) => {
|
|
13297
|
-
const tableName =
|
|
13575
|
+
const tableName = getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
|
|
13298
13576
|
const existingSnapshotResult = await t.oneOrNone(
|
|
13299
13577
|
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
13300
13578
|
[workflowName, runId]
|
|
@@ -13344,7 +13622,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13344
13622
|
const updatedAtValue = updatedAt ? updatedAt : now;
|
|
13345
13623
|
const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
|
|
13346
13624
|
await this.#db.client.none(
|
|
13347
|
-
`INSERT INTO ${
|
|
13625
|
+
`INSERT INTO ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
|
|
13348
13626
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
13349
13627
|
ON CONFLICT (workflow_name, run_id) DO UPDATE
|
|
13350
13628
|
SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
|
|
@@ -13402,7 +13680,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13402
13680
|
}
|
|
13403
13681
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13404
13682
|
const query = `
|
|
13405
|
-
SELECT * FROM ${
|
|
13683
|
+
SELECT * FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
|
|
13406
13684
|
${whereClause}
|
|
13407
13685
|
ORDER BY "createdAt" DESC LIMIT 1
|
|
13408
13686
|
`;
|
|
@@ -13430,7 +13708,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13430
13708
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
13431
13709
|
try {
|
|
13432
13710
|
await this.#db.client.none(
|
|
13433
|
-
`DELETE FROM ${
|
|
13711
|
+
`DELETE FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
|
|
13434
13712
|
[runId, workflowName]
|
|
13435
13713
|
);
|
|
13436
13714
|
} catch (error$1) {
|
|
@@ -13498,7 +13776,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13498
13776
|
const usePagination = typeof perPage === "number" && typeof page === "number";
|
|
13499
13777
|
if (usePagination) {
|
|
13500
13778
|
const countResult = await this.#db.client.one(
|
|
13501
|
-
`SELECT COUNT(*) as count FROM ${
|
|
13779
|
+
`SELECT COUNT(*) as count FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} ${whereClause}`,
|
|
13502
13780
|
values
|
|
13503
13781
|
);
|
|
13504
13782
|
total = Number(countResult.count);
|
|
@@ -13506,7 +13784,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13506
13784
|
const normalizedPerPage = usePagination ? storage.normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
|
|
13507
13785
|
const offset = usePagination ? page * normalizedPerPage : void 0;
|
|
13508
13786
|
const query = `
|
|
13509
|
-
SELECT * FROM ${
|
|
13787
|
+
SELECT * FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
|
|
13510
13788
|
${whereClause}
|
|
13511
13789
|
ORDER BY "createdAt" DESC
|
|
13512
13790
|
${usePagination ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
|
|
@@ -14231,7 +14509,8 @@ var ALL_DOMAINS = [
|
|
|
14231
14509
|
DatasetsPG,
|
|
14232
14510
|
ExperimentsPG,
|
|
14233
14511
|
BackgroundTasksPG,
|
|
14234
|
-
ChannelsPG
|
|
14512
|
+
ChannelsPG,
|
|
14513
|
+
SchedulesPG
|
|
14235
14514
|
];
|
|
14236
14515
|
function exportSchemas(schemaName) {
|
|
14237
14516
|
const statements = [];
|
|
@@ -14287,7 +14566,8 @@ var PostgresStore = class extends storage.MastraCompositeStore {
|
|
|
14287
14566
|
datasets: new DatasetsPG(domainConfig),
|
|
14288
14567
|
experiments: new ExperimentsPG(domainConfig),
|
|
14289
14568
|
backgroundTasks: new BackgroundTasksPG(domainConfig),
|
|
14290
|
-
channels: new ChannelsPG(domainConfig)
|
|
14569
|
+
channels: new ChannelsPG(domainConfig),
|
|
14570
|
+
schedules: new SchedulesPG(domainConfig)
|
|
14291
14571
|
};
|
|
14292
14572
|
} catch (e) {
|
|
14293
14573
|
throw new error.MastraError(
|
|
@@ -14491,6 +14771,7 @@ exports.PgVector = PgVector;
|
|
|
14491
14771
|
exports.PoolAdapter = PoolAdapter;
|
|
14492
14772
|
exports.PostgresStore = PostgresStore;
|
|
14493
14773
|
exports.PromptBlocksPG = PromptBlocksPG;
|
|
14774
|
+
exports.SchedulesPG = SchedulesPG;
|
|
14494
14775
|
exports.ScorerDefinitionsPG = ScorerDefinitionsPG;
|
|
14495
14776
|
exports.ScoresPG = ScoresPG;
|
|
14496
14777
|
exports.SkillsPG = SkillsPG;
|