<?php

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

class CreateZones extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('zones', function (Blueprint $table) {
			$table->id();
			$table->timestamps();

			$table->integer('zone_id');
			$table->string('description')->nullable();
			$table->boolean('active');
			$table->string('notes')->nullable();
			$table->boolean('public')->default(TRUE);

			$table->ipAddress('ipv4')->nullable();
			$table->integer('ipv4_mask')->nullable();

			$table->ipAddress('ipv6')->nullable();
			$table->integer('ipv6_mask')->nullable();

			$table->integer('domain_id')->nullable()->unique();
			$table->foreign('domain_id')->references('id')->on('domains');

			$table->binary('zt_id',10)->nullable()->unique();
			$table->foreign('zt_id')->references('id')->on('zt');

			$table->unique(['zone_id','domain_id']);
		});

	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists('zones');
	}
}