1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Cycle\Migrations\Operation\Index; |
||
6 | |||
7 | use Cycle\Migrations\CapsuleInterface; |
||
8 | use Cycle\Migrations\Exception\Operation\IndexException; |
||
9 | use Cycle\Migrations\Operation\Traits\OptionsTrait; |
||
10 | |||
11 | final class Alter extends Index |
||
12 | { |
||
13 | use OptionsTrait; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
14 | |||
15 | 24 | public function __construct(string $table, array $columns, array $options = []) |
|
16 | { |
||
17 | 24 | $this->options = $options; |
|
18 | 24 | parent::__construct($table, $columns); |
|
19 | } |
||
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | 24 | public function execute(CapsuleInterface $capsule): void |
|
25 | { |
||
26 | 24 | $schema = $capsule->getSchema($this->getTable()); |
|
27 | |||
28 | 24 | if (!$schema->hasIndex($this->columns)) { |
|
29 | 8 | $columns = implode(',', $this->columns); |
|
30 | 8 | throw new IndexException( |
|
31 | 8 | "Unable to alter index '{$schema->getName()}'.({$columns}), no such index" |
|
32 | ); |
||
33 | } |
||
34 | |||
35 | 16 | $schema->index($this->columns)->unique( |
|
36 | 16 | $this->getOption('unique', false) |
|
37 | ); |
||
38 | } |
||
39 | } |
||
40 |