<?php

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

class CreateDocumentsTableOnEpac extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::connection('site_epac')->create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('nom')->nullable(false);
            $table->string('slug')->nullable(false);
            $table->unsignedBigInteger('departement_id')->nullable(false);
          //  $table->foreign('departement_id')->references('id')->on('departements')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });

        Schema::connection('site_epac')->create('documents', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('departement_id')->nullable(false);
          //  $table->foreign('departement_id')->references('id')->on('departements')->onDelete('cascade');
            $table->unsignedBigInteger('user_id')->nullable(false);
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->unsignedBigInteger('categorie_id')->nullable(false);
            $table->foreign('categorie_id')->references('id')->on('categories')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::connection('site_epac')->dropIfExists('documents');
        Schema::connection('site_epac')->dropIfExists('categories');
    }
}
