<?php

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

class CreateNodes extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('nodes', function (Blueprint $table) {
			$table->increments('id');
			$table->timestamps();
			$table->integer('zone_id')->index();
			$table->integer('region_id')->nullable();
			$table->integer('host_id')->index();
			$table->integer('hub_id')->nullable()->index();
			$table->integer('node_id')->index();
			$table->integer('point_id')->default(0);

			$table->boolean('active');
			$table->string('status')->nullable();
			$table->string('system');
			$table->string('sysop');
			$table->string('location');
			$table->integer('baud');
			$table->string('phone')->nullable();
			$table->binary('zt',10)->nullable();

			$table->unique(['zone_id','host_id','node_id','point_id']);
			$table->unique(['zone_id','zt']);

			$table->foreign('zone_id')->references('id')->on('zones');

//			$table->unique(['zone_id','host_id','id']);
//			$table->index(['zone_id','host_id']);
//			$table->index(['zone_id','id']);
//			$table->foreign(['zone_id','host_id'])->references(['zone_id','id'])->on('nodes');
		});

	}

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