Yii migrations will be applied in alphabetical order, and the convention is that their names start with the letter m
, followed by the date and time when the migration was created (for example, something like m221206_185401_create_foo_field_group
).
In other words, to create a set of migrations that needs to be applied in a particular order, simply make sure that the first migration has an earlier date/time in its name than the second one, and so on.
A good idea is using the core migrate/create
CLI command to scaffold your migrations. That console command will create the necessary migration files for you, with generated file/class names containing the current date and time. So to create your set of migrations, you could simply execute the migrate/create
command multiple times; scaffolding each migration in the order that they should be run.
Note that the utility defaults to creating content migrations, but can also be used to create plugin migrations by specifying a plugin handle with the --plugin
parameter:
php craft migrate/create create_foo_field_group --plugin=some-plugin-handle
It's also worth mentioning that except for creating an entry, all of the operations you plan on handling in these migrations are things that Craft will track in project config. As such, you should make sure that your migrations apply their schema changes defensibly; avoiding the risk of conflicts in cases where the project config YAML files are checked into version control and allowAdminChanges
is set to false
in the current environment. The official docs have a decent outline on this topic.