[6.x] Allowing a plugin to run additional migration tracks #18128
-
|
In Craft 5, we could override the The issue I'm trying to solve is that I have a plugin that depends on certain additional migrations managed in a separate Laravel package and has a different migration track. Ideally, I would not have to communicate any details about this to a Craft user. They could just run the Craft plugin migrations as they normally do, and my code sorts out what migrations need to run. Currently, I think, Craft assumes there are only 3 types of migration tracks ( On Craft 5 I solved this by extending the MigrationManager and adding the logic I needed for the additional tracks. Is there some option to do this that I'm missing? If not, would Craft consider adding support within the migration logic and giving plugins some way to let Craft know what other migration tracks need to be run when a given plugin is installed/updated? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
|
6.x currently has no fixed set of tracks and you can use the You can retrieve the migrator either using dependency injection or You'll also need to call You can see for reference how the Plugin determines the paths & track to run https://github.com/craftcms/cms/blob/6.x/src/Plugin/Concerns/Installable.php#L73-L80 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @riasvdv. Can you help me connect the dots here? I understand what your saying about creating a Migrator with a custom Perhaps one more detail that I didn't mention in my first comment is that I'd like to have a single plugin do this for multiple custom tracks. The Where would you recommend that I |
Beta Was this translation helpful? Give feedback.
-
|
I've added an event which allows you to register additional migrators that are run with the use CraftCms\Cms\Database\Events\RegisterMigrators;
use CraftCms\Cms\Database\Migrator;
use Illuminate\Support\Facades\Event;
Event::listen(RegisterMigrators::class, function (RegisterMigrators $event) {
$event->migrators[] = app(Migrator::class)->track('my-track')->setPaths([
// Path to migration files
]);
});This is similar to how the functionality was already available as discussed here: #6172 (comment) |
Beta Was this translation helpful? Give feedback.
I've added an event which allows you to register additional migrators that are run with the
php craft migrate:allcommand: 70a57d6This is similar to how the functionality was already available as discussed here: #6172 (comment)