SAN FRANCISCO (CN) – A federal judge on Tuesday ordered the Trump administration to turn over contested Department of Homeland Security and Justice Department documents in multiple lawsuits challenging its decision to end a program that shields young undocumented immigrants from deportation.

Ruling that the administration had excluded “highly relevant materials” from the administrative record, U.S. District Judge William Alsup granted in part a motion by plaintiffs in five related lawsuits over the decision to terminate the Deferred Action for Childhood Arrivals program, or DACA.

In the ruling, Alsup granted the plaintiffs access to documents at both agencies but limited the scope of what must be produced.

“These are intended as practical limits on what would otherwise be a bone-crushing expedition to locate needles in haystacks,” Alsup wrote in a 14-page order.

The state of California, the University of California, the city of San Jose, Santa Clara County and a group of DACA recipients sued President Donald Trump and the Department of Homeland Security within days of the Sept. 5 announcement to phase out DACA beginning in six months – potentially jeopardizing the future of 800,000 program recipients, nicknamed Dreamers.

Dreamers, brought to the United States as undocumented children, must meet certain conditions to stay in the country, such as attending school and passing criminal background checks. California is home to more than a quarter of all Dreamers, more than any other state.

The plaintiffs called the government’s decision to end the program “arbitrary and capricious,” and said administration officials had made no attempt to justify it as a matter of policy, as required by the Administrative Procedure Act.

When the administration produced only the documents that Acting Homeland Security Secretary Elaine Duke personally considered in making her decision, the plaintiffs moved for a court order to also produce every document and communication she “indirectly” considered, especially ones viewed by all of Duke’s subordinates and anyone at the Justice Department.

They reasoned they should get the Justice Department documents because the decision was purportedly based on a letter from U.S. Attorney General Jeff Sessions that deemed DACA illegal, and because it was Sessions who announced the decision to the public.

“In our view, the decision-making agency may very well be the Department of Justice,” Jeffrey Davidson, an attorney with Covington & Burling representing the University of California, told Alsup at a hearing yesterday on the plaintiffs’ motion.

Alsup instead ordered the administration to produce all emails, letters, memos, notes, news items, opinions and other materials that Duke directly or indirectly considered; all DACA-related materials considered by employees anywhere in the government who gave Duke written or verbal advice or input – including at the Justice Department and the White House – and anything that former Homeland Security Secretary John Kelly considered in issuing his February memo that left DACA intact.

“The rule that government counsel advocates would allow agencies to contrive a record that suppresses information actually considered by decision-makers and by those making recommendations to the decision-makers, information that might undercut the claimed rationale for the decision,” Alsup wrote of the administration’s limited document production.

Davidson, the University of California’s attorney, agreed with Alsup’s assessment Tuesday.

“We are pleased that the court recognized the inadequacy of the administrative record initially produced by the government, and we look forward to a merits resolution based on the whole record, as the law requires,” he said in an email.

Alsup also held that the administration had waived attorney-client privilege over materials related to legality of DACA by saying that it had terminated it for that reason.

At the hearing, Justice Department attorney Brad Rosenberg insisted the decision was meant to avoid litigation over DACA by states that oppose it. In an opposition brief, the government argued that leaving DACA intact would have risked a nationwide injunction, “plunging its 800,000 recipients into uncertainty.” An “orderly wind-down” was “the least disruptive option,” the government said.

The Justice Department declined to comment Tuesday evening.

The administration must produce the documents by Oct. 27.