<?php

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

class CreatePagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('pages', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->string('seo_title')->unique();
            $table->string('meta_description')->unique();
            $table->string('opengraph_title')->unique();
            $table->string('opengraph_image')->unique();
            $table->json('data');
            $table->enum('state', [
              Page::PAGE_DRAFT,
              Page::PAGE_LIVE,
              Page::PAGE_ARCHIVED,
            ]);
            $table->integer('author')->unsigned()->nullable();
            $table->foreign('author')->references('id')->on('users')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('pages');
    }
}
