@mastra/mysql 0.5.0 → 0.6.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 CHANGED
@@ -1,5 +1,69 @@
1
1
  # @mastra/mysql
2
2
 
3
+ ## 0.6.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - Stored workflow definitions now persist across restarts on every major database backend. ([#20471](https://github.com/mastra-ai/mastra/pull/20471))
8
+
9
+ Implement the `workflowDefinitions` storage domain for libsql, pg, mysql, mssql, mongodb, and spanner. Previously the stored-workflow persistence path (`POST /stored/workflows`, `Mastra.addStoredWorkflow`) only worked against `@mastra/core`'s in-memory store. Persistent adapters returned `undefined` from `storage.getStore('workflowDefinitions')` and threw when the HTTP handler tried to read/write a workflow.
10
+
11
+ ```ts
12
+ const workflowDefinitions = await storage.getStore('workflowDefinitions');
13
+ if (!workflowDefinitions) {
14
+ throw new Error('This storage adapter does not support the workflowDefinitions domain');
15
+ }
16
+
17
+ await workflowDefinitions.upsert({
18
+ id: 'greeting-workflow',
19
+ inputSchema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
20
+ outputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
21
+ graph: [{ type: 'agent', id: 'greet', agentId: 'greeter-agent' }],
22
+ });
23
+
24
+ const { definitions, total } = await workflowDefinitions.list({ status: 'active' });
25
+ const definition = await workflowDefinitions.get('greeting-workflow');
26
+ await workflowDefinitions.delete('greeting-workflow');
27
+ ```
28
+
29
+ Each adapter now ships a `WorkflowDefinitions*` domain that:
30
+
31
+ - Creates the shared `mastra_workflow_definitions` table (or Mongo collection) from `WORKFLOW_DEFINITIONS_SCHEMA` during `init()`, plus a default index on `status`.
32
+ - Implements `upsert` / `get` / `list` / `delete` matching `WorkflowDefinitionsStorage` semantics (`list` supports `status` and `authorId` filters and orders by `updatedAt` desc). Partial upserts preserve unspecified fields, including `authorId` updates and `createdAt` / `updatedAt` semantics.
33
+ - Handles concurrent first-writes race-safely: if two callers upsert the same new id simultaneously, the losing insert detects the duplicate key, re-reads the row, and applies the partial-update path instead of failing.
34
+ - Round-trips the JSON columns (`inputSchema`, `outputSchema`, `stateSchema`, `requestContextSchema`, `metadata`, `graph`) through each adapter's JSON handling, so declarative workflow graphs rehydrate identically no matter which backend they were stored in. Malformed persisted JSON surfaces as an actionable error naming the row and column instead of hydrating raw strings.
35
+
36
+ Exported class names by adapter: `WorkflowDefinitionsLibSQL`, `WorkflowDefinitionsPG`, `WorkflowDefinitionsMySQL`, `WorkflowDefinitionsMSSQL`, `MongoDBWorkflowDefinitionsStore`, `WorkflowDefinitionsSpanner`. The composite stores (`LibSQLStore`, `PostgresStore`, `MySQLStore`, `MSSQLStore`, `MongoDBStore`, `SpannerStore`) auto-wire the new domain, so callers do not need to construct it manually — `storage.getStore('workflowDefinitions')` now returns a live handle.
37
+
38
+ The pg adapter reads `createdAt` / `updatedAt` from the auto-added `createdAtZ` / `updatedAtZ` `timestamptz` companion columns to avoid the naive-timestamp / local-TZ drift that a plain `TIMESTAMP` read exhibits under node-pg.
39
+
40
+ `@mastra/clickhouse` and `@mastra/cloudflare` register the new `mastra_workflow_definitions` table in their table/type maps so shared table constants stay exhaustive (no workflow-definitions domain implementation yet).
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [[`4844167`](https://github.com/mastra-ai/mastra/commit/4844167cff2d5ec5004e94edd34970833040fa3f), [`5faf93f`](https://github.com/mastra-ai/mastra/commit/5faf93f03e19daea394b9e2a923f2e4f833407f2), [`80ad891`](https://github.com/mastra-ai/mastra/commit/80ad891f8cd10379aa5b5af7510c763783b2ab56), [`a1cb98d`](https://github.com/mastra-ai/mastra/commit/a1cb98d11990b560b98482292a1f34aa1a2d9092), [`598ad82`](https://github.com/mastra-ai/mastra/commit/598ad82d41c41389a686338a1d0e50b7400e1938), [`1fd6aad`](https://github.com/mastra-ai/mastra/commit/1fd6aad1ea4a9d32f65efa832307c35e981a4c0a)]:
45
+ - @mastra/core@1.56.0-alpha.4
46
+
47
+ ## 0.6.0-alpha.0
48
+
49
+ ### Minor Changes
50
+
51
+ - Added persistence for dataset item undeclared tool policies. ([#19643](https://github.com/mastra-ai/mastra/pull/19643))
52
+
53
+ ```typescript
54
+ await dataset.addItem({
55
+ input: 'What is the weather?',
56
+ unmockedToolPolicy: 'deny',
57
+ });
58
+ ```
59
+
60
+ ### Patch Changes
61
+
62
+ - Added a comment column to experiment results so review comments persist. The column is added automatically and non-destructively on startup for existing databases (https://github.com/mastra-ai/mastra/issues/19857). ([#19865](https://github.com/mastra-ai/mastra/pull/19865))
63
+
64
+ - Updated dependencies [[`c5e56ff`](https://github.com/mastra-ai/mastra/commit/c5e56ff3bcabdf062708f2d48744fec304df6792), [`4e35a56`](https://github.com/mastra-ai/mastra/commit/4e35a56cdf8d74a5ff6d5eda01f2c1deaf6cc7be)]:
65
+ - @mastra/core@1.56.0-alpha.1
66
+
3
67
  ## 0.5.0
4
68
 
5
69
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1907,6 +1907,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
1907
1907
  "source",
1908
1908
  "expectedTrajectory",
1909
1909
  "toolMocks",
1910
+ "unmockedToolPolicy",
1910
1911
  "externalId"
1911
1912
  ]
1912
1913
  });
@@ -1962,6 +1963,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
1962
1963
  groundTruth: row.groundTruth ? parseJSON$3(row.groundTruth) : void 0,
1963
1964
  expectedTrajectory: row.expectedTrajectory ? parseJSON$3(row.expectedTrajectory) : void 0,
1964
1965
  toolMocks: row.toolMocks ? parseJSON$3(row.toolMocks) : void 0,
1966
+ unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
1965
1967
  requestContext: row.requestContext ? parseJSON$3(row.requestContext) : void 0,
1966
1968
  metadata: row.metadata ? parseJSON$3(row.metadata) : void 0,
1967
1969
  source: row.source ? parseJSON$3(row.source) : void 0,
@@ -1983,6 +1985,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
1983
1985
  groundTruth: row.groundTruth ? parseJSON$3(row.groundTruth) : void 0,
1984
1986
  expectedTrajectory: row.expectedTrajectory ? parseJSON$3(row.expectedTrajectory) : void 0,
1985
1987
  toolMocks: row.toolMocks ? parseJSON$3(row.toolMocks) : void 0,
1988
+ unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
1986
1989
  requestContext: row.requestContext ? parseJSON$3(row.requestContext) : void 0,
1987
1990
  metadata: row.metadata ? parseJSON$3(row.metadata) : void 0,
1988
1991
  source: row.source ? parseJSON$3(row.source) : void 0,
@@ -2264,7 +2267,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2264
2267
  const newVersion = parentRow?.version;
2265
2268
  const parentOrganizationId = parentRow?.organizationId ?? null;
2266
2269
  const parentProjectId = parentRow?.projectId ?? null;
2267
- await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`, [
2270
+ await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`unmockedToolPolicy\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?, ?)`, [
2268
2271
  id,
2269
2272
  args.datasetId,
2270
2273
  newVersion,
@@ -2272,6 +2275,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2272
2275
  parentProjectId,
2273
2276
  jsonArg(args.input),
2274
2277
  jsonArg(args.groundTruth),
2278
+ args.unmockedToolPolicy ?? null,
2275
2279
  jsonArg(args.metadata),
2276
2280
  transformToSqlValue(now),
2277
2281
  transformToSqlValue(now)
@@ -2291,6 +2295,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2291
2295
  projectId: parentProjectId,
2292
2296
  input: args.input,
2293
2297
  groundTruth: args.groundTruth,
2298
+ unmockedToolPolicy: args.unmockedToolPolicy,
2294
2299
  metadata: args.metadata,
2295
2300
  createdAt: now,
2296
2301
  updatedAt: now
@@ -2338,6 +2343,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2338
2343
  const mergedGroundTruth = args.groundTruth ?? existing.groundTruth;
2339
2344
  const mergedExpectedTrajectory = args.expectedTrajectory ?? existing.expectedTrajectory;
2340
2345
  const mergedToolMocks = args.toolMocks ?? existing.toolMocks;
2346
+ const mergedUnmockedToolPolicy = args.unmockedToolPolicy ?? existing.unmockedToolPolicy;
2341
2347
  const mergedRequestContext = args.requestContext ?? existing.requestContext;
2342
2348
  const mergedMetadata = args.metadata ?? existing.metadata;
2343
2349
  const mergedSource = args.source ?? existing.source;
@@ -2348,7 +2354,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2348
2354
  const parentOrganizationId = parentRow?.organizationId ?? null;
2349
2355
  const parentProjectId = parentRow?.projectId ?? null;
2350
2356
  await connection.execute(`UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [newVersion, args.id]);
2351
- await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2357
+ await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`unmockedToolPolicy\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2352
2358
  args.id,
2353
2359
  args.datasetId,
2354
2360
  newVersion,
@@ -2359,6 +2365,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2359
2365
  jsonArg(mergedGroundTruth),
2360
2366
  jsonArg(mergedExpectedTrajectory),
2361
2367
  jsonArg(mergedToolMocks),
2368
+ mergedUnmockedToolPolicy ?? null,
2362
2369
  jsonArg(mergedRequestContext),
2363
2370
  jsonArg(mergedMetadata),
2364
2371
  jsonArg(mergedSource),
@@ -2381,6 +2388,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2381
2388
  groundTruth: mergedGroundTruth,
2382
2389
  expectedTrajectory: mergedExpectedTrajectory,
2383
2390
  toolMocks: mergedToolMocks,
2391
+ unmockedToolPolicy: mergedUnmockedToolPolicy,
2384
2392
  requestContext: mergedRequestContext,
2385
2393
  metadata: mergedMetadata,
2386
2394
  source: mergedSource,
@@ -2426,7 +2434,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2426
2434
  const parentOrganizationId = parentRow?.organizationId ?? null;
2427
2435
  const parentProjectId = parentRow?.projectId ?? null;
2428
2436
  await connection.execute(`UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [newVersion, id]);
2429
- await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2437
+ await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`unmockedToolPolicy\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2430
2438
  id,
2431
2439
  datasetId,
2432
2440
  newVersion,
@@ -2437,6 +2445,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2437
2445
  jsonArg(existing.groundTruth),
2438
2446
  jsonArg(existing.expectedTrajectory),
2439
2447
  jsonArg(existing.toolMocks),
2448
+ existing.unmockedToolPolicy ?? null,
2440
2449
  jsonArg(existing.requestContext),
2441
2450
  jsonArg(existing.metadata),
2442
2451
  jsonArg(existing.source),
@@ -2675,7 +2684,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2675
2684
  await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = ? WHERE id = ?`, [newVersion, input.datasetId]);
