<?php

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

class CreateCoursesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable('courses')){
            Schema::create('courses', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('destination_id');
                $table->integer('institute_id');
                $table->integer('level_id');
                $table->string('department');
                $table->string('name');
                $table->tinyInteger('length');
                $table->decimal('ielts',3,2)->nullable();
                $table->decimal('toefl',4,2)->nullable();
                $table->decimal('pte',4,2)->nullable();
                $table->decimal('duolingo',4,2)->nullable();
                $table->decimal('tution_fee',10,2);
                $table->decimal('scholarship',8,2)->nullable();
                $table->enum('ucas_fee',[0,1])->default(0);
                $table->tinyInteger('deposit_required')->default(0);
                $table->decimal('min_gpa',3,2)->nullable();
                $table->enum('sop',[0,1])->default(1);
                $table->enum('cv',[0,1])->default(1);
                $table->tinyInteger('reference')->default(0);
                $table->timestamps();
                $table->softDeletes('deleted_at', 0);
            });
        }

        if(!Schema::hasTable('course_intakes')){
            Schema::create('course_intakes', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('course_id');
                $table->tinyInteger('intake');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('course_campuses')){
            Schema::create('course_campuses', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('course_id');
                $table->integer('campus_id');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('course_tags')){
            Schema::create('course_tags', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('course_id');
                $table->string('keyword');
                $table->timestamps();
            });
        }

        // if(!Schema::hasColumn('courses', 'reference')) {
        //     Schema::table('courses', function($table) {
        //         $table->tinyInteger('reference')->after('cv');
        //     });
        // }
    }

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

//php artisan migrate:refresh --path=/database/migrations/2020_07_25_171829_create_courses_table.php
