@mastra/pg 1.20.0-alpha.4 → 1.20.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/dist/index.cjs CHANGED
@@ -19382,33 +19382,47 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
19382
19382
  updatedAt: new Date(row.updatedAtZ || row.updatedAt)
19383
19383
  };
19384
19384
  }
19385
+ static getDefaultIndexDefs(schemaPrefix) {
19386
+ return [{
19387
+ name: `${schemaPrefix}mastra_workflow_snapshot_name_createdat_idx`,
19388
+ table: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
19389
+ columns: ["workflow_name", "createdAt DESC"]
19390
+ }];
19391
+ }
19385
19392
  /**
19386
19393
  * Returns all DDL statements for this domain: table with unique constraint.
19387
19394
  * Used by exportSchemas to produce a complete, reproducible schema export.
19388
19395
  */
19389
19396
  static getExportDDL(schemaName) {
19390
19397
  const statements = [];
19398
+ const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
19399
+ const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
19391
19400
  statements.push(generateTableSQL({
19392
19401
  tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
19393
19402
  schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT],
19394
19403
  schemaName,
19395
19404
  includeAllConstraints: true
19396
19405
  }));
19406
+ for (const idx of WorkflowsPG.getDefaultIndexDefs(schemaPrefix)) statements.push(generateIndexSQL(idx, schemaName));
19397
19407
  return statements;
19398
19408
  }
19399
19409
  /**
19400
19410
  * Returns default index definitions for the workflows domain tables.
19401
- * Currently no default indexes are defined for workflows.
19402
19411
  */
19403
19412
  getDefaultIndexDefinitions() {
19404
- return [];
19413
+ const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
19414
+ return WorkflowsPG.getDefaultIndexDefs(schemaPrefix);
19405
19415
  }
19406
19416
  /**
19407
19417
  * Creates default indexes for optimal query performance.
19408
- * Currently no default indexes are defined for workflows.
19409
19418
  */
19410
19419
  async createDefaultIndexes() {
19411
19420
  if (this.#skipDefaultIndexes) return;
19421
+ for (const indexDef of this.getDefaultIndexDefinitions()) try {
19422
+ await this.#db.createIndex(indexDef);
19423
+ } catch (error) {
19424
+ this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
19425
+ }
19412
19426
  }
19413
19427
  async init() {
19414
19428
  await this.#db.createTable({