diff --git a/database/migrations/2020_12_14_091314_create_port_groups_table.php b/database/migrations/2020_12_14_091314_create_port_groups_table.php index 6824fbd367..0ce090f9c2 100644 --- a/database/migrations/2020_12_14_091314_create_port_groups_table.php +++ b/database/migrations/2020_12_14_091314_create_port_groups_table.php @@ -12,16 +12,24 @@ class CreatePortGroupsTable extends Migration */ public function up() { - // drop table if exists, migration can fail when creating index. + // migration can fail when creating index if the user's SQL server isn't new enough. if (Schema::hasTable('port_groups')) { - Schema::drop('port_groups'); - } + $table = Schema::getConnection()->getDoctrineSchemaManager() + ->listTableDetails('port_groups'); - Schema::create('port_groups', function (Blueprint $table) { - $table->increments('id'); - $table->string('name')->unique(); - $table->string('desc')->nullable(); - }); + // if the table exists and the index doesn't, add the index. + if (! $table->hasIndex('port_groups_name_unique')) { + Schema::table('port_groups', function (Blueprint $table) { + $table->unique('name'); + }); + } + } else { + Schema::create('port_groups', function (Blueprint $table) { + $table->increments('id'); + $table->string('name')->unique(); + $table->string('desc')->nullable(); + }); + } } /**