<?php

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

class CreateCsMessagesTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('cs_messages')) return;

        Schema::create('cs_messages', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('business_id')->index();
            $table->unsignedInteger('site_id')->index();
            $table->string('name', 150);
            $table->string('email', 180)->nullable();
            $table->string('phone', 40)->nullable();
            $table->string('subject', 200)->nullable();
            $table->text('message')->nullable();
            $table->string('source', 60)->default('contact_form');
            $table->boolean('is_read')->default(false);
            $table->string('ip', 60)->nullable();
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('cs_messages');
    }
}
