-- SQL to create auth_audit table in Supabase
CREATE OR REPLACE FUNCTION public.create_auth_audit_table()
RETURNS void
LANGUAGE sql
AS $$
  CREATE TABLE IF NOT EXISTS auth_audit (
    id BIGSERIAL PRIMARY KEY,
    user_id UUID REFERENCES users(id),
    action TEXT NOT NULL,
    timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    details TEXT,
    ip_address TEXT
  );

  CREATE INDEX IF NOT EXISTS idx_auth_audit_user_id ON auth_audit(user_id);
  CREATE INDEX IF NOT EXISTS idx_auth_audit_timestamp ON auth_audit(timestamp);
$$;
