Permalink
Browse files

added doctrine migrations

  • Loading branch information...
1 parent 432f27b commit f9e6557d9dbbc80505d2547094102cbdd66f9e86 Michael committed Oct 20, 2011
Showing with 2,419 additions and 18 deletions.
  1. +10 −14 application/Bootstrap.php
  2. +9 −4 bin/doctrine.php
  3. +3 −0 bin/migration-apply.php
  4. +3 −0 bin/migration-create.php
  5. +3 −0 bin/migration-dry.php
  6. +3 −0 bin/migration-status.php
  7. +4 −0 bin/migrations.yml
  8. 0 data/migrations/.gitignore
  9. +3 −0 library/App/Entity/Quote.php
  10. +8 −0 library/Doctrine/DBAL/Migrations/AbortMigrationException.php
  11. +178 −0 library/Doctrine/DBAL/Migrations/AbstractMigration.php
  12. +93 −0 library/Doctrine/DBAL/Migrations/Configuration/AbstractFileConfiguration.php
  13. +508 −0 library/Doctrine/DBAL/Migrations/Configuration/Configuration.php
  14. +58 −0 library/Doctrine/DBAL/Migrations/Configuration/XmlConfiguration.php
  15. +61 −0 library/Doctrine/DBAL/Migrations/Configuration/YamlConfiguration.php
  16. +33 −0 library/Doctrine/DBAL/Migrations/IrreversibleMigrationException.php
  17. +160 −0 library/Doctrine/DBAL/Migrations/Migration.php
  18. +66 −0 library/Doctrine/DBAL/Migrations/MigrationException.php
  19. +26 −0 library/Doctrine/DBAL/Migrations/MigrationsVersion.php
  20. +52 −0 library/Doctrine/DBAL/Migrations/OutputWriter.php
  21. +8 −0 library/Doctrine/DBAL/Migrations/SkipMigrationException.php
  22. +122 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/AbstractCommand.php
  23. +106 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/DiffCommand.php
  24. +102 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/ExecuteCommand.php
  25. +130 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/GenerateCommand.php
  26. +107 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/MigrateCommand.php
  27. +115 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/StatusCommand.php
  28. +95 −0 library/Doctrine/DBAL/Migrations/Tools/Console/Command/VersionCommand.php
  29. +353 −0 library/Doctrine/DBAL/Migrations/Version.php
