<?php

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

class UpdateResidentialComplexesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('residential_complexes', function (Blueprint $table) {
            if (!Schema::hasColumn('residential_complexes', 'stage_of_construction_id')) {
                $table->integer('stage_of_construction_id')->unsigned()->nullable();
                $table->foreign('stage_of_construction_id')->references('id')->on('stage_of_constructions')->onDelete('set null');
            }

            if (!Schema::hasColumn('residential_complexes', 'start_of_sale')) {
                $table->tinyInteger('start_of_sale')->nullable()->default('0');
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
