<?php

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

class CreateTablePropertyGroupAndPropertyGroupMappingTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        DB::statement("
         CREATE TABLE `property_group` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `name` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
        `type` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'MyWeb: MYW, BookingEngine: BE',
        `status` tinyint(3) unsigned 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
        )
       ");

        DB::statement("
         CREATE TABLE `property_group_mapping` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `property_id` int(10) unsigned NOT NULL,
        `property_group_id` int(10) unsigned NOT NULL,
        `order_number` int(10) unsigned NOT NULL,
        `status` tinyint(1) unsigned 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 ( `property_id` ) REFERENCES `property` ( `id` ) ON DELETE RESTRICT ON UPDATE RESTRICT,
        FOREIGN KEY ( `property_group_id` ) REFERENCES `property_group` ( `id` ) ON DELETE RESTRICT ON UPDATE RESTRICT,
        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
        )
       ");
    }

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

    }
}
