Add migration

This commit is contained in:
Daniel Supernault 2024-05-31 03:17:54 -06:00
parent dc6b9f4661
commit 86ac10fab7
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('instances', function (Blueprint $table) {
$schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
$indexesFound = $schemaManager->listTableIndexes('instances');
if (! array_key_exists('instances_nodeinfo_last_fetched_index', $indexesFound)) {
$table->index('nodeinfo_last_fetched');
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('instances', function (Blueprint $table) {
$schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
$indexesFound = $schemaManager->listTableIndexes('instances');
if (array_key_exists('instances_nodeinfo_last_fetched_index', $indexesFound)) {
$table->dropIndex('instances_nodeinfo_last_fetched_index');
}
});
}
};