CREATE TABLE IF NOT EXISTS migrations (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL UNIQUE,
  applied_at TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS tool_invocations (
  id TEXT PRIMARY KEY,
  ts TEXT NOT NULL DEFAULT (datetime('now')),
  tool_name TEXT NOT NULL,
  action TEXT,
  status TEXT NOT NULL,
  duration_ms INTEGER,
  input_json TEXT,
  output_json TEXT,
  error_text TEXT,
  trace_id TEXT,
  actor TEXT,
  input_meta_json TEXT,
  output_meta_json TEXT
);

CREATE TABLE IF NOT EXISTS mcp_calls (
  id TEXT PRIMARY KEY,
  ts TEXT NOT NULL DEFAULT (datetime('now')),
  server_name TEXT NOT NULL,
  method TEXT NOT NULL,
  tool_name TEXT,
  status TEXT NOT NULL,
  duration_ms INTEGER,
  request_json TEXT,
  response_json TEXT,
  error_text TEXT,
  trace_id TEXT,
  client_id TEXT,
  request_meta_json TEXT,
  response_meta_json TEXT
);

CREATE TABLE IF NOT EXISTS proof_artifacts (
  id TEXT PRIMARY KEY,
  ts TEXT NOT NULL DEFAULT (datetime('now')),
  kind TEXT NOT NULL,
  path TEXT,
  sha256_hex TEXT,
  blake3_hex TEXT,
  size_bytes INTEGER,
  meta_json TEXT,
  trace_id TEXT
);