2676
2685
  const inserted = /* @__PURE__ */ new Map();
2677
2686
  for (const { id, item } of plan.inserts) {
2678
- await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2687
+ await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`unmockedToolPolicy\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2679
2688
  id,
2680
2689
  input.datasetId,
2681
2690
  newVersion,
@@ -2686,6 +2695,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2686
2695
  jsonArg(item.groundTruth),
2687
2696
  jsonArg(item.expectedTrajectory),
2688
2697
  jsonArg(item.toolMocks),
2698
+ item.unmockedToolPolicy ?? null,
2689
2699
  jsonArg(item.requestContext),
2690
2700
  jsonArg(item.metadata),
2691
2701
  jsonArg(item.source),
@@ -2753,7 +2763,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2753
2763
  const parentProjectId = dataset.projectId ?? null;
2754
2764
  for (const item of currentItems) {
2755
2765
  await connection.execute(`UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [newVersion, item.id]);
2756
- await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2766
+ await connection.execute(`INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`externalId\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`expectedTrajectory\`, \`toolMocks\`, \`unmockedToolPolicy\`, \`requestContext\`, \`metadata\`, \`source\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, ?, NULL, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
2757
2767
  item.id,
2758
2768
  input.datasetId,
2759
2769
  newVersion,
@@ -2764,6 +2774,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2764
2774
  jsonArg(item.groundTruth),
2765
2775
  jsonArg(item.expectedTrajectory),
2766
2776
  jsonArg(item.toolMocks),
2777
+ item.unmockedToolPolicy ?? null,
2767
2778
  jsonArg(item.requestContext),
2768
2779
  jsonArg(item.metadata),
2769
2780
  jsonArg(item.source),
@@ -2886,7 +2897,11 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
2886
2897
  await this.operations.alterTable({
2887
2898
  tableName: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
2888
2899
  schema: _mastra_core_storage.EXPERIMENT_RESULTS_SCHEMA,
2889
- ifNotExists: ["organizationId", "projectId"]
2900
+ ifNotExists: [
2901
+ "comment",
2902
+ "organizationId",
2903
+ "projectId"
2904
+ ]
2890
2905
  });
2891
2906
  await this.createDefaultIndexes();
2892
2907
  await this.createCustomIndexes();
@@ -2937,6 +2952,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
2937
2952
  traceId: row.traceId ?? null,
2938
2953
  status: row.status ?? null,
2939
2954
  tags: row.tags ? parseJSON$2(row.tags) ?? null : null,
2955
+ comment: row.comment ?? null,
2940
2956
  createdAt: parseDateTime(row.createdAt) ?? /* @__PURE__ */ new Date()
2941
2957
  };
2942
2958
  }
@@ -3268,6 +3284,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
3268
3284
  const updateData = {};
3269
3285
  if (input.status !== void 0) updateData.status = input.status;
3270
3286
  if (input.tags !== void 0) updateData.tags = input.tags ? JSON.stringify(input.tags) : null;
3287
+ if (input.comment !== void 0) updateData.comment = input.comment;
3271
3288
  if (Object.keys(updateData).length > 0) await this.operations.update({
3272
3289
  tableName: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
3273
3290
  keys: { id: input.id },
@@ -9160,6 +9177,140 @@ var ToolProviderConnectionsMySQL = class ToolProviderConnectionsMySQL extends _m
9160
9177
  }
9161
9178
  };
9162
9179
  //#endregion
9180
+ //#region src/storage/domains/workflow-definitions/index.ts
9181
+ function rowToDefinition(row) {
9182
+ const transformed = transformFromSqlRow({
9183
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
9184
+ sqlRow: row
9185
+ });
9186
+ const def = {
9187
+ id: String(transformed.id),
9188
+ inputSchema: transformed.inputSchema,
9189
+ outputSchema: transformed.outputSchema,
9190
+ graph: transformed.graph,
9191
+ status: String(transformed.status),
9192
+ source: String(transformed.source),
9193
+ createdAt: transformed.createdAt,
9194
+ updatedAt: transformed.updatedAt
9195
+ };
9196
+ if (transformed.description != null) def.description = String(transformed.description);
9197
+ if (transformed.metadata != null) def.metadata = transformed.metadata;
9198
+ if (transformed.stateSchema != null) def.stateSchema = transformed.stateSchema;
9199
+ if (transformed.requestContextSchema != null) def.requestContextSchema = transformed.requestContextSchema;
9200
+ if (transformed.authorId != null) def.authorId = String(transformed.authorId);
9201
+ return def;
9202
+ }
9203
+ var WorkflowDefinitionsMySQL = class extends _mastra_core_storage.WorkflowDefinitionsStorage {
9204
+ pool;
9205
+ operations;
9206
+ database;
9207
+ static MANAGED_TABLES = [_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS];
9208
+ static getExportDDL() {
9209
+ return [generateTableSQL({
9210
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
9211
+ schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA
9212
+ })];
9213
+ }
9214
+ constructor({ pool, operations, database }) {
9215
+ super();
9216
+ this.pool = pool;
9217
+ this.operations = operations;
9218
+ this.database = database;
9219
+ }
9220
+ async init() {
9221
+ await this.operations.createTable({
9222
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
9223
+ schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA
9224
+ });
9225
+ }
9226
+ async dangerouslyClearAll() {
9227
+ await this.operations.clearTable({ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS });
9228
+ }
9229
+ async upsert(input) {
9230
+ const now = /* @__PURE__ */ new Date();
9231
+ if (!await this.get(input.id)) {
9232
+ if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
9233
+ if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
9234
+ if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
9235
+ const record = {
9236
+ id: input.id,
9237
+ description: input.description ?? null,
9238
+ metadata: input.metadata ?? null,
9239
+ inputSchema: input.inputSchema,
9240
+ outputSchema: input.outputSchema,
9241
+ stateSchema: input.stateSchema ?? null,
9242
+ requestContextSchema: input.requestContextSchema ?? null,
9243
+ graph: input.graph,
9244
+ status: "active",
9245
+ source: "storage",
9246
+ authorId: "authorId" in input ? input.authorId ?? null : null,
9247
+ createdAt: now,
9248
+ updatedAt: now
9249
+ };
9250
+ try {
9251
+ await this.operations.insertOnly({
9252
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
9253
+ record
9254
+ });
9255
+ } catch (error) {
9256
+ if (!await this.get(input.id)) throw error;
9257
+ return this.applyUpdate(input, now);
9258
+ }
9259
+ const created = await this.get(input.id);
9260
+ if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
9261
+ return created;
9262
+ }
9263
+ return this.applyUpdate(input, now);
9264
+ }
9265
+ async applyUpdate(input, now) {
9266
+ const data = { updatedAt: now };
9267
+ if ("description" in input && input.description !== void 0) data.description = input.description;
9268
+ if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
9269
+ if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
9270
+ if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
9271
+ if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
9272
+ if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
9273
+ if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
9274
+ if ("status" in input && input.status !== void 0) data.status = input.status;
9275
+ if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
9276
+ await this.operations.update({
9277
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
9278
+ keys: { id: input.id },
9279
+ data
9280
+ });
9281
+ const updated = await this.get(input.id);
9282
+ if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
9283
+ return updated;
9284
+ }
9285
+ async get(id) {
9286
+ const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
9287
+ if (!rows.length) return null;
9288
+ return rowToDefinition(rows[0]);
9289
+ }
9290
+ async list(args) {
9291
+ const conditions = [];
9292
+ const params = [];
9293
+ if (args?.status) {
9294
+ conditions.push(`${quoteIdentifier("status", "column name")} = ?`);
9295
+ params.push(args.status);
9296
+ }
9297
+ if (args?.authorId !== void 0) {
9298
+ conditions.push(`${quoteIdentifier("authorId", "column name")} = ?`);
9299
+ params.push(args.authorId);
9300
+ }
9301
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
9302
+ const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)}${where} ORDER BY ${quoteIdentifier("updatedAt", "column name")} DESC`, params);
9303
+ const definitions = rows.map((row) => rowToDefinition(row));
9304
+ return {
9305
+ definitions,
9306
+ total: definitions.length
9307
+ };
9308
+ }
9309
+ async delete(id) {
9310
+ await this.pool.execute(`DELETE FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
9311
+ }
9312
+ };
9313
+ //#endregion
9163
9314
  //#region src/storage/domains/workflows/index.ts
9164
9315
  function parseSnapshot(snapshot) {
9165
9316
  if (typeof snapshot === "string") try {
@@ -10240,6 +10391,11 @@ var MySQLStore = class extends _mastra_core_storage.MastraCompositeStore {
10240
10391
  skipDefaultIndexes: config.skipDefaultIndexes,
10241
10392
  indexes: config.indexes
10242
10393
  });
10394
+ const workflowDefinitions = new WorkflowDefinitionsMySQL({
10395
+ pool: this.pool,
10396
+ operations,
10397
+ database
10398
+ });
10243
10399
  this.stores = {
10244
10400
  memory,
10245
10401
  workflows,
@@ -10259,7 +10415,8 @@ var MySQLStore = class extends _mastra_core_storage.MastraCompositeStore {
10259
10415
  channels,
10260
10416
  favorites,
10261
10417
  schedules,
10262
- toolProviderConnections
10418
+ toolProviderConnections,
10419
+ workflowDefinitions
10263
10420
  };
10264
10421
  }
10265
10422
  async init() {