I am searching community for the same question and
the piece of code in Sergei's link is the answer!
Thank you Sergei.
I don't understand this question "why you want to make it?"?
SKD asked a totally relevant question.
No need to long explanations, but ok if anyone wants to know the reason, i can give you mine...
We don't want to open doors for a System App (AAD) in upper environments (UAT, QA, PRD...)
So i do my setup in DEV, where third party is testing new OData and API.
(Before any puritan asks why in DEV, no matter we were doing so in TST we would end up with the same problem)
As "Data Dump" occurs from upper environment onto DEV, it overrides our setup, which resides in Data level.
We can assure Application level elements are always present (Security Role, Duties, and Privileges) but for Data level only the user comes from restored DB, roles assignment does not.
And this long story is why i need to easily recreate a simple Role Assignment into my testing environment.
Again, thank you Sergei for enriching community content the simple way.