<?php

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

class BookingEngineMigration extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        DB::statement("
            ALTER TABLE `property_channel`
            ADD COLUMN `token` VARCHAR(45) NULL AFTER `official_name`,
            ADD UNIQUE INDEX `token_UNIQUE` (`token` ASC);
        ");

        DB::statement("
            CREATE TABLE `property_booking_engine` (
                `id` INT NOT NULL AUTO_INCREMENT,
                `property_id` INT UNSIGNED NOT NULL,
                `channel_id` INT UNSIGNED NOT NULL,
                `token` VARCHAR ( 45 ) NOT NULL,
                `status` TINYINT ( 4 ) NOT NULL DEFAULT 1,
                `created_by` INT ( 10 ) UNSIGNED NOT NULL,
                `updated_by` INT ( 10 ) UNSIGNED NOT NULL,
                `created_at` INT ( 11 ) NOT NULL,
                `updated_at` INT ( 11 ) NOT NULL,
                PRIMARY KEY ( `id` ),
                FOREIGN KEY ( `created_by` ) REFERENCES `user` ( `id` ) ON DELETE RESTRICT ON UPDATE RESTRICT,
                FOREIGN KEY ( `updated_by` ) REFERENCES `user` ( `id` ) ON DELETE RESTRICT ON UPDATE RESTRICT,
                FOREIGN KEY ( `property_id` ) REFERENCES `property` ( `id` ) ON DELETE RESTRICT ON UPDATE RESTRICT,
                FOREIGN KEY ( `channel_id` ) REFERENCES `property_channel` ( `id` ) ON DELETE RESTRICT ON UPDATE RESTRICT
            );
        ");
    }
}
