<?php

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

class EnhanceAdslTraffic extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
	    Schema::table('ab_service__adsl_traffic', function (Blueprint $table) {
		    $table->bigInteger('ab_service_adsl_id')->nullable();
		    $table->foreign('ab_service_adsl_id')->references('id')->on('ab_service__adsl');

		    $table->unique(['ab_service_adsl_id','date','time']);
	    });

	    DB::statement('ALTER TABLE ab_service__adsl_traffic CHANGE COLUMN service service varchar(128) DEFAULT NULL');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
	    DB::statement('ALTER TABLE ab_service__adsl_traffic CHANGE COLUMN service service varchar(128) NOT NULL');

	    Schema::table('ab_service__adsl_traffic', function (Blueprint $table) {
		    $table->dropForeign(['ab_service_adsl_id']);
		    $table->dropUnique(['ab_service_adsl_id','date','time']);
		    $table->dropColumn('ab_service_adsl_id');
	    });
    }
}
