<?php

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

class CreateProductImagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('product_images', function (Blueprint $table) {
            $table->increments('id');

            $table->unsignedInteger('product_id')->nullable()->index();

            $table->string('filename')->index();
            $table->string('original_name')->index();
            $table->string('ext')->index();
            $table->string('mine')->index();
            $table->unsignedInteger('size');
            $table->boolean('active')->default(true);
            $table->string('slug')->unique()->index();
            $table->unsignedTinyInteger('pos')->nullable()->default(0);


            $table->timestamps();

            $table->foreign('product_id')
                ->references('id')
                ->on('products')
                ->onDelete('cascade');
        });
    }

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