CREATE TABLE captcha_projects (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  site_key TEXT NOT NULL UNIQUE,
  secret_hash TEXT NOT NULL UNIQUE,
  engine_secret TEXT NOT NULL,
  allowed_hostnames_json TEXT NOT NULL DEFAULT '[]',
  monthly_quota INTEGER NOT NULL DEFAULT 10000,
  usage_month TEXT NOT NULL,
  usage_count INTEGER NOT NULL DEFAULT 0,
  enabled INTEGER NOT NULL DEFAULT 1,
  created_at INTEGER NOT NULL,
  updated_at INTEGER NOT NULL
);

CREATE TABLE captcha_usage_events (
  id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES captcha_projects(id),
  event_type TEXT NOT NULL,
  action TEXT,
  hostname TEXT,
  success INTEGER NOT NULL,
  provider TEXT NOT NULL,
  created_at INTEGER NOT NULL
);
CREATE INDEX captcha_usage_project_time ON captcha_usage_events(project_id, created_at);
