@mastra/pg 1.22.3-alpha.0 → 1.22.3-alpha.2

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.
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.22.3-alpha.0"
6
+ version: "1.22.3-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.3-alpha.0",
2
+ "version": "1.22.3-alpha.2",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -818,19 +818,18 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
818
818
  }
819
819
  async ensureNamespaceSchema(indexName, client) {
820
820
  const { tableName, parsedIndexName } = this.getTableName(indexName);
821
- const schemaName = this.schema ? (0, _mastra_core_utils.parseSqlIdentifier)(this.schema, "schema name") : "public";
822
821
  if ((await client.query(`SELECT 1
823
- FROM information_schema.columns
824
- WHERE table_schema = $1 AND table_name = $2 AND column_name = 'vector_id'`, [schemaName, parsedIndexName])).rowCount === 0) return;
822
+ FROM pg_attribute
823
+ WHERE attrelid = to_regclass($1)
824
+ AND attname = 'vector_id'
825
+ AND attnum > 0
826
+ AND NOT attisdropped`, [tableName])).rowCount === 0) return;
825
827
  await client.query(`ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS namespace VARCHAR(255) NOT NULL DEFAULT '${DEFAULT_NAMESPACE}'`);
826
828
  const legacyConstraints = await client.query(`SELECT c.conname
827
829
  FROM pg_constraint c
828
- JOIN pg_class t ON t.oid = c.conrelid
829
- JOIN pg_namespace n ON n.oid = t.relnamespace
830
- WHERE n.nspname = $1
831
- AND t.relname = $2
830
+ WHERE c.conrelid = to_regclass($1)
832
831
  AND c.contype = 'u'
833
- AND pg_get_constraintdef(c.oid) = 'UNIQUE (vector_id)'`, [schemaName, parsedIndexName]);
832
+ AND pg_get_constraintdef(c.oid) = 'UNIQUE (vector_id)'`, [tableName]);
834
833
  for (const { conname } of legacyConstraints.rows) {
835
834
  const parsedConstraintName = (0, _mastra_core_utils.parseSqlIdentifier)(conname, "constraint name");
836
835
  await client.query(`ALTER TABLE ${tableName} DROP CONSTRAINT "${parsedConstraintName}"`);
@@ -1468,7 +1467,9 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
1468
1467
  return (await client.query(`
1469
1468
  SELECT DISTINCT t.table_name
1470
1469
  FROM information_schema.tables t
1471
- WHERE t.table_schema = $1
1470
+ WHERE t.table_schema = ANY(
1471
+ CASE WHEN $1::text IS NULL THEN current_schemas(false) ELSE ARRAY[$1::text] END
1472
+ )
1472
1473
  AND EXISTS (
1473
1474
  SELECT 1
1474
1475
  FROM information_schema.columns c
@@ -1493,7 +1494,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
1493
1494
  AND c.column_name = 'metadata'
1494
1495
  AND c.data_type = 'jsonb'
1495
1496
  );
1496
- `, [this.schema || "public"])).rows.map((row) => row.table_name);
1497
+ `, [this.schema ?? null])).rows.map((row) => row.table_name);
1497
1498
  } catch (e) {
1498
1499
  const mastraError = new _mastra_core_error.MastraError({
1499
1500
  id: (0, _mastra_core_storage.createVectorErrorId)("PG", "LIST_INDEXES", "FAILED"),
@@ -1528,15 +1529,18 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
1528
1529
  async describeIndexMetadata({ indexName }) {
1529
1530
  const client = await this.pool.connect();
1530
1531
  try {
1531
- const { tableName } = this.getTableName(indexName);
1532
+ const { tableName, parsedIndexName } = this.getTableName(indexName);
1532
1533
  const tableExists = await client.query(`
1533
- SELECT udt_name
1534
- FROM information_schema.columns
1535
- WHERE table_schema = $1
1536
- AND table_name = $2
1537
- AND udt_name IN ('vector', 'halfvec', 'bit', 'sparsevec')
1534
+ SELECT t.typname AS udt_name
1535
+ FROM pg_attribute a
1536
+ JOIN pg_type t ON t.oid = a.atttypid
1537
+ WHERE a.attrelid = to_regclass($1)
1538
+ AND a.attname = 'embedding'
1539
+ AND a.attnum > 0
1540
+ AND NOT a.attisdropped
1541
+ AND t.typname IN ('vector', 'halfvec', 'bit', 'sparsevec')
1538
1542
  LIMIT 1;
1539
- `, [this.schema || "public", indexName]);
1543
+ `, [tableName]);
1540
1544
  if (tableExists.rows.length === 0) throw new Error(`Vector table ${tableName} does not exist`);
1541
1545
  const udtName = tableExists.rows[0].udt_name;
1542
1546
  const vectorType = udtName === "halfvec" ? "halfvec" : udtName === "bit" ? "bit" : udtName === "sparsevec" ? "sparsevec" : "vector";
@@ -1555,12 +1559,11 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
1555
1559
  JOIN pg_class c ON i.indexrelid = c.oid
1556
1560
  JOIN pg_am am ON c.relam = am.oid
1557
1561
  JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
1558
- JOIN pg_namespace n ON c.relnamespace = n.oid
1559
1562
  WHERE c.relname = $1
