CREATE TABLE audit_logs (
  id TEXT PRIMARY KEY,
  actor_user_id TEXT,
  actor_name TEXT NOT NULL,
  actor_email TEXT,
  action_type TEXT NOT NULL,
  module TEXT NOT NULL,
  ip_address TEXT,
  severity TEXT NOT NULL DEFAULT 'default',
  details TEXT NOT NULL,
  metadata_json JSONB,
  created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX audit_logs_created_at_idx ON audit_logs(created_at);
CREATE INDEX audit_logs_actor_name_idx ON audit_logs(actor_name);
CREATE INDEX audit_logs_action_type_idx ON audit_logs(action_type);
CREATE INDEX audit_logs_module_idx ON audit_logs(module);
