<?php

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

class CreateCollectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('collections', function (Blueprint $table) {

            $table->bigIncrements('id');
            $table->unsignedBigInteger('backend_user_id')->nullable();
            $table->unsignedBigInteger('image_id')->nullable();
            $table->unsignedBigInteger('city_id');
            $table->unsignedBigInteger('city_zone_id')->nullable();

            $table->point('map_position');
            $table->smallInteger('map_position_zoom');
            $table->string('address_name', 255)->nullable();
            $table->text('address')->nullable();
            $table->string('website', 255)->nullable();

            $table->nullableTimestamps();

            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');

            $table->foreign('image_id')
                ->references('id')
                ->on('media_items')
                ->onDelete('SET NULL')
                ->onUpdate('CASCADE');

            $table->foreign('city_id')
                ->references('id')
                ->on('cities')
                ->onDelete('restrict');

            $table->foreign('city_zone_id')
                ->references('id')
                ->on('city_zones')
                ->onDelete('set null');
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('collections');
    }
}
