doctrine.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Very useful script in order to create a Migration file based in the
  5. * current differences of the database:
  6. *
  7. * php bin/doctrine.php migrations:diff
  8. *
  9. * This script also show doctrine basic commands:
  10. * - Create schema
  11. * - Drop schema
  12. * - Update schema,
  13. * etc
  14. *
  15. **/
  16. use Doctrine\ORM\Tools\Console\ConsoleRunner;
  17. use Symfony\Component\Console\Helper\HelperSet;
  18. use Doctrine\DBAL\Types\Type;
  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. Type::addType(
  41. 'json',
  42. 'Sonata\Doctrine\Types\JsonType'
  43. );
  44. $commands = array(
  45. new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
  46. new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
  47. new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
  48. new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(),
  49. new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
  50. new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
  51. new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
  52. );
  53. $helperSet = require $configFile;
  54. if ( ! ($helperSet instanceof HelperSet)) {
  55. foreach ($GLOBALS as $helperSetCandidate) {
  56. if ($helperSetCandidate instanceof HelperSet) {
  57. $helperSet = $helperSetCandidate;
  58. break;
  59. }
  60. }
  61. }
  62. \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);