From dec767e2b9ef2538b29e8e820d51bd548a6ba99d Mon Sep 17 00:00:00 2001 From: David Sevilla Martin <6401250+dsevillamartin@users.noreply.github.com> Date: Sun, 15 Oct 2023 20:07:29 -0400 Subject: [PATCH] Fix error when migrating with existing `webhooks.tag_id` foreign (#65) --- ..._06_07_000000_remove_tag_id_constraint.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 migrations/2023_06_07_000000_remove_tag_id_constraint.php diff --git a/migrations/2023_06_07_000000_remove_tag_id_constraint.php b/migrations/2023_06_07_000000_remove_tag_id_constraint.php new file mode 100644 index 0000000..6614057 --- /dev/null +++ b/migrations/2023_06_07_000000_remove_tag_id_constraint.php @@ -0,0 +1,38 @@ + 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) { + // + }, +];