custom-integration.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Custom Integration
  2. ==================
  3. If you don't want to use the ``./vendor/bin/doctrine-migrations`` script that comes with the project,
  4. you can always setup your own custom integration.
  5. In the root of your project, create a file named ``migrations`` and make it executable:
  6. .. code-block:: bash
  7. $ chmod +x migrations
  8. Now place the following code in the ``migrations`` file:
  9. .. code-block:: php
  10. #!/usr/bin/env php
  11. <?php
  12. require_once __DIR__.'/vendor/autoload.php';
  13. use Doctrine\DBAL\DriverManager;
  14. use Doctrine\Migrations\DependencyFactory;
  15. use Doctrine\Migrations\Configuration\Migration\PhpFile;
  16. use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
  17. use Doctrine\Migrations\Tools\Console\Command;
  18. use Symfony\Component\Console\Application;
  19. $dbParams = [
  20. 'dbname' => 'migrations_docs_example',
  21. 'user' => 'root',
  22. 'password' => '',
  23. 'host' => 'localhost',
  24. 'driver' => 'pdo_mysql',
  25. ];
  26. $connection = DriverManager::getConnection($dbParams);
  27. $config = new PhpFile('migrations.php'); // Or use one of the Doctrine\Migrations\Configuration\Configuration\* loaders
  28. $dependencyFactory = DependencyFactory::fromConnection($config, new ExistingConnection($connection));
  29. $cli = new Application('Doctrine Migrations');
  30. $cli->setCatchExceptions(true);
  31. $cli->addCommands(array(
  32. new Command\DumpSchemaCommand($dependencyFactory),
  33. new Command\ExecuteCommand($dependencyFactory),
  34. new Command\GenerateCommand($dependencyFactory),
  35. new Command\LatestCommand($dependencyFactory),
  36. new Command\ListCommand($dependencyFactory),
  37. new Command\MigrateCommand($dependencyFactory),
  38. new Command\RollupCommand($dependencyFactory),
  39. new Command\StatusCommand($dependencyFactory),
  40. new Command\SyncMetadataCommand($dependencyFactory),
  41. new Command\VersionCommand($dependencyFactory),
  42. ));
  43. $cli->run();
  44. Now you can execute the migrations console application like this:
  45. .. code-block:: bash
  46. $ ./migrations