CREATE TABLE IF NOT EXISTS xbp_nginx_edit_audit_logs (
    nginx_edit_audit_log_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    project_id uuid REFERENCES xbp_projects(project_id) ON DELETE SET NULL,
    domain text,
    config_path text,
    actor text,
    action text NOT NULL,
    old_content text,
    new_content text,
    occurred_at timestamptz NOT NULL,
    metadata jsonb NOT NULL DEFAULT '{}'::jsonb,
    created_at timestamptz NOT NULL DEFAULT now(),
    updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_xbp_nginx_audit_project_id ON xbp_nginx_edit_audit_logs (project_id);
CREATE INDEX IF NOT EXISTS idx_xbp_nginx_audit_domain ON xbp_nginx_edit_audit_logs (domain);
CREATE INDEX IF NOT EXISTS idx_xbp_nginx_audit_occurred_at ON xbp_nginx_edit_audit_logs (occurred_at DESC);
