<?php

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

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('phone');
            $table->unsignedBigInteger('order_id');
            $table->unsignedBigInteger('device_id');
            $table->timestamps();
            $table->unsignedInteger('query_order')->default(0);
            $table->foreign('order_id')
                ->references('id')
                ->on('orders');
            $table->foreign('device_id')
                ->references('id')
                ->on('devices');

            $table->index(['order_id', 'device_id']);

        });

    }

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