This is a classic case of inversion. Note that "did" in inversions comes always with "only" which combines with time expressions and it is usually used with past simple. It has nothing to do with it being before a pronoun and in an affirmative sentence .
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.