Skip to content

Commit

Permalink
Introduce Doctrine\DBAL\Migrations\AbstractMigration deprecation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed May 18, 2018
1 parent c43891c commit 231e0bb
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 165 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -31,7 +31,8 @@
},
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\Migrations\\": "lib/Doctrine/DBAL/Migrations"
"Doctrine\\DBAL\\Migrations\\": "lib/Doctrine/DBAL/Migrations",
"Doctrine\\Migrations\\": "lib/Doctrine/Migrations"
}
},
"autoload-dev": {
Expand Down
168 changes: 5 additions & 163 deletions lib/Doctrine/DBAL/Migrations/AbstractMigration.php
Expand Up @@ -2,171 +2,13 @@

namespace Doctrine\DBAL\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration as BaseAbstractMigration;

@trigger_error(sprintf('The "%s" class is deprecated since Doctrine Migrations 2.0. Use %s instead.', AbstractMigration::class, BaseAbstractMigration::class), E_USER_DEPRECATED);

/**
* 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>
* @deprecated Please use Doctrine\Migrations\AbstractMigration
*/
abstract class AbstractMigration
abstract class AbstractMigration extends BaseAbstractMigration
{
/**
* Reference to the Version instance representing this migration
*
* @var Version
*/
protected $version;

/**
* The Doctrine\DBAL\Connection instance we are migrating
*
* @var \Doctrine\DBAL\Connection
*/
protected $connection;

/**
* Reference to the SchemaManager instance referenced by $_connection
*
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
protected $sm;

/**
* Reference to the DatabasePlatform instance referenced by $_connection
*
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
protected $platform;

/**
* The OutputWriter object instance used for outputting information
*
* @var OutputWriter
*/
private $outputWriter;

public function __construct(Version $version)
{
$config = $version->getConfiguration();

$this->version = $version;
$this->connection = $config->getConnection();
$this->sm = $this->connection->getSchemaManager();
$this->platform = $this->connection->getDatabasePlatform();
$this->outputWriter = $config->getOutputWriter();
}

/**
* Indicates the transactional mode of this migration.
* If this function returns true (default) the migration will be executed in one transaction,
* otherwise non-transactional state will be used to execute each of the migration SQLs.
*
* Extending class should override this function to alter the return value
*
* @return bool TRUE by default.
*/
public function isTransactional()
{
return true;
}

/**
* Get migration description
*
* @return string
*/
public function getDescription()
{
return '';
}

/**
* Print a warning message if the condition evaluates to TRUE.
*
* @param boolean $condition
* @param string $message
*/
public function warnIf($condition, $message = '')
{
if ($condition) {
$message = $message ?: 'Unknown Reason';
$this->outputWriter->write(sprintf(
' <comment>Warning during %s: %s</comment>',
$this->version->getExecutionState(),
$message
));
}
}

/**
* Abort the migration if the condition evaluates to TRUE.
*
* @param boolean $condition
* @param string $message
*
* @throws AbortMigrationException
*/
public function abortIf($condition, $message = '')
{
if ($condition) {
throw new AbortMigrationException($message ?: 'Unknown Reason');
}
}

/**
* Skip this migration (but not the next ones) if condition evaluates to TRUE.
*
* @param boolean $condition
* @param string $message
*
* @throws SkipMigrationException
*/
public function skipIf($condition, $message = '')
{
if ($condition) {
throw new SkipMigrationException($message ?: 'Unknown Reason');
}
}

public function preUp(Schema $schema)
{
}

public function postUp(Schema $schema)
{
}

public function preDown(Schema $schema)
{
}

public function postDown(Schema $schema)
{
}

abstract public function up(Schema $schema);
abstract public function down(Schema $schema);

protected function addSql($sql, array $params = [], array $types = [])
{
$this->version->addSql($sql, $params, $types);
}

protected function write($message)
{
$this->outputWriter->write($message);
}

protected function throwIrreversibleMigrationException($message = null)
{
if (null === $message) {
$message = 'This migration is irreversible and cannot be reverted.';
}

throw new IrreversibleMigrationException($message);
}
}
Expand Up @@ -24,8 +24,8 @@ class GenerateCommand extends AbstractCommand
namespace <namespace>;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
Expand Down
168 changes: 168 additions & 0 deletions lib/Doctrine/Migrations/AbstractMigration.php
@@ -0,0 +1,168 @@
<?php

namespace Doctrine\Migrations;

use Doctrine\DBAL\Migrations\AbortMigrationException;
use Doctrine\DBAL\Migrations\IrreversibleMigrationException;
use Doctrine\DBAL\Migrations\SkipMigrationException;
use Doctrine\DBAL\Migrations\Version;
use Doctrine\DBAL\Schema\Schema;

abstract class AbstractMigration
{
/**
* Reference to the Version instance representing this migration
*
* @var Version
*/
protected $version;

/**
* The Doctrine\DBAL\Connection instance we are migrating
*
* @var \Doctrine\DBAL\Connection
*/
protected $connection;

/**
* Reference to the SchemaManager instance referenced by $_connection
*
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
protected $sm;

/**
* Reference to the DatabasePlatform instance referenced by $_connection
*
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
protected $platform;

/**
* The OutputWriter object instance used for outputting information
*
* @var OutputWriter
*/
private $outputWriter;

public function __construct(Version $version)
{
$config = $version->getConfiguration();

$this->version = $version;
$this->connection = $config->getConnection();
$this->sm = $this->connection->getSchemaManager();
$this->platform = $this->connection->getDatabasePlatform();
$this->outputWriter = $config->getOutputWriter();
}

/**
* Indicates the transactional mode of this migration.
* If this function returns true (default) the migration will be executed in one transaction,
* otherwise non-transactional state will be used to execute each of the migration SQLs.
*
* Extending class should override this function to alter the return value
*
* @return bool TRUE by default.
*/
public function isTransactional()
{
return true;
}

/**
* Get migration description
*
* @return string
*/
public function getDescription()
{
return '';
}

/**
* Print a warning message if the condition evaluates to TRUE.
*
* @param boolean $condition
* @param string $message
*/
public function warnIf($condition, $message = '')
{
if ($condition) {
$message = $message ?: 'Unknown Reason';
$this->outputWriter->write(sprintf(
' <comment>Warning during %s: %s</comment>',
$this->version->getExecutionState(),
$message
));
}
}

/**
* Abort the migration if the condition evaluates to TRUE.
*
* @param boolean $condition
* @param string $message
*
* @throws AbortMigrationException
*/
public function abortIf($condition, $message = '')
{
if ($condition) {
throw new AbortMigrationException($message ?: 'Unknown Reason');
}
}

/**
* Skip this migration (but not the next ones) if condition evaluates to TRUE.
*
* @param boolean $condition
* @param string $message
*
* @throws SkipMigrationException
*/
public function skipIf($condition, $message = '')
{
if ($condition) {
throw new SkipMigrationException($message ?: 'Unknown Reason');
}
}

public function preUp(Schema $schema)
{
}

public function postUp(Schema $schema)
{
}

public function preDown(Schema $schema)
{
}

public function postDown(Schema $schema)
{
}

abstract public function up(Schema $schema);
abstract public function down(Schema $schema);

protected function addSql($sql, array $params = [], array $types = [])
{
$this->version->addSql($sql, $params, $types);
}

protected function write($message)
{
$this->outputWriter->write($message);
}

protected function throwIrreversibleMigrationException($message = null)
{
if (null === $message) {
$message = 'This migration is irreversible and cannot be reverted.';
}

throw new IrreversibleMigrationException($message);
}
}

0 comments on commit 231e0bb

Please sign in to comment.