<?php

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

class Echoarea extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
		Schema::create('echoareas', function (Blueprint $table) {
			$table->id();
			$table->timestamps();
			$table->softDeletes();
			$table->string('name');
			$table->string('description');
			$table->boolean('active');
			$table->boolean('public');
			$table->string('notes')->nullable();

			$table->bigInteger('domain_id');
			$table->foreign('domain_id')->references('id')->on('domains');
		});

		Schema::create('fileareas', function (Blueprint $table) {
			$table->id();
			$table->timestamps();
			$table->softDeletes();
			$table->string('name');
			$table->string('description');
			$table->boolean('active');
			$table->boolean('public');
			$table->string('notes')->nullable();

			$table->bigInteger('domain_id');
			$table->foreign('domain_id')->references('id')->on('domains');
		});

		Schema::create('address_echoarea', function (Blueprint $table) {
			$table->bigInteger('echoarea_id');
			$table->foreign('echoarea_id')->references('id')->on('echoareas');

			$table->bigInteger('address_id');
			$table->foreign('address_id')->references('id')->on('addresses');

			$table->unique(['echoarea_id','address_id']);

			$table->dateTime('subscribed');
		});

		Schema::create('address_filearea', function (Blueprint $table) {
			$table->bigInteger('filearea_id');
			$table->foreign('filearea_id')->references('id')->on('fileareas');

			$table->bigInteger('address_id');
			$table->foreign('address_id')->references('id')->on('addresses');

			$table->unique(['filearea_id','address_id']);

			$table->dateTime('subscribed');
		});
    }

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

		Schema::dropIfExists('fileareas');
		Schema::dropIfExists('echoareas');
    }
}