From e8df6f7103bfbf580a1fec132f47439d96550ac4 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 18 Aug 2021 00:13:25 +1000 Subject: [PATCH] Default zone only when default=true --- database/migrations/2021_08_08_125817_default_route.php | 2 +- database/migrations/2021_08_15_134329_default_zones.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/database/migrations/2021_08_08_125817_default_route.php b/database/migrations/2021_08_08_125817_default_route.php index f84119e..ee598a7 100644 --- a/database/migrations/2021_08_08_125817_default_route.php +++ b/database/migrations/2021_08_08_125817_default_route.php @@ -27,7 +27,7 @@ class DefaultRoute extends Migration */ public function down() { - DB::statement("DROP UNIQUE INDEX default_zone"); + DB::statement("DROP INDEX default_zone"); Schema::table('system_zone', function (Blueprint $table) { $table->dropColumn('default'); diff --git a/database/migrations/2021_08_15_134329_default_zones.php b/database/migrations/2021_08_15_134329_default_zones.php index 1d03a5a..a6d18f0 100644 --- a/database/migrations/2021_08_15_134329_default_zones.php +++ b/database/migrations/2021_08_15_134329_default_zones.php @@ -19,8 +19,9 @@ class DefaultZones extends Migration Schema::table('zones', function (Blueprint $table) { $table->boolean('default')->default(FALSE); - $table->unique(['zone_id','default']); }); + + DB::statement('CREATE UNIQUE INDEX default_zones ON zones (zone_id) WHERE "default" = true'); } /** @@ -30,12 +31,13 @@ class DefaultZones extends Migration */ public function down() { + DB::statement("DROP INDEX default_zones"); + Schema::table('zones', function (Blueprint $table) { - $table->dropUnique(['zone_id','default']); $table->dropColumn('default'); }); - Schema::table('zones', function (Blueprint $table) { + Schema::table('domains', function (Blueprint $table) { $table->boolean('default')->default(FALSE); }); }