@mastra/duckdb 1.4.0-alpha.0 → 1.4.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.
@@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS span_events (
28
28
  -- Event metadata
29
29
  eventType VARCHAR NOT NULL,
30
30
  timestamp TIMESTAMP NOT NULL,
31
- cursorId BIGINT DEFAULT nextval('span_events_cursor_id_seq'),
31
+ cursorId BIGINT,
32
32
 
33
33
  -- IDs
34
34
  traceId VARCHAR NOT NULL,
@@ -75,7 +75,7 @@ var METRIC_EVENTS_DDL = `
75
75
  CREATE TABLE IF NOT EXISTS metric_events (
76
76
  -- Event metadata
77
77
  timestamp TIMESTAMP NOT NULL,
78
- cursorId BIGINT DEFAULT nextval('metric_events_cursor_id_seq'),
78
+ cursorId BIGINT,
79
79
 
80
80
  -- IDs
81
81
  metricId VARCHAR NOT NULL PRIMARY KEY,
@@ -128,7 +128,7 @@ var LOG_EVENTS_DDL = `
128
128
  CREATE TABLE IF NOT EXISTS log_events (
129
129
  -- Event metadata
130
130
  timestamp TIMESTAMP NOT NULL,
131
- cursorId BIGINT DEFAULT nextval('log_events_cursor_id_seq'),
131
+ cursorId BIGINT,
132
132
 
133
133
  -- IDs
134
134
  logId VARCHAR NOT NULL PRIMARY KEY,
@@ -176,7 +176,7 @@ var SCORE_EVENTS_DDL = `
176
176
  CREATE TABLE IF NOT EXISTS score_events (
177
177
  -- Event metadata
178
178
  timestamp TIMESTAMP NOT NULL,
179
- cursorId BIGINT DEFAULT nextval('score_events_cursor_id_seq'),
179
+ cursorId BIGINT,
180
180
 
181
181
  -- IDs
182
182
  scoreId VARCHAR NOT NULL PRIMARY KEY,
@@ -228,7 +228,7 @@ var FEEDBACK_EVENTS_DDL = `
228
228
  CREATE TABLE IF NOT EXISTS feedback_events (
229
229
  -- Event metadata
230
230
  timestamp TIMESTAMP NOT NULL,
231
- cursorId BIGINT DEFAULT nextval('feedback_events_cursor_id_seq'),
231
+ cursorId BIGINT,
232
232
 
233
233
  -- IDs
234
234
  feedbackId VARCHAR NOT NULL PRIMARY KEY,
@@ -295,14 +295,16 @@ var ALL_MIGRATIONS = [
295
295
  `CREATE SEQUENCE IF NOT EXISTS log_events_cursor_id_seq START 1`,
296
296
  `CREATE SEQUENCE IF NOT EXISTS score_events_cursor_id_seq START 1`,
297
297
  `CREATE SEQUENCE IF NOT EXISTS feedback_events_cursor_id_seq START 1`,
298
- // Span events. Existing rows intentionally keep NULL cursorId values; delta
299
- // polling only applies to rows written after this migration path is in place.
298
+ // Existing rows intentionally keep NULL cursorId values; delta polling only
299
+ // applies to rows written by insert paths that explicitly call nextval().
300
+ // Databases upgraded from a prior version may still carry a
301
+ // `DEFAULT nextval(...)` on cursorId, which breaks DuckDB WAL replay; that
302
+ // remediation lives in `dropLegacyCursorIdDefaults` and only runs when the
303
+ // bad default is detected in information_schema.
300
304
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS cursorId BIGINT`,
301
- `ALTER TABLE span_events ALTER COLUMN cursorId SET DEFAULT nextval('span_events_cursor_id_seq')`,
302
305
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS entityVersionId VARCHAR`,
303
306
  // Metrics. Legacy rows remain page-visible but are not part of delta polling.
304
307
  `ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS cursorId BIGINT`,
305
- `ALTER TABLE metric_events ALTER COLUMN cursorId SET DEFAULT nextval('metric_events_cursor_id_seq')`,
306
308
  `ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS entityVersionId VARCHAR`,
307
309
  `ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS parentEntityVersionId VARCHAR`,
308
310
  `ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS rootEntityVersionId VARCHAR`,
@@ -328,7 +330,6 @@ var ALL_MIGRATIONS = [
328
330
  `ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS scope JSON`,
329
331
  // Logs. Legacy rows remain page-visible but are not part of delta polling.
330
332
  `ALTER TABLE log_events ADD COLUMN IF NOT EXISTS cursorId BIGINT`,
331
- `ALTER TABLE log_events ALTER COLUMN cursorId SET DEFAULT nextval('log_events_cursor_id_seq')`,
332
333
  `ALTER TABLE log_events ADD COLUMN IF NOT EXISTS entityVersionId VARCHAR`,
333
334
  `ALTER TABLE log_events ADD COLUMN IF NOT EXISTS parentEntityVersionId VARCHAR`,
334
335
  `ALTER TABLE log_events ADD COLUMN IF NOT EXISTS rootEntityVersionId VARCHAR`,
@@ -354,7 +355,6 @@ var ALL_MIGRATIONS = [
354
355
  `ALTER TABLE log_events ADD COLUMN IF NOT EXISTS scope JSON`,
355
356
  // Scores. Legacy rows remain page-visible but are not part of delta polling.
356
357
  `ALTER TABLE score_events ADD COLUMN IF NOT EXISTS cursorId BIGINT`,
357
- `ALTER TABLE score_events ALTER COLUMN cursorId SET DEFAULT nextval('score_events_cursor_id_seq')`,
358
358
  `ALTER TABLE score_events ADD COLUMN IF NOT EXISTS entityVersionId VARCHAR`,
359
359
  `ALTER TABLE score_events ADD COLUMN IF NOT EXISTS parentEntityVersionId VARCHAR`,
360
360
  `ALTER TABLE score_events ADD COLUMN IF NOT EXISTS rootEntityVersionId VARCHAR`,
@@ -384,7 +384,6 @@ var ALL_MIGRATIONS = [
384
384
  `ALTER TABLE score_events ALTER COLUMN traceId DROP NOT NULL`,
385
385
  // Feedback. Legacy rows remain page-visible but are not part of delta polling.
386
386
  `ALTER TABLE feedback_events ADD COLUMN IF NOT EXISTS cursorId BIGINT`,
387
- `ALTER TABLE feedback_events ALTER COLUMN cursorId SET DEFAULT nextval('feedback_events_cursor_id_seq')`,
388
387
  `ALTER TABLE feedback_events ADD COLUMN IF NOT EXISTS entityVersionId VARCHAR`,
389
388
  `ALTER TABLE feedback_events ADD COLUMN IF NOT EXISTS parentEntityVersionId VARCHAR`,
390
389
  `ALTER TABLE feedback_events ADD COLUMN IF NOT EXISTS rootEntityVersionId VARCHAR`,
@@ -883,7 +882,7 @@ async function createFeedback(db, args) {
883
882
  const feedbackUserId = f.feedbackUserId ?? f.userId ?? null;
884
883
  await db.execute(
885
884
  `INSERT INTO feedback_events (
886
- feedbackId, timestamp, traceId, spanId, experimentId,
885
+ feedbackId, timestamp, cursorId, traceId, spanId, experimentId,
887
886
  entityType, entityId, entityName, entityVersionId, parentEntityVersionId, parentEntityType, parentEntityId, parentEntityName, rootEntityVersionId, rootEntityType, rootEntityId, rootEntityName,
888
887
  userId, organizationId, resourceId, runId, sessionId, threadId, requestId, environment, executionSource, serviceName,
889
888
  feedbackUserId, sourceId, feedbackSource, feedbackType, value, comment, tags, metadata, scope
@@ -891,6 +890,7 @@ async function createFeedback(db, args) {
891
890
  VALUES (${[
892
891
  v(f.feedbackId),
893
892
  v(f.timestamp),
893
+ "nextval('feedback_events_cursor_id_seq')",
894
894
  v(f.traceId),
895
895
  v(f.spanId ?? null),
896
896
  v(f.experimentId ?? null),
@@ -938,6 +938,7 @@ async function batchCreateFeedback(db, args) {
938
938
  return `(${[
939
939
  v(legacyFeedback.feedbackId),
940
940
  v(legacyFeedback.timestamp),
941
+ "nextval('feedback_events_cursor_id_seq')",
941
942
  v(legacyFeedback.traceId),
942
943
  v(legacyFeedback.spanId ?? null),
943
944
  v(legacyFeedback.experimentId ?? null),
@@ -976,7 +977,7 @@ async function batchCreateFeedback(db, args) {
976
977
  });
977
978
  await db.execute(
978
979
  `INSERT INTO feedback_events (
979
- feedbackId, timestamp, traceId, spanId, experimentId,
980
+ feedbackId, timestamp, cursorId, traceId, spanId, experimentId,
980
981
  entityType, entityId, entityName, entityVersionId, parentEntityVersionId, parentEntityType, parentEntityId, parentEntityName, rootEntityVersionId, rootEntityType, rootEntityId, rootEntityName,
981
982
  userId, organizationId, resourceId, runId, sessionId, threadId, requestId, environment, executionSource, serviceName,
982
983
  feedbackUserId, sourceId, feedbackSource, feedbackType, value, comment, tags, metadata, scope
@@ -1182,6 +1183,7 @@ async function getFeedbackPercentiles(db, args) {
1182
1183
  var COLUMNS = [
1183
1184
  "logId",
1184
1185
  "timestamp",
1186
+ "cursorId",
1185
1187
  "level",
1186
1188
  "message",
1187
1189
  "data",
@@ -1258,6 +1260,7 @@ async function batchCreateLogs(db, args) {
1258
1260
  return `(${[
1259
1261
  v(log.logId),
1260
1262
  v(log.timestamp),
1263
+ "nextval('log_events_cursor_id_seq')",
1261
1264
  v(log.level),
1262
1265
  v(log.message),
1263
1266
  jsonV(log.data),
@@ -1416,6 +1419,7 @@ function buildMetricNameFilter(name) {
1416
1419
  var METRIC_COLUMNS = [
1417
1420
  "metricId",
1418
1421
  "timestamp",
1422
+ "cursorId",
1419
1423
  "name",
1420
1424
  "value",
1421
1425
  "traceId",
@@ -1564,6 +1568,7 @@ async function batchCreateMetrics(db, args) {
1564
1568
  return `(${[
1565
1569
  v(m.metricId),
1566
1570
  v(m.timestamp),
1571
+ "nextval('metric_events_cursor_id_seq')",
1567
1572
  v(m.name),
1568
1573
  v(m.value),
1569
1574
  v(m.traceId ?? null),
@@ -1950,6 +1955,17 @@ async function getMetricLabelValues(db, args) {
1950
1955
  );
1951
1956
  return { values: rows.map((r) => r.val) };
1952
1957
  }
1958
+ var CURSOR_ID_TABLES = ["span_events", "metric_events", "log_events", "score_events", "feedback_events"];
1959
+ async function dropLegacyCursorIdDefaults(db) {
1960
+ const rows = await db.query(
1961
+ `SELECT table_name FROM information_schema.columns
1962
+ WHERE column_name = 'cursorId'
1963
+ AND column_default IS NOT NULL
1964
+ AND table_name IN (${CURSOR_ID_TABLES.map((t) => `'${t}'`).join(", ")})`
1965
+ );
1966
+ if (rows.length === 0) return;
1967
+ await db.executeBatch(rows.map((row) => `ALTER TABLE ${row.table_name} ALTER COLUMN cursorId DROP DEFAULT`));
1968
+ }
1953
1969
  var SIGNAL_MIGRATIONS = [
1954
1970
  {
1955
1971
  table: "metric_events",
@@ -2273,7 +2289,7 @@ async function createScore(db, args) {
2273
2289
  const scoreSource = s.scoreSource ?? s.source ?? null;
2274
2290
  await db.execute(
2275
2291
  `INSERT INTO score_events (
2276
- scoreId, timestamp, traceId, spanId, experimentId, scoreTraceId,
2292
+ scoreId, timestamp, cursorId, traceId, spanId, experimentId, scoreTraceId,
2277
2293
  entityType, entityId, entityName, entityVersionId, parentEntityVersionId, parentEntityType, parentEntityId, parentEntityName, rootEntityVersionId, rootEntityType, rootEntityId, rootEntityName,
2278
2294
  userId, organizationId, resourceId, runId, sessionId, threadId, requestId, environment, executionSource, serviceName,
2279
2295
  scorerId, scorerVersion, scoreSource, score, reason, tags, metadata, scope
@@ -2281,6 +2297,7 @@ async function createScore(db, args) {
2281
2297
  VALUES (${[
2282
2298
  v(s.scoreId),
2283
2299
  v(s.timestamp),
2300
+ "nextval('score_events_cursor_id_seq')",
2284
2301
  v(s.traceId),
2285
2302
  v(s.spanId ?? null),
2286
2303
  v(s.experimentId ?? null),
@@ -2327,6 +2344,7 @@ async function batchCreateScores(db, args) {
2327
2344
  return `(${[
2328
2345
  v(legacyScore.scoreId),
2329
2346
  v(legacyScore.timestamp),
2347
+ "nextval('score_events_cursor_id_seq')",
2330
2348
  v(legacyScore.traceId),
2331
2349
  v(legacyScore.spanId ?? null),
2332
2350
  v(legacyScore.experimentId ?? null),
@@ -2365,7 +2383,7 @@ async function batchCreateScores(db, args) {
2365
2383
  });
2366
2384
  await db.execute(
2367
2385
  `INSERT INTO score_events (
2368
- scoreId, timestamp, traceId, spanId, experimentId, scoreTraceId,
2386
+ scoreId, timestamp, cursorId, traceId, spanId, experimentId, scoreTraceId,
2369
2387
  entityType, entityId, entityName, entityVersionId, parentEntityVersionId, parentEntityType, parentEntityId, parentEntityName, rootEntityVersionId, rootEntityType, rootEntityId, rootEntityName,
2370
2388
  userId, organizationId, resourceId, runId, sessionId, threadId, requestId, environment, executionSource, serviceName,
2371
2389
  scorerId, scorerVersion, scoreSource, score, reason, tags, metadata, scope
@@ -2573,6 +2591,7 @@ async function getScorePercentiles(db, args) {
2573
2591
  var COLUMNS2 = [
2574
2592
  "eventType",
2575
2593
  "timestamp",
2594
+ "cursorId",
2576
2595
  "traceId",
2577
2596
  "spanId",
2578
2597
  "parentSpanId",
@@ -2805,6 +2824,7 @@ function toValuesTuple(row) {
2805
2824
  return [
2806
2825
  v(row.eventType),
2807
2826
  v(row.timestamp),
2827
+ "nextval('span_events_cursor_id_seq')",
2808
2828
  v(row.traceId),
2809
2829
  v(row.spanId),
2810
2830
  v(row.parentSpanId),
@@ -3605,6 +3625,7 @@ var ObservabilityStorageDuckDB = class extends storage.ObservabilityStorage {
3605
3625
  });
3606
3626
  }
3607
3627
  await this.db.executeBatch([...ALL_DDL, ...ALL_MIGRATIONS]);
3628
+ await dropLegacyCursorIdDefaults(this.db);
3608
3629
  }
3609
3630
  /**
3610
3631
  * Manually migrate legacy signal tables to the signal-ID primary-key schema.
@@ -3783,5 +3804,5 @@ var ObservabilityStorageDuckDB = class extends storage.ObservabilityStorage {
3783
3804
  };
3784
3805
 
3785
3806
  exports.ObservabilityStorageDuckDB = ObservabilityStorageDuckDB;
3786
- //# sourceMappingURL=observability-25HVQJC2.cjs.map
3787
- //# sourceMappingURL=observability-25HVQJC2.cjs.map
3807
+ //# sourceMappingURL=observability-V2KYD7UF.cjs.map
3808
+ //# sourceMappingURL=observability-V2KYD7UF.cjs.map