link the usage with the session to display together

This commit is contained in:
Owen
2026-08-11 16:14:46 -04:00
parent c42df737b0
commit f7aca85417
9 changed files with 129 additions and 8 deletions
+9 -1
View File
@@ -1831,6 +1831,13 @@ export const aiUsageRecords = pgTable(
userId: varchar("userId").references(() => users.userId, {
onDelete: "set null"
}),
// Links this usage record back to the aiSessionLog row for the same
// request (aiSessionLog.sessionId), so token/cost usage can be shown
// alongside the session transcript. Not a DB-level FK - aiSessionLog
// lives in the separate logs database. Nullable because the session
// log may be disabled (retention set to 0) while usage tracking
// stays on.
sessionId: varchar("sessionId"),
requestedModel: varchar("requestedModel").notNull(),
promptTokens: integer("promptTokens").notNull().default(0),
cacheReadTokens: integer("cacheReadTokens").notNull().default(0),
@@ -1862,7 +1869,8 @@ export const aiUsageRecords = pgTable(
t.orgId,
t.userId,
t.createdAt
)
),
index("idx_ai_usage_records_session").on(t.sessionId)
]
);
+9 -1
View File
@@ -1819,6 +1819,13 @@ export const aiUsageRecords = sqliteTable(
userId: text("userId").references(() => users.userId, {
onDelete: "set null"
}),
// Links this usage record back to the aiSessionLog row for the same
// request (aiSessionLog.sessionId), so token/cost usage can be shown
// alongside the session transcript. Not a DB-level FK - aiSessionLog
// lives in the separate logs database. Nullable because the session
// log may be disabled (retention set to 0) while usage tracking
// stays on.
sessionId: text("sessionId"),
requestedModel: text("requestedModel").notNull(),
promptTokens: integer("promptTokens").notNull().default(0),
cacheReadTokens: integer("cacheReadTokens").notNull().default(0),
@@ -1852,7 +1859,8 @@ export const aiUsageRecords = sqliteTable(
t.orgId,
t.userId,
t.createdAt
)
),
index("idx_ai_usage_records_session").on(t.sessionId)
]
);