<?php

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

class CreateSuppliers extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('suppliers', function (Blueprint $table) {
            $table->integer('id',TRUE)->unsigned();
			$table->boolean('active');
			$table->string('name')->unique();
			$table->string('address1');
			$table->string('address2')->nullable();
			$table->string('city',64);
			$table->string('state',32);
			$table->string('postcode',8);
        });

		Schema::create('supplier_details', function (Blueprint $table) {
			$table->integer('id',TRUE)->unsigned();
			$table->timestamps();
			$table->text('notes')->nullable();
			$table->string('accounts')->nullable();
			$table->string('support')->nullable();
			$table->string('payments')->nullable();

			$table->integer('supplier_id')->unsigned();
			$table->integer('site_id');

			$table->unique(['supplier_id','site_id']);

			$table->foreign(['supplier_id'])->references(['id'])->on('suppliers');
			$table->foreign(['site_id'])->references(['id'])->on('sites');
		});
    }

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