Seeking suggestions for updating foreign key with attribute value

I have a user attribute that I’d like to use as a foreign key to look up subscribers.

I am using the RestAPI plugin extensively, and it allows setting of the foreign key when adding subscribers, but no way I can find to update the foreign key of an existing subscriber.

I certainly can update the field directly with SQL, but I try to avoid directly manipulating the database in case there are some rules or related values I am unaware of.

What I am trying to achieve is that whenever a specific user attribute changes, the foreign key is set to that value. In my particular case, I’d like to strip non-digits from the user attribute when updating the foreign key, but that is an implementation detail.

It would work for me to have this update occur in non realtime using a cron job or similar.

Does anyone have suggestions or best practices to achieve these results safely and reliably?

Thanks for listening.