<?php

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

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

            $table->timestamp('expiration_at');
            $table->timestamp('approved_at')->nullable();

            $table->ipAddress('address');
            $table->integer('mask');

            $table->tinyInteger('permanent_request');

            $table->string('city');
            $table->string('provider');
            $table->ipAddress('router');

            $table->text('reason')->nullable();

            $table->foreignId('organisation_id')->cascadeOnDelete()->constrained('organisations');
        });

        Schema::create('reroute_organisation_attributes', function (Blueprint $table) {
            // General characteristics - PK, timestamps, soft-deletable
            $table->id();
            $table->timestamps();

            // Foreign identifiers
            $table->foreignId('organisation_id')->cascadeOnDelete()->constrained('organisations');

            // Characteristics
            $table->bigInteger('hourly')->nullable();
            $table->bigInteger('active')->nullable();
        });
    }

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