MCPcopy
hub / github.com/phuryn/claude-usage / init_db

Function init_db

scanner.py:50–131  ·  view source on GitHub ↗
(conn)

Source from the content-addressed store, hash-verified

48
49
50def init_db(conn):
51 conn.executescript("""
52 CREATE TABLE IF NOT EXISTS sessions (
53 session_id TEXT PRIMARY KEY,
54 project_name TEXT,
55 first_timestamp TEXT,
56 last_timestamp TEXT,
57 git_branch TEXT,
58 total_input_tokens INTEGER DEFAULT 0,
59 total_output_tokens INTEGER DEFAULT 0,
60 total_cache_read INTEGER DEFAULT 0,
61 total_cache_creation INTEGER DEFAULT 0,
62 model TEXT,
63 turn_count INTEGER DEFAULT 0,
64 topic TEXT
65 );
66
67 CREATE TABLE IF NOT EXISTS turns (
68 id INTEGER PRIMARY KEY AUTOINCREMENT,
69 session_id TEXT,
70 timestamp TEXT,
71 model TEXT,
72 input_tokens INTEGER DEFAULT 0,
73 output_tokens INTEGER DEFAULT 0,
74 cache_read_tokens INTEGER DEFAULT 0,
75 cache_creation_tokens INTEGER DEFAULT 0,
76 tool_name TEXT,
77 cwd TEXT,
78 message_id TEXT,
79 is_subagent INTEGER DEFAULT 0,
80 agent_id TEXT
81 );
82
83 CREATE TABLE IF NOT EXISTS processed_files (
84 path TEXT PRIMARY KEY,
85 mtime REAL,
86 lines INTEGER
87 );
88
89 CREATE TABLE IF NOT EXISTS agents (
90 agent_id TEXT PRIMARY KEY,
91 agent_type TEXT,
92 dispatched_in_session TEXT,
93 completed_at TEXT,
94 status TEXT,
95 total_tokens INTEGER,
96 total_duration_ms INTEGER,
97 tool_use_count INTEGER
98 );
99
100 CREATE TABLE IF NOT EXISTS schema_meta (
101 key TEXT PRIMARY KEY,
102 value TEXT
103 );
104
105 CREATE INDEX IF NOT EXISTS idx_turns_session ON turns(session_id);
106 CREATE INDEX IF NOT EXISTS idx_turns_timestamp ON turns(timestamp);
107 CREATE INDEX IF NOT EXISTS idx_sessions_first ON sessions(first_timestamp);

Callers 13

get_dashboard_dataFunction · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90

Calls 1

_ensure_columnFunction · 0.85

Tested by 11

setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72