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)
*/
namespace Spiral\Migrations\Operations\Table;
use Spiral\Database\Entities\AbstractHandler;
use Spiral\Migrations\CapsuleInterface;
use Spiral\Migrations\Exceptions\Operations\TableException;
use Spiral\Migrations\Operations\TableOperation;
class CreateTable extends TableOperation
{
* {@inheritdoc}
public function execute(CapsuleInterface $capsule)
$schema = $capsule->getSchema($this->getTable(), $this->getDatabase());
$database = $this->database ?? '[default]';
if ($schema->exists()) {
throw new TableException(
"Unable to create table '{$database}'.'{$this->getTable()}', table already exists"
);
}
if (empty($schema->getColumns())) {
"Unable to create table '{$database}'.'{$this->getTable()}', no columns were added"
$schema->save(AbstractHandler::DO_ALL);