SPB Git

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%
2.7 KB · 94 lines typescript
Raw Blame History
1/*2 * =============================================================================3 *  VibeQuant (vquant) — AI-Powered Financial Intelligence Platform4 * -----------------------------------------------------------------------------5 *  File:      server/migrate-sqlite.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 path from 'path';1920const dbPath = path.join(process.cwd(), 'local.db');21const db = new Database(dbPath);2223console.log(`Initializing SQLite database at: ${dbPath}`);2425// Create tables26db.exec(`27  CREATE TABLE IF NOT EXISTS users (28    id TEXT PRIMARY KEY,29    display_name TEXT NOT NULL,30    token TEXT NOT NULL UNIQUE,31    created_at INTEGER NOT NULL32  );3334  CREATE TABLE IF NOT EXISTS crawled_pages (35    id TEXT PRIMARY KEY,36    url TEXT NOT NULL UNIQUE,37    title TEXT NOT NULL,38    content TEXT NOT NULL,39    snippet TEXT,40    favicon TEXT,41    crawled_at INTEGER NOT NULL42  );4344  CREATE TABLE IF NOT EXISTS embeddings (45    id TEXT PRIMARY KEY,46    page_id TEXT NOT NULL UNIQUE,47    embedding TEXT,48    token_count INTEGER NOT NULL,49    created_at INTEGER NOT NULL,50    FOREIGN KEY (page_id) REFERENCES crawled_pages(id) ON DELETE CASCADE51  );5253  CREATE TABLE IF NOT EXISTS messages (54    id TEXT PRIMARY KEY,55    session_id TEXT NOT NULL,56    role TEXT NOT NULL,57    content TEXT NOT NULL,58    sources TEXT,59    created_at INTEGER NOT NULL60  );6162  CREATE TABLE IF NOT EXISTS shared_reports (63    id TEXT PRIMARY KEY,64    share_id TEXT NOT NULL UNIQUE,65    question TEXT NOT NULL,66    answer TEXT NOT NULL,67    tool_results TEXT,68    sources TEXT,69    custom_python_figures TEXT,70    created_at INTEGER NOT NULL71  );7273  CREATE TABLE IF NOT EXISTS conversation_sessions (74    id TEXT PRIMARY KEY,75    session_id TEXT NOT NULL UNIQUE,76    user_id TEXT,77    title TEXT NOT NULL,78    messages TEXT NOT NULL,79    input_tokens INTEGER DEFAULT 0,80    output_tokens INTEGER DEFAULT 0,81    total_cost REAL DEFAULT 0,82    created_at INTEGER NOT NULL,83    updated_at INTEGER NOT NULL,84    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE85  );8687  CREATE INDEX IF NOT EXISTS idx_messages_session_id ON messages(session_id);88  CREATE INDEX IF NOT EXISTS idx_conversation_sessions_user_id ON conversation_sessions(user_id);89  CREATE INDEX IF NOT EXISTS idx_conversation_sessions_session_id ON conversation_sessions(session_id);90`);9192console.log('Database tables created successfully!');93db.close();94