Skip to content

Commit

Permalink
Fix index down migration (#172)
Browse files Browse the repository at this point in the history
* Fix index down migration #160

* Apply fixes from StyleCI

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
clarkwinkelmann and StyleCIBot authored May 13, 2022
1 parent 9df3eae commit ac5fdff
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion migrations/2021_01_13_000000_unified_index_index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
use Illuminate\Support\Arr;

return [
'up' => function (Builder $schema) {
Expand All @@ -19,7 +20,19 @@
});
},
'down' => function (Builder $schema) {
$schema->table('users', function (Blueprint $table) {
$schema->table('users', function (Blueprint $table) use ($schema) {
$connection = $schema->getConnection();
$schemaManager = $connection->getDoctrineSchemaManager();
$existingIndexes = $schemaManager->listTableIndexes($table->getTable());

// If migration 2021_04_21_000000_drop_users_unified_index_column has been applied, this index already no longer exists
// Unfortunately we can't call the protected createIndexName method so we have to build the index name manually
$indexName = strtolower(str_replace(['-', '.'], '_', $connection->getTablePrefix().$table->getTable()).'_unified_index_with_byobu_index');

if (!Arr::exists($existingIndexes, $indexName)) {
return;
}

// Use array syntax so the blueprint "guesses" the full index name
$table->dropIndex(['unified_index_with_byobu']);
});
Expand Down

0 comments on commit ac5fdff

Please sign in to comment.