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