Conditions | 4 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | public function up(Schema $schema): void |
||
19 | { |
||
20 | $shortUrls = $schema->getTable('short_urls'); |
||
21 | if ($shortUrls->hasIndex('unique_short_code_plus_domain')) { |
||
22 | return; |
||
23 | } |
||
24 | |||
25 | /** @var Index|null $shortCodesIndex */ |
||
26 | $shortCodesIndex = array_reduce($shortUrls->getIndexes(), function (?Index $found, Index $current) { |
||
27 | [$column] = $current->getColumns(); |
||
28 | return $column === 'short_code' ? $current : $found; |
||
29 | }); |
||
30 | if ($shortCodesIndex === null) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | $shortUrls->dropIndex($shortCodesIndex->getName()); |
||
35 | $shortUrls->addUniqueIndex(['short_code', 'domain_id'], 'unique_short_code_plus_domain'); |
||
36 | } |
||
49 |