<?php

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

class CreateVirtualDevicesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('virtual_devices', function (Blueprint $table) {
            $table->increments('id');
            $table->bigInteger('sim')->unsigned()->default(0)->comment('SIM号');
            $table->string('unique_key', 32)->unsigned()->default(0)->comment('唯一设备编号');
            $table->string('imsi', 32)->unsigned()->default(0)->comment('IMSI号');
            $table->string('imei', 32)->default("")->comment('IMEI号');
            $table->string('plant_no', 32)->default("")->comment('车牌号');
            $table->string('model', 32)->default("")->comment('型号');
            $table->decimal('first_lon', 10, 6)->default(0.000000)->comment('第一次访问经度');
            $table->decimal('first_lat', 10, 6)->default(0.000000)->comment('第一次访问纬度');
            $table->decimal('last_lon', 10, 6)->default(0.000000)->comment('最后访问经度');
            $table->decimal('last_lat', 10, 6)->default(0.000000)->comment('最后访问纬度');
            $table->string('last_location', 255)->default('')->comment('最后访问位置');
            $table->tinyInteger("type")->unsigned()->default(0)->comment('平台类型 0:广电 1:车控宝 2:微科 3:省内交通厅 4:省外交通厅 5:北斗行 99:虚拟设备');
            $table->timestamps();
            $table->unique(['unique_key']);

            $table->tinyInteger("is_lock")->unsigned()->default(0)->comment('0:未锁住 1:锁住');
            $table->tinyInteger("is_effective")->unsigned()->default(0)->comment('0:无效 1:有效');
            $table->tinyInteger("is_match")->unsigned()->default(0)->comment('0:未匹配 1:匹配');
            $table->string("cartype", 15)->default("")->comment('设备对应得车类型,0:乘用车，1:商用车，2:其它');
            $table->tinyInteger("jointdays")->unsigned()->default(0)->comment('衔接点空闲天数');
            $table->decimal('averspeed', 10, 6)->default(0.000000)->comment('平均速度');
            $table->decimal('averdrivetime', 10, 6)->default(0.000000)->comment('平均驾驶时长');
        });
    }

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