Let's start with the ending: you didn't eat exclusively with your friends on the terrace, so you use the imperfect. Eating is a short event repeated an unspecified number of times, so the past perfect sounds wrong to me, unless you really ate for three years with your friends, on the terrace.
The "ir a la escuela" bit is more ambiguous, you could argue for the use both past tenses: you definitely don't go anymore to that school, and it's a specific period of time, but on the other hand, maybe you didn't go to school every day. Maybe you want to use the imperfect to give a sense of "unfinished business", maybe not. It's not incorrect to use either tense in that part of the sentence.
All this said, I'd use the second sentence. It's more "undefined", thanks to the use of the past imperfect, and that's what I'd use. Note that I'd do the opposite in English if I were to describe a 3 months' stay in London, where I studied English and occasionally ate with friends on the school's terrace.
As a pedantic aside, I have to say that, in any case, the sentence feels forced. Really, you lived in Spain for three years and what you can tell us about that is that you went to school and you ate with friends on the terrace? Which terrace, by the way? That "la" is very definite. It also gives an image of you eating there day after day, in summer, and winter, under the snow... The combination of interesting (school -> learning Spanish language and culture, making friends) and trivial (eating on the terrace) is really jarring.