Suppose $X$ is a finite flat group scheme over $\mathbb Z$, killed by a prime number $p$ and such that there exists an extension as finite flat group schemes defined over $\mathbb Z$: $$0\to \mathbb{Z}/p\mathbb{Z}\to X \to \mu_p \to 1.$$

Question:Can we conclude that $X\cong \mathbb{Z}/p\mathbb{Z}\times \mu_p$ over $\mathbb{Z}$?

I know that the answer to this question is negative in general if you consider it over $\mathbb Q$, since you can take $X=E[7]$, the group scheme of $p$-torsion points of an elliptic curve with a $7$-torsion point defined over $\mathbb Q$, since we have such elliptic curves but no such curve with $E[7]\cong \mathbb{Z}/7\mathbb{Z}\times \mu_7$. Of course you can find examples easily for $p=2,3,5$, and probably for infinitely many prime numbers.

On the other hand, over the finite field $\mathbb{F}_p$ the answer is positive, since $\mu_p$ is connected and $\mathbb{Z}/p\mathbb{Z}$ étale, and one could use the connected-étale exact sequence of $X$ to get an splitting of the exact sequence above.

If the answer to the question is affirmative, I will be also interested for what other ring of integers the result is true. I suspect it should be related to the fact that $\mathbb{Q}$ has no unramified extensions.