<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWebsiteObjectsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('website_objects', function (Blueprint $table) {
            $table->bigIncrements('website_object_id');
            $table->unsignedBigInteger('parent_id')->nullable();
            $table->unsignedBigInteger('object_id');
            $table->string('object_type', 200);
            $table->string('content_type', 50);
            $table->string('slug', 150);
            $table->string('uri', 255)->nullable();
            $table->string('template', 255)->nullable();
            $table->string('status', 20);
            $table->unsignedInteger('position')->nullable();
            $table->nullableTimestamps();

            $table->unique('slug', 'idx_website_objects_slug');
            $table->unique(['object_id', 'object_type'], 'idx_website_object');

            $table->foreign('parent_id')->references('website_object_id')
                ->on('website_objects')->onDelete('SET NULL')->onUpdate('RESTRICT');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('website_objects');
    }
}
