<?php

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

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

            $table->text('identity');
            $table->text('key');

            $table->index('key', 'organisation_external_identities_key_index');
            $table->index(['key', 'identity'], 'organisation_external_identities_lookup_index');
            $table->foreignId('organisation_id')->cascadeOnDelete()->constrained('organisations');
        });

        DB::table('api_scopes')->insert([
            [ 'name' => 'api.internal.network' ],
            [ 'name' => 'api.internal.organisation' ],
        ]);
    }

    public function down()
    {
        Schema::dropIfExists('organisation_external_identities');
    }
}