for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/
declare(strict_types=1);
namespace Cycle\Migrations\Operation\Table;
use Cycle\Database\Driver\HandlerInterface;
use Cycle\Migrations\CapsuleInterface;
use Cycle\Migrations\Exception\Operation\TableException;
use Cycle\Migrations\Operation\AbstractOperation;
final class Rename extends AbstractOperation
{
/** @var string */
private $newName = '';
* @param string $table
* @param string $newName
public function __construct(string $table, string $newName)
parent::__construct($table);
$this->newName = $newName;
}
* {@inheritdoc}
public function execute(CapsuleInterface $capsule): void
$schema = $capsule->getSchema($this->getTable());
$database = $this->database ?? '[default]';
database
Cycle\Migrations\Operation\Table\Rename
if (!$schema->exists()) {
throw new TableException(
"Unable to rename table '{$database}'.'{$this->getTable()}', table does not exists"
);
if ($capsule->getDatabase()->hasTable($this->newName)) {
"Unable to rename table '{$database}'.'{$this->getTable()}', table '{$this->newName}' already exists"
$schema->setName($this->newName);
$schema->save(HandlerInterface::DO_ALL);