Can someone please help explain some basics regarding migrations and the associated CLI commands to help troubleshoot when things fail? Specifically,
How does craft know which migrations have been applied and which are new?
I.e. Is it by comparing the craft_migrations
table to the migration files found in '/vendor/craftcms/cms/src/migrations' folder (or plugin folders)?
Where does the information from running 'php craft migrate/new' and 'php craft migrate/history' come from? I ask because, when running php craft migrate/all
and a migration fails, if I reload the previous DB and run migrate/new
it says "No new migrations found", which is clearly wrong. Likewise running migrate/history
displays "No migration has been done before." But when running migrate/all
again it does attempt to run the migrations again. So clearly something is out of sync (or is terribly wrong in this project).
How are version numbers and migrations associated with each other? I.e. Is it simply based on whatever migration files happen to currently exist in the 'migrations' folder based on the last composer update
?
What determines the order that migrations are run? I.e. Are they simply run alphabetically, based on the file names in the 'migrations' folder?
Finally, if a migration fails, is there something else that should be done besides restoring the DB to reset the craft state, before attempting to run migrate/all
again?
Appreciate the help. Thanks.