<?php

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

class Latencies extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        /* Network */
        Schema::create('latency_locations', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->softDeletes();

            $table->string('name');
        });

        DB::table('latency_locations')->insert([
            ['name' => 'Brisbane'],
            ['name' => 'Sydney'],
            ['name' => 'Melbourne'],
            ['name' => 'Adelaide'],
            ['name' => 'Perth'],
            ['name' => 'Auckland'],
            ['name' => 'Tokyo'],
            ['name' => 'Singapore'],
            ['name' => 'Hong Kong'],
            ['name' => 'Frankfurt'],
            ['name' => 'Amsterdam'],
            ['name' => 'Marseille'],
            ['name' => 'Los Angeles'],
            ['name' => 'Chicago'],
            ['name' => 'New York'],
            ['name' => 'Ashburn'],
            ['name' => 'Dallas'],
        ]);

        Schema::create('static_latencies', function (Blueprint $table) {
            $table->timestamps();

            $table->integer('location_a');
            $table->integer('location_b');

            $table->primary(['location_a', 'location_b']);

            $table->float('latency', 9, 2);
        });

        Schema::create('dynamic_latencies', function (Blueprint $table) {
            $table->timestamps();

            $table->integer('location_a');
            $table->integer('location_b');

            $table->primary(['location_a', 'location_b']);

            $table->float('latency', 9, 2);
        });
        
    }

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