<?php

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

class AddExternalAccount extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
		Schema::create('external_account', function (Blueprint $table) {
			$table->bigInteger('account_id');
			$table->integer('site_id')->nullable();
			$table->integer('external_integration_id')->unsigned();
			$table->string('link');

			$table->foreign('site_id')->references('id')->on('ab_setup');
			$table->foreign('external_integration_id')->references('id')->on('external_integrations');
			$table->foreign('account_id')->references('id')->on('ab_account');

			$table->unique(['site_id','account_id','external_integration_id'],'sae');
		});
    }

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