Data migration and population for new content-types

I have a new content-type e.g. articles

From Strapi documentation, it seems that

Migrations are run before the database tables are synced with the content-types schemas.

I need to:

  1. Make sure that the content-type exist
  2. Do a findMany on ‘users’, populate and filter by the field ‘articles’ where it is null
  3. Perform relationship mapping with by creating the articles and linking them to ‘users’

I have to make sure #2 doesn’t fail, which can happen when we promote code upstream to higher environments, since the content-type creation code and the migration are pushed together to the new environment. This happened before.

How can I overcome this?

This topic has been created from a Discord post (1230171048692158617) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord