<?php

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

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

        Schema::create('goliath_rulesets', function (Blueprint $table) {

            $table->id();
            $table->timestamps();
            $table->softDeletes();
    

            $table->string('name')->nullable();
            $table->enum('type', [ 'Universal', 'Reusable' ]);
            $table->json('rules');
            $table->json('unencoded_rules')->default('[]');

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

        Schema::table('prefix_goliath_firewall', function (Blueprint $table) {
            $table->foreignId('ruleset_id')->cascadeOnDelete()->nullable()->constrained('goliath_rulesets');
        });
    }

    public function down()
    {
        Schema::dropColumns('prefix_goliath_firewall', 'ruleset_id');
        Schema::dropIfExists('goliath_rulesets');
    }
}