View
@@ -12,27 +12,23 @@ public function _initAutoloaderNamespaces()
require_once APPLICATION_PATH .
'/../library/Doctrine/Common/ClassLoader.php';
+ require_once APPLICATION_PATH .
+ '/../library/Symfony/Component/Di/sfServiceContainerAutoloader.php';
+
+ sfServiceContainerAutoloader::register();
$autoloader = \Zend_Loader_Autoloader::getInstance();
- $fmmAutoloader = new \Doctrine\Common\ClassLoader('Bisna');
- $autoloader->pushAutoloader(
- array($fmmAutoloader, 'loadClass'),
- 'Bisna'
- );
+ $fmmAutoloader = new \Doctrine\Common\ClassLoader('Bisna');
+ $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'Bisna');
$fmmAutoloader = new \Doctrine\Common\ClassLoader('App');
$autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'App');
- $fmmAutoloader = new \Doctrine\Common\ClassLoader('Boilerplate');
-
- $autoloader->pushAutoloader(
- array($fmmAutoloader, 'loadClass'),
- 'Boilerplate'
- );
- require_once APPLICATION_PATH .
- '/../library/Symfony/Component/Di/sfServiceContainerAutoloader.php';
+ $fmmAutoloader = new \Doctrine\Common\ClassLoader('Boilerplate');
+ $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'Boilerplate');
- sfServiceContainerAutoloader::register();
+ $fmmAutoloader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL\Migrations');
+ $autoloader->pushAutoloader(array($fmmAutoloader, 'loadClass'), 'Doctrine\DBAL\Migrations');
}
public function _initModuleLayout()
View
@@ -22,6 +22,9 @@
if (($em = $container->getEntityManager(getenv('EM') ?: $container->defaultEntityManager)) !== null) {
$helperSet['em'] = new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em);
}
+
+ $helperSet['dialog'] = new \Symfony\Component\Console\Helper\DialogHelper();
+
} catch (\Exception $e) {
$cli->renderException($e, new \Symfony\Component\Console\Output\ConsoleOutput());
}
@@ -30,11 +33,14 @@
$cli->setHelperSet(new \Symfony\Component\Console\Helper\HelperSet($helperSet));
$cli->addCommands(array(
- // DBAL Commands
new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
-
- // ORM Commands
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand(),
new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(),
new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(),
new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(),
@@ -48,7 +54,6 @@
new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(),
new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(),
-
));
$cli->run();
View
@@ -0,0 +1,3 @@
+<?php
+require_once('bootstrap.php');
+passthru('php doctrine.php migrations:migrate');
View
@@ -0,0 +1,3 @@
+<?php
+require_once('bootstrap.php');
+passthru('php doctrine.php migration:diff') . PHP_EOL;
View
@@ -0,0 +1,3 @@
+<?php
+require_once('bootstrap.php');
+passthru('php doctrine.php migrations:migrate --dry-run');
View
@@ -0,0 +1,3 @@
+<?php
+require_once('bootstrap.php');
+passthru('php doctrine.php migration:status') . PHP_EOL;
View
@@ -0,0 +1,4 @@
+name: Doctrine Migrations
+migrations_namespace: DoctrineMigrations
+table_name: doctrine_migration_versions
+migrations_directory: ../data/migrations
No changes.
@@ -48,4 +48,7 @@ public function __toString()
{
return $this->getWording();
}
+
+
+
}
@@ -0,0 +1,8 @@
+<?php
+
+namespace Doctrine\DBAL\Migrations;
+
+class AbortMigrationException extends MigrationException
+{
+
+}
@@ -0,0 +1,178 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+*/
+
+namespace Doctrine\DBAL\Migrations;
+
+use Doctrine\DBAL\Schema\Schema,
+ Doctrine\DBAL\Migrations\Configuration\Configuration,
+ Doctrine\DBAL\Migrations\Version;
+
+/**
+ * Abstract class for individual migrations to extend from.
+ *
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @since 2.0
+ * @author Jonathan H. Wage <jonwage@gmail.com>
+ */
+abstract class AbstractMigration
+{
+ /**
+ * The Migrations Configuration instance for this migration
+ *
+ * @var Configuration
+ */
+ private $configuration;
+
+ /**
+ * The OutputWriter object instance used for outputting information
+ *
+ * @var OutputWriter
+ */
+ private $outputWriter;
+
+ /**
+ * The Doctrine\DBAL\Connection instance we are migrating
+ *
+ * @var Connection
+ */
+ protected $connection;
+
+ /**
+ * Reference to the SchemaManager instance referened by $_connection
+ *
+ * @var \Doctrine\DBAL\Schema\AbstractSchemaManager
+ */
+ protected $sm;
+
+ /**
+ * Reference to the DatabasePlatform instance referenced by $_conection
+ *
+ * @var \Doctrine\DBAL\Platforms\AbstractPlatform
+ */
+ protected $platform;
+
+ /**
+ * Reference to the Version instance representing this migration
+ *
+ * @var Version
+ */
+ protected $version;
+
+ public function __construct(Version $version)
+ {
+ $this->configuration = $version->getConfiguration();
+ $this->outputWriter = $this->configuration->getOutputWriter();
+ $this->connection = $this->configuration->getConnection();
+ $this->sm = $this->connection->getSchemaManager();
+ $this->platform = $this->connection->getDatabasePlatform();
+ $this->version = $version;
+ }
+
+ /**
+ * Get custom migration name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ }
+
+ abstract public function up(Schema $schema);
+ abstract public function down(Schema $schema);
+
+ protected function addSql($sql, array $params = array())
+ {
+ return $this->version->addSql($sql, $params);
+ }
+
+ protected function write($message)
+ {
+ $this->outputWriter->write($message);
+ }
+
+ protected function throwIrreversibleMigrationException($message = null)
+ {
+ if ($message === null) {
+ $message = 'This migration is irreversible and cannot be reverted.';
+ }
+ throw new IrreversibleMigrationException($message);
+ }
+
+ /**
+ * Print a warning message if the condition evalutes to TRUE.
+ *
+ * @param bool $condition
+ * @param string $message
+ */
+ public function warnIf($condition, $message = '')
+ {
+ $message = (strlen($message)) ? $message : 'Unknown Reason';
+
+ if ($condition === true) {
+ $this->outputWriter->write(' <warning>Warning during ' . $this->version->getExecutionState() . ': ' . $message . '</warning>');
+ }
+ }
+
+ /**
+ * Abort the migration if the condition evalutes to TRUE.
+ *
+ * @param bool $condition
+ * @param string $message
+ */
+ public function abortIf($condition, $message = '')
+ {
+ $message = (strlen($message)) ? $message : 'Unknown Reason';
+
+ if ($condition === true) {
+ throw new AbortMigrationException($message);
+ }
+ }
+
+ /**
+ * Skip this migration (but not the next ones) if condition evalutes to TRUE.
+ *
+ * @param bool $condition
+ * @param string $message
+ */
+ public function skipIf($condition, $message = '')
+ {
+ $message = (strlen($message)) ? $message : 'Unknown Reason';
+
+ if ($condition === true) {
+ throw new SkipMigrationException($message);
+ }
+ }
+
+ public function preUp(Schema $schema)
+ {
+ }
+
+ public function postUp(Schema $schema)
+ {
+ }
+
+ public function preDown(Schema $schema)
+ {
+ }
+
+ public function postDown(Schema $schema)
+ {
+ }
+}
@@ -0,0 +1,93 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+*/
+
+namespace Doctrine\DBAL\Migrations\Configuration;
+
+use Doctrine\DBAL\Migrations\MigrationsException;
+
+/**
+ * Abstract Migration Configuration class for loading configuration information
+ * from a configuration file (xml or yml).
+ *
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @since 2.0
+ * @author Jonathan H. Wage <jonwage@gmail.com>
+ */
+abstract class AbstractFileConfiguration extends Configuration
+{
+ /**
+ * The configuration file used to load configuration information
+ *
+ * @var string
+ */
+ private $file;
+
+ /**
+ * Whether or not the configuration file has been loaded yet or not
+ *
+ * @var bool
+ */
+ private $loaded = false;
+
+ /**
+ * Load the information from the passed configuration file
+ *
+ * @param string $file The path to the configuration file
+ * @return void
+ * @throws MigrationException $exception Throws exception if configuration file was already loaded
+ */
+ public function load($file)
+ {
+ if ($this->loaded) {
+ throw MigrationsException::configurationFileAlreadyLoaded();
+ }
+ if (file_exists($path = getcwd() . '/' . $file)) {
+ $file = $path;
+ }
+ $this->file = $file;
+ $this->doLoad($file);
+ $this->loaded = true;
+ }
+
+ protected function getDirectoryRelativeToFile($file, $input)
+ {
+ $path = realpath(dirname($file) . '/' . $input);
+ if ($path !== false) {
+ $directory = $path;
+ } else {
+ $directory = $input;
+ }
+ return $directory;
+ }
+
+ public function getFile()
+ {
+ return $this->file;
+ }
+
+ /**
+ * Abstract method that each file configuration driver must implement to
+ * load the given configuration file whether it be xml, yaml, etc. or something
+ * else.
+ *
+ * @param string $file The path to a configuration file.
+ */
+ abstract protected function doLoad($file);
+}
Oops, something went wrong.

0 comments on commit f9e6557

Please sign in to comment.