spb/vquant Public MIT
VibeQuant — AI-powered institutional-grade financial intelligence platform.
TypeScript 84.3%
Python 11.7%
JavaScript 1.6%
CSS 1.5%
HTML 0.7%
1/*2 * =============================================================================3 * VibeQuant (vquant) — AI-Powered Financial Intelligence Platform4 * -----------------------------------------------------------------------------5 * File: server/migrate-tokens.ts6 *7 * Author: Simon-Pierre Boucher8 * Contact: contact@spboucher.ai9 * Website: https://www.spboucher.ai10 * Demo: https://www.vquant.ai11 * License: MIT (see LICENSE)12 *13 * Copyright © 2026 Simon-Pierre Boucher. All rights reserved.14 * =============================================================================15 */1617import Database from "better-sqlite3";18import { existsSync } from "fs";19import path from "path";2021/**22 * Migration script to add token tracking and cost columns to conversation_sessions table23 * Run this with: tsx server/migrate-tokens.ts24 */2526const DB_PATH = path.join(process.cwd(), "local.db");2728if (!existsSync(DB_PATH)) {29 console.error("❌ Database file not found at:", DB_PATH);30 process.exit(1);31}3233console.log("🔄 Starting migration to add token tracking columns...");34console.log("📁 Database:", DB_PATH);3536const db = new Database(DB_PATH);3738try {39 // Check if columns already exist40 const tableInfo = db.pragma("table_info(conversation_sessions)");41 const existingColumns = tableInfo.map((col: any) => col.name);4243 console.log("\n📋 Existing columns:", existingColumns.join(", "));4445 const columnsToAdd = [46 { name: "input_tokens", sql: "ALTER TABLE conversation_sessions ADD COLUMN input_tokens INTEGER DEFAULT 0" },47 { name: "output_tokens", sql: "ALTER TABLE conversation_sessions ADD COLUMN output_tokens INTEGER DEFAULT 0" },48 { name: "total_cost", sql: "ALTER TABLE conversation_sessions ADD COLUMN total_cost REAL DEFAULT 0" }49 ];5051 let addedCount = 0;5253 for (const column of columnsToAdd) {54 if (!existingColumns.includes(column.name)) {55 console.log(`\n➕ Adding column: ${column.name}`);56 db.exec(column.sql);57 addedCount++;58 console.log(`✅ Column ${column.name} added successfully`);59 } else {60 console.log(`⏭️ Column ${column.name} already exists, skipping`);61 }62 }6364 console.log("\n✨ Migration completed successfully!");65 console.log(`📊 Added ${addedCount} new column${addedCount !== 1 ? 's' : ''}`);6667 // Show updated table structure68 const updatedTableInfo = db.pragma("table_info(conversation_sessions)");69 console.log("\n📋 Updated table structure:");70 updatedTableInfo.forEach((col: any) => {71 console.log(` - ${col.name}: ${col.type}${col.dflt_value ? ` (default: ${col.dflt_value})` : ''}`);72 });7374} catch (error) {75 console.error("\n❌ Migration failed:", error);76 process.exit(1);77} finally {78 db.close();79}80