<?php

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

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

            $table->timestamp('started_at')->nullable();
            $table->timestamp('rounded_started_at')->nullable();
            $table->string('type')->nullable();
            $table->string('description')->nullable();
            $table->ipAddress('destination')->nullable();

            $table->foreignId('region_id')->cascadeOnDelete()->constrained('goliath_regions');
            $table->foreignId('subregion_id')->cascadeOnDelete()->constrained('goliath_subregions');
            $table->foreignId('metro_id')->cascadeOnDelete()->constrained('goliath_metro');

            $table->foreignId('appliance_id')->cascadeOnDelete()->constrained('goliath_appliances');
        });

        Schema::create('goliath_attack_prefixes', function (Blueprint $table) {
            $table->id();

            $table->foreignId('prefix_id')->cascadeOnDelete()->constrained('prefixes');
            $table->foreignId('attack_id')->cascadeOnDelete()->constrained('goliath_attacks');
        });

    }

    public function down()
    {
        Schema::dropIfExists('goliath_attack_prefixes');
        Schema::dropIfExists('goliath_attacks');

    }
}
