Documenting the Automated Schema Migrations

Hi, I am very new to Strapi. I’m working on a project that was built with Strapi. I am trying to better understand Strapi’s database tables and database migrations.

I found this in the Documentation

These migrations are run automatically when the application starts and are executed before the automated schema migrations that Strapi also performs on boot.

Is there a section in the Documentation that gives a good explanation of these automated schema migrations? If not, can we add one? What should I know about these automated schema migrations to be a good developer with Strapi?

My initial impression of Strapi is that there is a lot of code running every time that the application server boots up. I want to understand that code better and help my team understand it better. What should I know about the boot up code in order to be a good developer with Strapi. Thank you!

1 Like

I will look in to this and get back to you as soon as I get some more information. I am not a DB expert so will take me some time to gather some resources.

But this is an area where I would like to improve my understanding. So I will challenge my self to write a blog post answering your questions in the mean time. I will also post my finding here.

And will ping @piwi for visibility to remind me to add request for more content on this topic.

Thanks. In my original post I meant to link to Database migrations | Strapi Documentation but I put the : at the end of the URL instead of putting a space before the colon.

My guess is that something like this happens when the Strapi app starts. But I want more clarification:

  1. first it finds all of the migration files in ./database/migrations .
  2. Then it checks the database to see if any of those have not been run yet
  3. Any of those migration files for the current environment that haven’t been run yet gets run in alphabetical order. Only if automigration is turned on?
  4. Then – I think, but this part I’m fuzzy on – Strapi goes through and finds all of the schema .JSON files for “content-types” . Then it tries to modify the database tables to make sure that the tables support the schemas? Only if auto migration is turned on? But it doesn’t generate migration files for these changes to the database? They just sort of happen behind the scenes? I’m not sure yet. I haven’t had time to study Strapi enough yet.

Step 3: Scripts will run regardless if auto is turned on.

Step 4:

  1. It will call the internal api to check all the collection types
  2. generate hash key
  3. Compare to previous generated hash key
  4. If different will run using native database functions to check DB schema vs Strapi schema.
  5. Will fix any deviations
  6. Store the new hash key in place of the old one.

I got these details from @DMehaffy thank you for your help.