<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class DefaultZones extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
		Schema::table('domains', function (Blueprint $table) {
			$table->dropColumn('default');
		});

		Schema::table('zones', function (Blueprint $table) {
			$table->boolean('default')->default(FALSE);
		});

		DB::statement('CREATE UNIQUE INDEX default_zones ON zones (zone_id) WHERE "default" = true');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
		DB::statement("DROP INDEX default_zones");

		Schema::table('zones', function (Blueprint $table) {
			$table->dropColumn('default');
		});

		Schema::table('domains', function (Blueprint $table) {
			$table->boolean('default')->default(FALSE);
		});
    }
}