(a) A juvenile court may allow, by order, the inspection of records sealed under this subchapter or under Section 58.003, as that law existed before September 1, 2017, only by:
(1) a person named in the order, on the petition of the person who is the subject of the records;
(2) a prosecutor, on the petition of the prosecutor, for the purpose of reviewing the records for possible use:
(A) in a capital prosecution; or
(B) for the enhancement of punishment under Section 12.42, Penal Code; or
(3) a court, the Texas Department of Criminal Justice, or the Texas Juvenile Justice Department for the purposes of Article 62.007(e), Code of Criminal Procedure.
(b) After a petitioner inspects records under this section, the court may order the release of any or all of the records to the petitioner on the motion of the petitioner.