It this is the case then I would probably add an option when I did it the first time https://codex.wordpress.org/Function_Reference/add_option and check this option to see if it’s already been run. Might be the simplest thing to do.
$option = get_option('my_option');
if (!$option) {
// run setup
add_option('my_option', true);
}