Skip to content

Instantly share code, notes, and snippets.

@frak
Last active October 31, 2019 12:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frak/5361df1556927443ba69ddd999cae718 to your computer and use it in GitHub Desktop.
Save frak/5361df1556927443ba69ddd999cae718 to your computer and use it in GitHub Desktop.
Run Doctrine migrations on composer install
{
"scripts": {
"symfony-scripts": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"default-params": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
],
"post-install-cmd": [
"@symfony-scripts",
"AppBundle\\Composer\\MigrationHandler::runMigrations"
],
"post-update-cmd": [
"@symfony-scripts"
]
}
}
<?php
namespace AppBundle\Composer;
use Composer\Script\Event;
use Sensio\Bundle\DistributionBundle\Composer\ScriptHandler;
class MigrationHandler extends ScriptHandler
{
/**
* Runs the Doctrine migrations.
*
* @param Event $event
*/
public static function runMigrations(Event $event)
{
$options = static::getOptions($event);
$consoleDir = static::getConsoleDir($event, 'run database migrations');
if (null === $consoleDir) {
return;
}
static::executeCommand($event, $consoleDir, 'doctrine:migrations:migrate -n', $options['process-timeout']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment