init without trunk
This commit is contained in:
parent
ed24ac4994
commit
bb809e7233
14652 changed files with 177862 additions and 94817 deletions
2
vendor/doctrine/doctrine-migrations-bundle/.gitignore
vendored
Normal file
2
vendor/doctrine/doctrine-migrations-bundle/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
composer.lock
|
||||
/vendor/
|
||||
13
vendor/doctrine/doctrine-migrations-bundle/Changelog.md
vendored
Normal file
13
vendor/doctrine/doctrine-migrations-bundle/Changelog.md
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
## 1.1.0 (2015-09-29)
|
||||
|
||||
Features:
|
||||
|
||||
* Allowed DoctrineMigrationsBundle to work with Symfony apps using DBAL only
|
||||
|
||||
## 1.0.1 (2015-05-06)
|
||||
|
||||
* Allowed Symfony 3.0 components
|
||||
|
||||
## 1.0.0 (2014-08-17)
|
||||
|
||||
Initial stable release
|
||||
105
vendor/doctrine/doctrine-migrations-bundle/Command/DoctrineCommand.php
vendored
Normal file
105
vendor/doctrine/doctrine-migrations-bundle/Command/DoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand as BaseCommand;
|
||||
use Doctrine\DBAL\Migrations\Configuration\AbstractFileConfiguration;
|
||||
use Doctrine\DBAL\Migrations\Configuration\Configuration;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Base class for Doctrine console commands to extend from.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class DoctrineCommand extends BaseCommand
|
||||
{
|
||||
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
|
||||
{
|
||||
if (!$configuration->getMigrationsDirectory()) {
|
||||
$dir = $container->getParameter('doctrine_migrations.dir_name');
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
|
||||
$error = error_get_last();
|
||||
throw new \ErrorException($error['message']);
|
||||
}
|
||||
$configuration->setMigrationsDirectory($dir);
|
||||
} else {
|
||||
$dir = $configuration->getMigrationsDirectory();
|
||||
// class Kernel has method getKernelParameters with some of the important path parameters
|
||||
$pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
|
||||
foreach ($pathPlaceholderArray as $pathPlaceholder) {
|
||||
if ($container->hasParameter($pathPlaceholder) && preg_match('/\%'.$pathPlaceholder.'\%/', $dir)) {
|
||||
$dir = str_replace('%'.$pathPlaceholder.'%', $container->getParameter($pathPlaceholder), $dir);
|
||||
}
|
||||
}
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
|
||||
$error = error_get_last();
|
||||
throw new \ErrorException($error['message']);
|
||||
}
|
||||
$configuration->setMigrationsDirectory($dir);
|
||||
}
|
||||
if (!$configuration->getMigrationsNamespace()) {
|
||||
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
|
||||
}
|
||||
if (!$configuration->getName()) {
|
||||
$configuration->setName($container->getParameter('doctrine_migrations.name'));
|
||||
}
|
||||
// For backward compatibility, need use a table from parameters for overwrite the default configuration
|
||||
if (!($configuration instanceof AbstractFileConfiguration) || !$configuration->getMigrationsTableName()) {
|
||||
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
|
||||
}
|
||||
// Migrations is not register from configuration loader
|
||||
if (!($configuration instanceof AbstractFileConfiguration)) {
|
||||
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
|
||||
}
|
||||
|
||||
$organizeMigrations = $container->getParameter('doctrine_migrations.organize_migrations');
|
||||
switch ($organizeMigrations) {
|
||||
case Configuration::VERSIONS_ORGANIZATION_BY_YEAR:
|
||||
$configuration->setMigrationsAreOrganizedByYear(true);
|
||||
break;
|
||||
|
||||
case Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
|
||||
$configuration->setMigrationsAreOrganizedByYearAndMonth(true);
|
||||
break;
|
||||
|
||||
case false:
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidArgumentException('Invalid value for "doctrine_migrations.organize_migrations" parameter.');
|
||||
}
|
||||
|
||||
self::injectContainerToMigrations($container, $configuration->getMigrations());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @param array $versions
|
||||
*
|
||||
* Injects the container to migrations aware of it
|
||||
*/
|
||||
private static function injectContainerToMigrations(ContainerInterface $container, array $versions)
|
||||
{
|
||||
foreach ($versions as $version) {
|
||||
$migration = $version->getMigration();
|
||||
if ($migration instanceof ContainerAwareInterface) {
|
||||
$migration->setContainer($container);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
vendor/doctrine/doctrine-migrations-bundle/Command/Helper/DoctrineCommandHelper.php
vendored
Normal file
55
vendor/doctrine/doctrine-migrations-bundle/Command/Helper/DoctrineCommandHelper.php
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Guilehrme Blanco <guilhermeblanco@hotmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command\Helper;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper as BaseDoctrineCommandHelper;
|
||||
use Doctrine\DBAL\Sharding\PoolingShardConnection;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
|
||||
* and multiple connections/entity managers.
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
abstract class DoctrineCommandHelper extends BaseDoctrineCommandHelper
|
||||
{
|
||||
public static function setApplicationHelper(Application $application, InputInterface $input)
|
||||
{
|
||||
$container = $application->getKernel()->getContainer();
|
||||
$doctrine = $container->get('doctrine');
|
||||
$managerNames = $doctrine->getManagerNames();
|
||||
|
||||
if ($input->getOption('db') || empty($managerNames)) {
|
||||
self::setApplicationConnection($application, $input->getOption('db'));
|
||||
} else {
|
||||
self::setApplicationEntityManager($application, $input->getOption('em'));
|
||||
}
|
||||
|
||||
if ($input->getOption('shard')) {
|
||||
$connection = $application->getHelperSet()->get('db')->getConnection();
|
||||
if (!$connection instanceof PoolingShardConnection) {
|
||||
if (empty($managerNames)) {
|
||||
throw new \LogicException(sprintf("Connection '%s' must implement shards configuration.", $input->getOption('db')));
|
||||
} else {
|
||||
throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em')));
|
||||
}
|
||||
}
|
||||
|
||||
$connection->connect($input->getOption('shard'));
|
||||
}
|
||||
}
|
||||
}
|
||||
63
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsDiffDoctrineCommand.php
vendored
Normal file
63
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsDiffDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand;
|
||||
use Doctrine\DBAL\Sharding\PoolingShardConnection;
|
||||
use LogicException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Command for generate migration classes by comparing your current database schema
|
||||
* to your mapping information.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsDiffDoctrineCommand extends DiffCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:diff')
|
||||
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
|
||||
if ($input->getOption('shard')) {
|
||||
$connection = $this->getApplication()->getHelperSet()->get('db')->getConnection();
|
||||
if (!$connection instanceof PoolingShardConnection) {
|
||||
throw new LogicException(sprintf("Connection of EntityManager '%s' must implements shards configuration.", $input->getOption('em')));
|
||||
}
|
||||
|
||||
$connection->connect($input->getOption('shard'));
|
||||
}
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsExecuteDoctrineCommand.php
vendored
Normal file
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsExecuteDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
|
||||
|
||||
/**
|
||||
* Command for executing single migrations up or down manually.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:execute')
|
||||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
|
||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// EM and DB options cannot be set at same time
|
||||
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
|
||||
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
|
||||
}
|
||||
|
||||
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsGenerateDoctrineCommand.php
vendored
Normal file
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsGenerateDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
|
||||
|
||||
/**
|
||||
* Command for generating new blank migration classes
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsGenerateDoctrineCommand extends GenerateCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:generate')
|
||||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
|
||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// EM and DB options cannot be set at same time
|
||||
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
|
||||
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
|
||||
}
|
||||
|
||||
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsLatestDoctrineCommand.php
vendored
Normal file
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsLatestDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand;
|
||||
|
||||
/**
|
||||
* Command for outputting the latest version number.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsLatestDoctrineCommand extends LatestCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:latest')
|
||||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
|
||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// EM and DB options cannot be set at same time
|
||||
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
|
||||
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
|
||||
}
|
||||
|
||||
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsMigrateDoctrineCommand.php
vendored
Normal file
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsMigrateDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
|
||||
|
||||
/**
|
||||
* Command for executing a migration to a specified version or the latest available version.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsMigrateDoctrineCommand extends MigrateCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:migrate')
|
||||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
|
||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// EM and DB options cannot be set at same time
|
||||
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
|
||||
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
|
||||
}
|
||||
|
||||
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsStatusDoctrineCommand.php
vendored
Normal file
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsStatusDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
|
||||
|
||||
/**
|
||||
* Command to view the status of a set of migrations.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsStatusDoctrineCommand extends StatusCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:status')
|
||||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
|
||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// EM and DB options cannot be set at same time
|
||||
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
|
||||
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
|
||||
}
|
||||
|
||||
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsVersionDoctrineCommand.php
vendored
Normal file
57
vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsVersionDoctrineCommand.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
|
||||
|
||||
/**
|
||||
* Command for manually adding and deleting migration versions from the version table.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class MigrationsVersionDoctrineCommand extends VersionCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:migrations:version')
|
||||
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
|
||||
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
|
||||
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// EM and DB options cannot be set at same time
|
||||
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
|
||||
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
|
||||
}
|
||||
|
||||
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
|
||||
|
||||
$configuration = $this->getMigrationConfiguration($input, $output);
|
||||
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
96
vendor/doctrine/doctrine-migrations-bundle/DependencyInjection/Configuration.php
vendored
Normal file
96
vendor/doctrine/doctrine-migrations-bundle/DependencyInjection/Configuration.php
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* DoctrineMigrationsExtension configuration structure.
|
||||
*
|
||||
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* Generates the configuration tree.
|
||||
*
|
||||
* @return TreeBuilder The config tree builder
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('doctrine_migrations', 'array');
|
||||
|
||||
$organizeMigrationModes = $this->getOrganizeMigrationsModes();
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('dir_name')->defaultValue('%kernel.root_dir%/DoctrineMigrations')->cannotBeEmpty()->end()
|
||||
->scalarNode('namespace')->defaultValue('Application\Migrations')->cannotBeEmpty()->end()
|
||||
->scalarNode('table_name')->defaultValue('migration_versions')->cannotBeEmpty()->end()
|
||||
->scalarNode('name')->defaultValue('Application Migrations')->end()
|
||||
->scalarNode('organize_migrations')->defaultValue(false)
|
||||
->info('Organize migrations mode. Possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false')
|
||||
->validate()
|
||||
->ifTrue(function ($v) use ($organizeMigrationModes) {
|
||||
if (false === $v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_string($v) && in_array(strtoupper($v), $organizeMigrationModes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
->thenInvalid('Invalid organize migrations mode value %s')
|
||||
->end()
|
||||
->validate()
|
||||
->ifString()
|
||||
->then(function ($v) {
|
||||
return constant('Doctrine\DBAL\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_'.strtoupper($v));
|
||||
})
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find organize migrations modes for their names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getOrganizeMigrationsModes()
|
||||
{
|
||||
$constPrefix = 'VERSIONS_ORGANIZATION_';
|
||||
$prefixLen = strlen($constPrefix);
|
||||
$refClass = new \ReflectionClass('Doctrine\DBAL\Migrations\Configuration\Configuration');
|
||||
$constsArray = $refClass->getConstants();
|
||||
$namesArray = array();
|
||||
|
||||
foreach ($constsArray as $key => $value) {
|
||||
if (strpos($key, $constPrefix) === 0) {
|
||||
$namesArray[] = substr($key, $prefixLen);
|
||||
}
|
||||
}
|
||||
|
||||
return $namesArray;
|
||||
}
|
||||
}
|
||||
58
vendor/doctrine/doctrine-migrations-bundle/DependencyInjection/DoctrineMigrationsExtension.php
vendored
Normal file
58
vendor/doctrine/doctrine-migrations-bundle/DependencyInjection/DoctrineMigrationsExtension.php
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* DoctrineMigrationsExtension.
|
||||
*
|
||||
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
|
||||
*/
|
||||
class DoctrineMigrationsExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* Responds to the migrations configuration parameter.
|
||||
*
|
||||
* @param array $configs
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
foreach ($config as $key => $value) {
|
||||
$container->setParameter($this->getAlias().'.'.$key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base path for the XSD files.
|
||||
*
|
||||
* @return string The XSD base path
|
||||
*/
|
||||
public function getXsdValidationBasePath()
|
||||
{
|
||||
return __DIR__.'/../Resources/config/schema';
|
||||
}
|
||||
|
||||
public function getNamespace()
|
||||
{
|
||||
return 'http://symfony.com/schema/dic/doctrine/migrations';
|
||||
}
|
||||
}
|
||||
27
vendor/doctrine/doctrine-migrations-bundle/DoctrineMigrationsBundle.php
vendored
Normal file
27
vendor/doctrine/doctrine-migrations-bundle/DoctrineMigrationsBundle.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Doctrine MigrationsBundle
|
||||
*
|
||||
* The code was originally distributed inside the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
/**
|
||||
* Bundle.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class DoctrineMigrationsBundle extends Bundle
|
||||
{
|
||||
}
|
||||
19
vendor/doctrine/doctrine-migrations-bundle/LICENSE
vendored
Normal file
19
vendor/doctrine/doctrine-migrations-bundle/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2006-2013 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
17
vendor/doctrine/doctrine-migrations-bundle/README.markdown
vendored
Normal file
17
vendor/doctrine/doctrine-migrations-bundle/README.markdown
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
DoctrineMigrationsBundle
|
||||
========================
|
||||
|
||||
This bundle integrates the [Doctrine2 Migrations library](http://www.doctrine-project.org/projects/migrations.html).
|
||||
into Symfony so that you can safely and quickly manage database migrations.
|
||||
|
||||
Documentation on how to install and use this bundle is available in the
|
||||
Symfony2 [documentation](https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html).
|
||||
|
||||
WARNING: Namespace changed
|
||||
==========================
|
||||
|
||||
This bundle was previously under the `Symfony\Bundle` namespace and is now moved to the
|
||||
`Doctrine\Bundle` namespace.
|
||||
|
||||
See the Resources/docs/index.rst for more information about the required changes in `deps`,
|
||||
`AppKernel.php` and `autoload.php` to accomodate for this change.
|
||||
24
vendor/doctrine/doctrine-migrations-bundle/Resources/config/schema/doctrine_migrations-1.0.xsd
vendored
Normal file
24
vendor/doctrine/doctrine-migrations-bundle/Resources/config/schema/doctrine_migrations-1.0.xsd
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xsd:schema xmlns="http://symfony.com/schema/dic/doctrine/migrations"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://symfony.com/schema/dic/doctrine/migrations"
|
||||
elementFormDefault="qualified">
|
||||
|
||||
<xsd:element name="config">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="dir_name" type="xsd:string" />
|
||||
<xsd:attribute name="namespace" type="xsd:string" />
|
||||
<xsd:attribute name="table_name" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="organize-migrations">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="BY_YEAR" />
|
||||
<xsd:enumeration value="BY_YEAR_AND_MONTH" />
|
||||
<xsd:enumeration value="false" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
410
vendor/doctrine/doctrine-migrations-bundle/Resources/doc/index.rst
vendored
Normal file
410
vendor/doctrine/doctrine-migrations-bundle/Resources/doc/index.rst
vendored
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
DoctrineMigrationsBundle
|
||||
========================
|
||||
|
||||
The database migrations feature is an extension of the database abstraction
|
||||
layer and offers you the ability to programmatically deploy new versions of
|
||||
your database schema in a safe, easy and standardized way.
|
||||
|
||||
.. tip::
|
||||
|
||||
You can read more about the Doctrine Database Migrations on the project's
|
||||
`documentation`_.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Doctrine migrations for Symfony are maintained in the `DoctrineMigrationsBundle`_.
|
||||
The bundle uses external `Doctrine Database Migrations`_ library.
|
||||
|
||||
First, install the bundle with composer:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ composer require doctrine/doctrine-migrations-bundle "^1.0"
|
||||
|
||||
If everything worked, the ``DoctrineMigrationsBundle`` can now be found
|
||||
at ``vendor/doctrine/doctrine-migrations-bundle``.
|
||||
|
||||
.. note::
|
||||
|
||||
``DoctrineMigrationsBundle`` installs
|
||||
`Doctrine Database Migrations`_ library. The library can be found
|
||||
at ``vendor/doctrine/migrations``.
|
||||
|
||||
Finally, be sure to enable the bundle in ``AppKernel.php`` by including the
|
||||
following:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// app/AppKernel.php
|
||||
public function registerBundles()
|
||||
{
|
||||
$bundles = array(
|
||||
//...
|
||||
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
|
||||
);
|
||||
}
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
You can configure the path, namespace, table_name and name in your ``config.yml``. The examples below are the default values.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# app/config/config.yml
|
||||
doctrine_migrations:
|
||||
dir_name: "%kernel.root_dir%/DoctrineMigrations"
|
||||
namespace: Application\Migrations
|
||||
table_name: migration_versions
|
||||
name: Application Migrations
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
.. caution::
|
||||
|
||||
If your application is based on Symfony 3, replace ``php app/console`` by
|
||||
``php bin/console`` before executing any of the console commands included
|
||||
in this article.
|
||||
|
||||
All of the migrations functionality is contained in a few console commands:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
doctrine:migrations
|
||||
:diff Generate a migration by comparing your current database to your mapping information.
|
||||
:execute Execute a single migration version up or down manually.
|
||||
:generate Generate a blank migration class.
|
||||
:migrate Execute a migration to a specified version or the latest available version.
|
||||
:status View the status of a set of migrations.
|
||||
:version Manually add and delete migration versions from the version table.
|
||||
|
||||
Start by getting the status of migrations in your application by running
|
||||
the ``status`` command:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
php app/console doctrine:migrations:status
|
||||
|
||||
== Configuration
|
||||
|
||||
>> Name: Application Migrations
|
||||
>> Configuration Source: manually configured
|
||||
>> Version Table Name: migration_versions
|
||||
>> Migrations Namespace: Application\Migrations
|
||||
>> Migrations Directory: /path/to/project/app/DoctrineMigrations
|
||||
>> Current Version: 0
|
||||
>> Latest Version: 0
|
||||
>> Executed Migrations: 0
|
||||
>> Available Migrations: 0
|
||||
>> New Migrations: 0
|
||||
|
||||
Now, you can start working with migrations by generating a new blank migration
|
||||
class. Later, you'll learn how Doctrine can generate migrations automatically
|
||||
for you.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:generate
|
||||
Generated new migration class to "/path/to/project/app/DoctrineMigrations/Version20100621140655.php"
|
||||
|
||||
Have a look at the newly generated migration class and you will see something
|
||||
like the following::
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration,
|
||||
Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
class Version20100621140655 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
If you run the ``status`` command it will now show that you have one new
|
||||
migration to execute:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:status --show-versions
|
||||
|
||||
== Configuration
|
||||
|
||||
>> Name: Application Migrations
|
||||
>> Configuration Source: manually configured
|
||||
>> Version Table Name: migration_versions
|
||||
>> Migrations Namespace: Application\Migrations
|
||||
>> Migrations Directory: /path/to/project/app/DoctrineMigrations
|
||||
>> Current Version: 0
|
||||
>> Latest Version: 2010-06-21 14:06:55 (20100621140655)
|
||||
>> Executed Migrations: 0
|
||||
>> Available Migrations: 1
|
||||
>> New Migrations: 1
|
||||
|
||||
== Migration Versions
|
||||
|
||||
>> 2010-06-21 14:06:55 (20100621140655) not migrated
|
||||
|
||||
Now you can add some migration code to the ``up()`` and ``down()`` methods and
|
||||
finally migrate when you're ready:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:migrate 20100621140655
|
||||
|
||||
For more information on how to write the migrations themselves (i.e. how to
|
||||
fill in the ``up()`` and ``down()`` methods), see the official Doctrine Migrations
|
||||
`documentation`_.
|
||||
|
||||
Running Migrations during Deployment
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Of course, the end goal of writing migrations is to be able to use them to
|
||||
reliably update your database structure when you deploy your application.
|
||||
By running the migrations locally (or on a beta server), you can ensure that
|
||||
the migrations work as you expect.
|
||||
|
||||
When you do finally deploy your application, you just need to remember to run
|
||||
the ``doctrine:migrations:migrate`` command. Internally, Doctrine creates
|
||||
a ``migration_versions`` table inside your database and tracks which migrations
|
||||
have been executed there. So, no matter how many migrations you've created
|
||||
and executed locally, when you run the command during deployment, Doctrine
|
||||
will know exactly which migrations it hasn't run yet by looking at the ``migration_versions``
|
||||
table of your production database. Regardless of what server you're on, you
|
||||
can always safely run this command to execute only the migrations that haven't
|
||||
been run yet on *that* particular database.
|
||||
|
||||
Skipping Migrations
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
You can skip single migrations by explicitely adding them to the ``migration_versions`` table:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:version YYYYMMDDHHMMSS --add
|
||||
|
||||
Doctrine will then assume that this migration has already been run and will ignore it.
|
||||
|
||||
|
||||
Generating Migrations Automatically
|
||||
-----------------------------------
|
||||
|
||||
In reality, you should rarely need to write migrations manually, as the migrations
|
||||
library can generate migration classes automatically by comparing your Doctrine
|
||||
mapping information (i.e. what your database *should* look like) with your
|
||||
actual current database structure.
|
||||
|
||||
For example, suppose you create a new ``User`` entity and add mapping information
|
||||
for Doctrine's ORM:
|
||||
|
||||
.. configuration-block::
|
||||
|
||||
.. code-block:: php-annotations
|
||||
|
||||
// src/Acme/HelloBundle/Entity/User.php
|
||||
namespace Acme\HelloBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="hello_user")
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
protected $name;
|
||||
}
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# src/Acme/HelloBundle/Resources/config/doctrine/User.orm.yml
|
||||
Acme\HelloBundle\Entity\User:
|
||||
type: entity
|
||||
table: hello_user
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
name:
|
||||
type: string
|
||||
length: 255
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<!-- src/Acme/HelloBundle/Resources/config/doctrine/User.orm.xml -->
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<entity name="Acme\HelloBundle\Entity\User" table="hello_user">
|
||||
<id name="id" type="integer" column="id">
|
||||
<generator strategy="AUTO"/>
|
||||
</id>
|
||||
<field name="name" column="name" type="string" length="255" />
|
||||
</entity>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
||||
With this information, Doctrine is now ready to help you persist your new
|
||||
``User`` object to and from the ``hello_user`` table. Of course, this table
|
||||
doesn't exist yet! Generate a new migration for this table automatically by
|
||||
running the following command:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:diff
|
||||
|
||||
You should see a message that a new migration class was generated based on
|
||||
the schema differences. If you open this file, you'll find that it has the
|
||||
SQL code needed to create the ``hello_user`` table. Next, run the migration
|
||||
to add the table to your database:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:migrate
|
||||
|
||||
The moral of the story is this: after each change you make to your Doctrine
|
||||
mapping information, run the ``doctrine:migrations:diff`` command to automatically
|
||||
generate your migration classes.
|
||||
|
||||
If you do this from the very beginning of your project (i.e. so that even
|
||||
the first tables were loaded via a migration class), you'll always be able
|
||||
to create a fresh database and run your migrations in order to get your database
|
||||
schema fully up to date. In fact, this is an easy and dependable workflow
|
||||
for your project.
|
||||
|
||||
If you don't want to use this workflow and instead create your schema via
|
||||
``doctrine:schema:create``, you can tell Doctrine to skip all existing migrations:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ php app/console doctrine:migrations:version --add --all
|
||||
|
||||
Otherwise Doctrine will try to run all migrations, which probably will not work.
|
||||
|
||||
Container Aware Migrations
|
||||
--------------------------
|
||||
|
||||
In some cases you might need access to the container to ensure the proper update of
|
||||
your data structure. This could be necessary to update relations with some specific
|
||||
logic or to create new entities.
|
||||
|
||||
Therefore you can just implement the ContainerAwareInterface with its needed methods
|
||||
to get full access to the container or ContainerAwareTrait if you use Symfony >= 2.4.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// ...
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class Version20130326212938 extends AbstractMigration implements ContainerAwareInterface
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// ... migration content
|
||||
}
|
||||
|
||||
public function postUp(Schema $schema)
|
||||
{
|
||||
$converter = $this->container->get('my_service.convert_data_to');
|
||||
// ... convert the data from markdown to html for instance
|
||||
}
|
||||
}
|
||||
|
||||
With the trait
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// ...
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
|
||||
class Version20130326212938 extends AbstractMigration implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// ... migration content
|
||||
}
|
||||
|
||||
public function postUp(Schema $schema)
|
||||
{
|
||||
$converter = $this->container->get('my_service.convert_data_to');
|
||||
// ... convert the data from markdown to html for instance
|
||||
}
|
||||
}
|
||||
|
||||
Manual Tables
|
||||
-------------
|
||||
|
||||
It is a common use case, that in addition to your generated database structure
|
||||
based on your doctrine entities you might need custom tables. By default such
|
||||
tables will be removed by the doctrine:migrations:diff command.
|
||||
|
||||
If you follow a specific scheme you can configure doctrine/dbal to ignore those
|
||||
tables. Let's say all custom tables will be prefixed by ``t_``. In this case you
|
||||
just have to add the following configuration option to your doctrine configuration:
|
||||
|
||||
.. configuration-block::
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
doctrine:
|
||||
dbal:
|
||||
schema_filter: ~^(?!t_)~
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<doctrine:dbal schema-filter="~^(?!t_)~" ... />
|
||||
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$container->loadFromExtension('doctrine', array(
|
||||
'dbal' => array(
|
||||
'schema_filter' => '~^(?!t_)~',
|
||||
// ...
|
||||
),
|
||||
// ...
|
||||
));
|
||||
|
||||
This ignores the tables on the DBAL level and they will be ignored by the diff command.
|
||||
|
||||
Note that if you have multiple connections configured then the ``schema_filter`` configuration
|
||||
will need to be placed per-connection.
|
||||
|
||||
.. _documentation: http://docs.doctrine-project.org/projects/doctrine-migrations/en/latest/index.html
|
||||
.. _DoctrineMigrationsBundle: https://github.com/doctrine/DoctrineMigrationsBundle
|
||||
.. _`Doctrine Database Migrations`: https://github.com/doctrine/migrations
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection;
|
||||
|
||||
use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension;
|
||||
use Doctrine\DBAL\Migrations\Configuration\Configuration;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
class DoctrineMigrationsExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testOrganizeMigrations()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$extension = new DoctrineMigrationsExtension();
|
||||
|
||||
$config = array(
|
||||
'organize_migrations' => 'BY_YEAR',
|
||||
);
|
||||
|
||||
$extension->load(array('doctrine_migrations' => $config), $container);
|
||||
|
||||
$this->assertEquals(Configuration::VERSIONS_ORGANIZATION_BY_YEAR, $container->getParameter('doctrine_migrations.organize_migrations'));
|
||||
}
|
||||
|
||||
private function getContainer()
|
||||
{
|
||||
return new ContainerBuilder(new ParameterBag(array(
|
||||
'kernel.debug' => false,
|
||||
'kernel.bundles' => array(),
|
||||
'kernel.cache_dir' => sys_get_temp_dir(),
|
||||
'kernel.environment' => 'test',
|
||||
'kernel.root_dir' => __DIR__.'/../../', // src dir
|
||||
)));
|
||||
}
|
||||
}
|
||||
39
vendor/doctrine/doctrine-migrations-bundle/composer.json
vendored
Normal file
39
vendor/doctrine/doctrine-migrations-bundle/composer.json
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "doctrine/doctrine-migrations-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "Symfony DoctrineMigrationsBundle",
|
||||
"keywords": ["DBAL", "Migrations", "Schema"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Doctrine Project",
|
||||
"homepage": "http://www.doctrine-project.org"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"symfony/framework-bundle": "~2.3|~3.0",
|
||||
"doctrine/doctrine-bundle": "~1.0",
|
||||
"doctrine/migrations": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Doctrine\\Bundle\\MigrationsBundle\\": "" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
20
vendor/doctrine/doctrine-migrations-bundle/phpunit.xml.dist
vendored
Normal file
20
vendor/doctrine/doctrine-migrations-bundle/phpunit.xml.dist
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit colors="true" bootstrap="vendor/autoload.php">
|
||||
<testsuites>
|
||||
<testsuite name="DoctrineMigrationsBundle for the Symfony Framework">
|
||||
<directory>./Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>.</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
Loading…
Add table
Add a link
Reference in a new issue