<?php
/* 
 * Migrations generated by: Skipper (http://www.skipper18.com)
 * Migration id: 46c0a901-82c6-46b0-b5b2-c384b35596e4
 * Migration datetime: 2022-03-18 14:22:24.400151
 */ 

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

class SkipperMigrations2022031814222440 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('config', function (Blueprint $table) {
            $table->bigInteger('id')->autoIncrement()->unsigned();
            $table->bigInteger('azienda_id')->nullable(true)->unsigned();
            $table->string('key')->nullable(true);
            $table->string('group')->nullable(true);
            $table->string('display_name')->nullable(true);
            $table->longText('value')->nullable(true);
            $table->integer('order')->nullable(true);
            $table->string('type')->nullable(true);
            $table->timestamp('created_at')->nullable(true);
            $table->timestamp('updated_at')->nullable(true);
        });
        Schema::create('user', function (Blueprint $table) {
            $table->bigInteger('id')->autoIncrement()->unsigned();
            $table->integer('redmine_id')->nullable(true);
            $table->bigInteger('azienda_id')->nullable(true)->unsigned();
            $table->binary('firma')->nullable(true);
            $table->timestamp('created_at')->nullable(true);
            $table->timestamp('updated_at')->nullable(true);
        });
        Schema::table('config', function (Blueprint $table) {
            $table->foreign('azienda_id')->references('id')->on('azienda')->onDelete('cascade');
        });
        Schema::table('user', function (Blueprint $table) {
            $table->foreign('azienda_id')->references('id')->on('azienda')->onDelete('cascade');
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasTable('user')) {
            Schema::table('user', function (Blueprint $table) {
                $table->dropForeign(['azienda_id']);
            });
        }
        if (Schema::hasTable('config')) {
            Schema::table('config', function (Blueprint $table) {
                $table->dropForeign(['azienda_id']);
            });
        }
        Schema::dropIfExists('user');
        Schema::dropIfExists('config');
    }
}
