-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error when migrating with existing
webhooks.tag_id
foreign (#65)
- Loading branch information
1 parent
6a39a4f
commit dec767e
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/webhooks. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\Builder; | ||
|
||
// Removes foreign key constraint for tag_id column that existed in previous versions of the extension. | ||
// Deleting the index is also necessary to prevent errors when changing the column type to JSON in the next migration. | ||
return [ | ||
'up' => static function (Builder $schema) { | ||
$schema->table('webhooks', function (Blueprint $table) use ($schema) { | ||
$indexes = $schema->getConnection()->getDoctrineSchemaManager()->listTableIndexes($table->getTable()); | ||
|
||
/** | ||
* @var \Doctrine\DBAL\Schema\Index $index | ||
*/ | ||
$index = collect($indexes)->first(function ($index) { | ||
return in_array('tag_id', $index->getColumns(), true); | ||
}); | ||
|
||
if ($index) { | ||
$table->dropForeign(['tag_id']); | ||
$table->dropIndex($index->getName()); | ||
} | ||
}); | ||
}, | ||
'down' => static function (Builder $schema) { | ||
// | ||
}, | ||
]; |