How can I make sure a function is ran only once when it's installed for the 1st time in a store?

I’ve some functions to create metafield definitions that I want them to run only once when the app is being installed for the 1st time in a store and then run some other functions when the app is being uninstalled.

How can I do that? TIA.

For your information I’m using an Remix App.