1560
- AND n.nspname = $2;
1563
+ AND i.indrelid = to_regclass($2);
1561
1564
  `;
1562
1565
  const dimResult = await client.query(dimensionQuery, [tableName]);
1563
- const { index_method, index_def, operator_class } = (await client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"])).rows[0] || {
1566
+ const { index_method, index_def, operator_class } = (await client.query(indexQuery, [`${parsedIndexName}_vector_idx`, tableName])).rows[0] || {
1564
1567
  index_method: "flat",
1565
1568
  index_def: "",
1566
1569
  operator_class: "cosine"
@@ -4498,6 +4501,25 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
4498
4501
  }, error);
4499
4502
  }
4500
4503
  }
4504
+ async getVersions(ids) {
4505
+ if (ids.length === 0) return [];
4506
+ try {
4507
+ const tableName = getTableName$5({
4508
+ indexName: _mastra_core_storage.TABLE_AGENT_VERSIONS,
4509
+ schemaName: getSchemaName$5(this.#schema)
4510
+ });
4511
+ const placeholders = ids.map((_, i) => `$${i + 1}`).join(", ");
4512
+ return (await this.#db.client.manyOrNone(`SELECT * FROM ${tableName} WHERE id IN (${placeholders})`, ids)).map((row) => this.parseVersionRow(row));
4513
+ } catch (error) {
4514
+ if (error instanceof _mastra_core_error.MastraError) throw error;
4515
+ throw new _mastra_core_error.MastraError({
4516
+ id: (0, _mastra_core_storage.createStorageErrorId)("PG", "GET_VERSIONS", "FAILED"),
4517
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
4518
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
4519
+ details: { count: ids.length }
4520
+ }, error);
4521
+ }
4522
+ }
4501
4523
  async getVersionByNumber(agentId, versionNumber) {
4502
4524
  try {
4503
4525
  const tableName = getTableName$5({
@@ -20122,6 +20144,25 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
20122
20144
  }, error);
20123
20145
  }
20124
20146
  }
20147
+ async getVersions(ids) {
20148
+ if (ids.length === 0) return [];
20149
+ try {
20150
+ const tableName = getTableName$5({
20151
+ indexName: _mastra_core_storage.TABLE_SKILL_VERSIONS,
20152
+ schemaName: getSchemaName$5(this.#schema)
20153
+ });
20154
+ const placeholders = ids.map((_, i) => `$${i + 1}`).join(", ");
20155
+ return (await this.#db.client.manyOrNone(`SELECT * FROM ${tableName} WHERE id IN (${placeholders})`, ids)).map((row) => this.parseVersionRow(row));
20156
+ } catch (error) {
20157
+ if (error instanceof _mastra_core_error.MastraError) throw error;
20158
+ throw new _mastra_core_error.MastraError({
20159
+ id: (0, _mastra_core_storage.createStorageErrorId)("PG", "GET_SKILL_VERSIONS", "FAILED"),
20160
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
20161
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
20162
+ details: { count: ids.length }
20163
+ }, error);
20164
+ }
20165
+ }
20125
20166
  async getVersionByNumber(skillId, versionNumber) {
20126
20167
  try {
20127
20168
  const tableName = getTableName$5({
@@ -20751,6 +20792,8 @@ function rowToDefinition(row) {
20751
20792
  if (stateSchema !== void 0 && stateSchema !== null) def.stateSchema = stateSchema;
20752
20793
  const requestContextSchema = parseJsonResilient(row.requestContextSchema);
20753
20794
  if (requestContextSchema !== void 0 && requestContextSchema !== null) def.requestContextSchema = requestContextSchema;
20795
+ const schedule = parseJsonResilient(row.schedule);
20796
+ if (schedule !== void 0 && schedule !== null) def.schedule = schedule;
20754
20797
  if (row.authorId != null) def.authorId = String(row.authorId);
20755
20798
  return def;
20756
20799
  }
@@ -20808,6 +20851,11 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends _mastra_core_sto
20808
20851
  tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
20809
20852
  schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS]
20810
20853
  });
20854
+ await this.#db.alterTable({
20855
+ tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
20856
+ schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS],
20857
+ ifNotExists: ["schedule"]
20858
+ });
20811
20859
  await this.createDefaultIndexes();
20812
20860
  await this.createCustomIndexes();
20813
20861
  }
@@ -20829,6 +20877,7 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends _mastra_core_sto
20829
20877
  stateSchema: input.stateSchema ?? null,
20830
20878
  requestContextSchema: input.requestContextSchema ?? null,
20831
20879
  graph: input.graph,
20880
+ schedule: "schedule" in input ? input.schedule ?? null : null,
20832
20881
  status: "active",
20833
20882
  source: "storage",
20834
20883
  authorId: "authorId" in input ? input.authorId ?? null : null,
@@ -20859,6 +20908,7 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends _mastra_core_sto
20859
20908
  if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
20860
20909
  if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
20861
20910
  if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
20911
+ if ("schedule" in input && input.schedule !== void 0) data.schedule = input.schedule;
20862
20912
  if ("status" in input && input.status !== void 0) data.status = input.status;
20863
20913
  if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
20864
20914
  await this.#db.update({