@mastra/mysql 0.3.0 → 0.3.1-alpha.0

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/mysql
2
2
 
3
+ ## 0.3.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed workflow snapshots and AI spans creating duplicate records instead of updating in place. Each workflow step previously inserted a new row, causing unbounded table growth and degraded read performance. ([#18460](https://github.com/mastra-ai/mastra/pull/18460))
8
+
9
+ - Fixed workflow runs preserving their original creation time when re-persisted in MySQL storage, including concurrent saves. ([#18004](https://github.com/mastra-ai/mastra/pull/18004))
10
+
11
+ - Updated dependencies [[`bf3fe49`](https://github.com/mastra-ai/mastra/commit/bf3fe49f9467dbbdb8f9eaf74e0f7971ffb19559), [`24ceaea`](https://github.com/mastra-ai/mastra/commit/24ceaea0bdd8609cabbab764380608ca6621a194), [`6ccf67b`](https://github.com/mastra-ai/mastra/commit/6ccf67bf075753754927a57bc2e1734ba2c820c5), [`825d8de`](https://github.com/mastra-ai/mastra/commit/825d8def9fa64c2bcc3d8dd6b49e09342c3ac5c7), [`ffa09e7`](https://github.com/mastra-ai/mastra/commit/ffa09e772a5c92270eabe2090fc42d45bd8ec4b7), [`461a7c5`](https://github.com/mastra-ai/mastra/commit/461a7c501449295287f4f0ee4b0b42344f39fcf8), [`4211472`](https://github.com/mastra-ai/mastra/commit/4211472a5a2bd319c60cd2e42d9109c3eef7ac1c), [`9e45902`](https://github.com/mastra-ai/mastra/commit/9e4590208e745055cecca202e2db0e5c65e17d3c), [`5c0df77`](https://github.com/mastra-ai/mastra/commit/5c0df776c40efa420f8c07a2f3ee66010296618e)]:
12
+ - @mastra/core@1.47.0-alpha.3
13
+
3
14
  ## 0.3.0
4
15
 
5
16
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -296,6 +296,16 @@ var StoreOperationsMySQL = class extends storage.StoreOperations {
296
296
  const pkColumns = tableConfig.compositePrimaryKey.map((col) => quoteIdentifier(col, "primary key column")).join(", ");
297
297
  extraConstraints.push(`PRIMARY KEY (${pkColumns})`);
298
298
  }
299
+ if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
300
+ extraConstraints.push(
301
+ `PRIMARY KEY (${quoteIdentifier("workflow_name", "column name")}, ${quoteIdentifier("run_id", "column name")})`
302
+ );
303
+ }
304
+ if (tableName === storage.TABLE_SPANS) {
305
+ extraConstraints.push(
306
+ `PRIMARY KEY (${quoteIdentifier("traceId", "column name")}, ${quoteIdentifier("spanId", "column name")})`
307
+ );
308
+ }
299
309
  return `CREATE TABLE IF NOT EXISTS ${tableIdent} (${[...columns, ...extraConstraints].filter(Boolean).join(", ")}) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`;
300
310
  }
301
311
  isKeyColumn(tableName, columnName) {
@@ -6888,7 +6898,8 @@ var ObservabilityMySQL = class _ObservabilityMySQL extends storage.Observability
6888
6898
  statements.push(
6889
6899
  generateTableSQL({
6890
6900
  tableName: storage.TABLE_SPANS,
6891
- schema: storage.TABLE_SCHEMAS[storage.TABLE_SPANS]
6901
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_SPANS],
6902
+ compositePrimaryKey: ["traceId", "spanId"]
6892
6903
  })
6893
6904
  );
6894
6905
  for (const idx of _ObservabilityMySQL.getDefaultIndexDefs()) {
@@ -9874,7 +9885,13 @@ var WorkflowsMySQL = class _WorkflowsMySQL extends storage.WorkflowsStorage {
9874
9885
  * Exports DDL statements for all managed tables.
9875
9886
  */
9876
9887
  static getExportDDL() {
9877
- return [generateTableSQL({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT, schema: storage.TABLE_SCHEMAS[storage.TABLE_WORKFLOW_SNAPSHOT] })];
9888
+ return [
9889
+ generateTableSQL({
9890
+ tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
9891
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_WORKFLOW_SNAPSHOT],
9892
+ compositePrimaryKey: ["workflow_name", "run_id"]
9893
+ })
9894
+ ];
9878
9895
  }
9879
9896
  constructor({
9880
9897
  operations,
@@ -10052,6 +10069,17 @@ var WorkflowsMySQL = class _WorkflowsMySQL extends storage.WorkflowsStorage {
10052
10069
  const updatedAtValue = updatedAt ?? now;
10053
10070
  try {
10054
10071
  const tableName = formatTableName(storage.TABLE_WORKFLOW_SNAPSHOT);
10072
+ const [updateResult] = await this.pool.execute(
10073
+ `UPDATE ${tableName}
10074
+ SET ${quoteIdentifier("resourceId", "column name")} = ?,
10075
+ ${quoteIdentifier("snapshot", "column name")} = ?,
10076
+ ${quoteIdentifier("updatedAt", "column name")} = ?
10077
+ WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} = ?`,
10078
+ [resourceId ?? null, JSON.stringify(snapshot), transformToSqlValue(updatedAtValue), workflowName, runId]
10079
+ );
10080
+ if (updateResult.affectedRows > 0) {
10081
+ return;
10082
+ }
10055
10083
  await this.pool.execute(
10056
10084
  `INSERT INTO ${tableName} (${quoteIdentifier("workflow_name", "column name")}, ${quoteIdentifier("run_id", "column name")}, ${quoteIdentifier("resourceId", "column name")}, ${quoteIdentifier("snapshot", "column name")}, ${quoteIdentifier("createdAt", "column name")}, ${quoteIdentifier("updatedAt", "column name")})
10057
10085
  VALUES (?, ?, ?, ?, ?, ?)