Skip to content

Commit

Permalink
Fix error when migrating with existing webhooks.tag_id foreign (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Oct 16, 2023
1 parent 6a39a4f commit dec767e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions migrations/2023_06_07_000000_remove_tag_id_constraint.php
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) {
//
},
];

0 comments on commit dec767e

Please sign in to comment.