# Mark users as migrated with rule

**URL:** <https://community.auth0.com/t/mark-users-as-migrated-with-rule/43838>\
**Category:** Get Help\
**Tags:** user-migration, auth0\
**Created:** [May 30, 2020, 6:40pm UTC](https://community.auth0.com/t/mark-users-as-migrated-with-rule/43838 "2020-05-30T18:40:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenneth.lamantia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kenneth.lamantia/32/12848_2.png) [@kenneth.lamantia](https://community.auth0.com/u/kenneth.lamantia)\
**Post date:** [May 30, 2020, 6:40pm UTC](https://community.auth0.com/t/mark-users-as-migrated-with-rule/43838/1 "2020-05-30T18:40:53Z")

</div>

In these docs: [Custom Database Action Script Execution Best Practices - Auth0 Docs](https://auth0.com/docs/best-practices/custom-db-connections/execution)

There is a section that says:

> **Use a rule to mark users as migrated.** This is not a hard requirement, but it does protect against one scenario in which a user changes their email address, then changes it back to the original email address. A rule should call out to the legacy database to mark the user as being migrated in the original database so that `get_user` can return false.

In the context of a rule, is there an out of the box way to tell if a user was migrated vs. newly registered directly in the Auth0 managed database? The way that section of the docs is written implies there is some straighforward way to do this.

Thanks.

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [June 1, 2020, 3:01pm UTC](https://community.auth0.com/t/mark-users-as-migrated-with-rule/43838/2 "2020-06-01T15:01:32Z")

</div>

In your lazy migration script, populate an app\_metadata field something like “migrated\_from\_legacy”: “true”

This will only be populated then for users who are migrated.

John

---

<div class="post-metadata">

**Author:** ![kenneth.lamantia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kenneth.lamantia/32/12848_2.png) [@kenneth.lamantia](https://community.auth0.com/u/kenneth.lamantia)\
**Post date:** [June 1, 2020, 3:43pm UTC](https://community.auth0.com/t/mark-users-as-migrated-with-rule/43838/3 "2020-06-01T15:43:31Z")

</div>

How do you recommend handling the edge case where app\_metadata is not properly populated from the database action script? I was thinking of appending text to the user\_id e.g. “\_migrated”.  
From your docs:

> If setting app\_metadata or user\_metadata, use a rule to fetch the metadata if it is missing. The metadata is not migrated until [https://YOUR\_TENANT.auth0.com/login/callback](https://your_tenant.auth0.com/login/callback) is called. However, the user credentials are migrated during the post to usernamepassword/login. This means that if the browser is killed or computer dies on a user after they have posted to usernamepassword/login, but before login/callback, then they will have a user in the Auth0 database, but their app and user metadata are lost. It is really important, therefore, to create a rule that looks a lot like your get\_user script to fetch the profile if app and user metadata are blank. This should only execute once per user at most (and usually never).
