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 https://docs.strapi.io/dev-docs/database-migrations:
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!
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:
- first it finds all of the migration files in ./database/migrations .
- Then it checks the database to see if any of those have not been run yet
- 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?
- 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.
- It will call the internal api to check all the collection types
- generate hash key
- Compare to previous generated hash key
- If different will run using native database functions to check DB schema vs Strapi schema.
- Will fix any deviations
- Store the new hash key in place of the old one.
I got these details from @DMehaffy thank you for your help.