From 14a5243bb2f7ea1a86b2a1b45f760794b84834d9 Mon Sep 17 00:00:00 2001 From: "Sven (AAMOS AI)" Date: Wed, 12 Aug 2026 20:51:50 +0700 Subject: [PATCH] =?UTF-8?q?feat(db):=20gemini=5Fusage-tabell=20f=C3=B6r=20?= =?UTF-8?q?token-telemetri?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0026_smart_mastermind.sql | 9 +++++++++ packages/database/src/schema/gemini-usage.ts | 16 ++++++++++++++++ packages/database/src/schema/index.ts | 1 + 3 files changed, 26 insertions(+) create mode 100644 infrastructure/migrations/0026_smart_mastermind.sql create mode 100644 packages/database/src/schema/gemini-usage.ts diff --git a/infrastructure/migrations/0026_smart_mastermind.sql b/infrastructure/migrations/0026_smart_mastermind.sql new file mode 100644 index 0000000..42f8596 --- /dev/null +++ b/infrastructure/migrations/0026_smart_mastermind.sql @@ -0,0 +1,9 @@ +CREATE TABLE "gemini_usage" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "task_type" text NOT NULL, + "prompt_tokens" integer NOT NULL, + "output_tokens" integer NOT NULL, + "total_tokens" integer NOT NULL, + "cost_microcents" bigint +); diff --git a/packages/database/src/schema/gemini-usage.ts b/packages/database/src/schema/gemini-usage.ts new file mode 100644 index 0000000..b243718 --- /dev/null +++ b/packages/database/src/schema/gemini-usage.ts @@ -0,0 +1,16 @@ +import { bigint, integer, pgTable, text, uuid } from "drizzle-orm/pg-core"; +import { createdAt } from "./_shared.js"; + +/** + * Token-telemetri för Gemini-anrop (spec §EOC): + * Rådata för /ops/v1/summary och framtida kostnadsuppföljning. + */ +export const geminiUsage = pgTable("gemini_usage", { + id: uuid("id").primaryKey().defaultRandom(), + createdAt: createdAt(), + taskType: text("task_type").notNull(), + promptTokens: integer("prompt_tokens").notNull(), + outputTokens: integer("output_tokens").notNull(), + totalTokens: integer("total_tokens").notNull(), + costMicrocents: bigint("cost_microcents", { mode: "number" }), +}); diff --git a/packages/database/src/schema/index.ts b/packages/database/src/schema/index.ts index bd8ada5..daf12f0 100644 --- a/packages/database/src/schema/index.ts +++ b/packages/database/src/schema/index.ts @@ -22,3 +22,4 @@ export * from "./feedback.js"; export * from "./ops.js"; export * from "./platform.js"; export * from "./releaseGates.js"; +export * from "./gemini-usage.js";