cycle /
migrations
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Cycle\Migrations\Operation\Table; |
||
| 6 | |||
| 7 | use Cycle\Migrations\CapsuleInterface; |
||
| 8 | use Cycle\Migrations\Exception\Operation\TableException; |
||
| 9 | use Cycle\Migrations\Operation\AbstractOperation; |
||
| 10 | |||
| 11 | final class PrimaryKeys extends AbstractOperation |
||
| 12 | { |
||
| 13 | 136 | public function __construct(string $table, private array $columns) |
|
| 14 | { |
||
| 15 | 136 | parent::__construct($table); |
|
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * {@inheritdoc} |
||
| 20 | */ |
||
| 21 | 136 | public function execute(CapsuleInterface $capsule): void |
|
| 22 | { |
||
| 23 | 136 | $schema = $capsule->getSchema($this->getTable()); |
|
| 24 | 136 | $database = $this->database ?? '[default]'; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 25 | |||
| 26 | 136 | if ($schema->exists()) { |
|
| 27 | 8 | throw new TableException( |
|
| 28 | 8 | "Unable to set primary keys for table '{$database}'.'{$this->getTable()}', table already exists" |
|
| 29 | ); |
||
| 30 | } |
||
| 31 | |||
| 32 | 136 | $schema->setPrimaryKeys($this->columns); |
|
| 33 | } |
||
| 34 | } |
||
| 35 |