doctrine.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Doctrine\ORM\Tools\Console\ConsoleRunner;
  4. use Symfony\Component\Console\Helper\HelperSet;
  5. use Doctrine\DBAL\Types\Type;
  6. /**
  7. * Very useful script in order to create a Migration file based in the
  8. * current differences of the database:
  9. *
  10. * php bin/doctrine.php migrations:diff
  11. *
  12. * This script also show doctrine basic commands:
  13. * - Create schema
  14. * - Drop schema
  15. * - Update schema,
  16. * etc
  17. *
  18. **/
  19. (@include_once __DIR__.'/../vendor/autoload.php') || @include_once __DIR__.'/../../../autoload.php';
  20. $directories = array(getcwd(), getcwd().DIRECTORY_SEPARATOR.'config');
  21. $configFile = null;
  22. foreach ($directories as $directory) {
  23. $configFile = $directory.DIRECTORY_SEPARATOR.'cli-config.php';
  24. if (file_exists($configFile)) {
  25. break;
  26. }
  27. }
  28. if (!file_exists($configFile)) {
  29. ConsoleRunner::printCliConfigTemplate();
  30. exit(1);
  31. }
  32. if (!is_readable($configFile)) {
  33. echo 'Configuration file ['.$configFile.'] does not have read permission.'."\n";
  34. exit(1);
  35. }
  36. Type::overrideType(
  37. Type::DATETIME,
  38. Database::getUTCDateTimeTypeClass()
  39. );
  40. if (!Type::hasType('json')) {
  41. Type::addType(
  42. 'json',
  43. 'Sonata\Doctrine\Types\JsonType'
  44. );
  45. }
  46. $commands = array(
  47. new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
  48. new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
  49. new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
  50. new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(),
  51. new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
  52. new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
  53. new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
  54. );
  55. $helperSet = require $configFile;
  56. if (!($helperSet instanceof HelperSet)) {
  57. foreach ($GLOBALS as $helperSetCandidate) {
  58. if ($helperSetCandidate instanceof HelperSet) {
  59. $helperSet = $helperSetCandidate;
  60. break;
  61. }
  62. }
  63. }
  64. \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);