Running plugin migrations when other plugin is installed? I'm creating a plugin (A) that has optional support for another 3rd party plugin (B). When my plugin A is installed, I create a number of tables. If plugin B is also installed my migrations create further tables specifically for plugin B.
The problem is if someone installs plugin A, then only installs plugin B afterward, my custom tables are never created.
How can I create tables/run migrations only when a plugin (B) is installed?
EDIT
I've been able to get this working with the following:
Event::on(
  Plugins::class,
  Plugins::EVENT_AFTER_INSTALL_PLUGIN,
  function (Event $event) {
    if ($event-&gt;plugin-&gt;handle == &quot;pluginB&quot;) {
      $migration = new migrations\m201031_120401_add_pluginB_support();
      $migration-&gt;safeUp();
    }
  });
You can have plugin A listen for the EVENT_AFTER_INSTALL_PLUGIN event.
It could then check if $plugin-&gt;handle is for plugin B and if so, run any additional install migrations or logic.
You could do something similar for the EVENT_AFTER_UNINSTALL_PLUGIN event to clean things up in the case where one gets uninstalled.