<?php

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

class AddCurrentfilesView extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        DB::statement('create view currentfiles as
            select `f`.`iid` AS `iid`, `f`.`hash` AS `hash`
            from `files` `f`
            where `f`.`created_at` = (select max(`files`.`created_at`)
                from `files`
                group by `files`.`iid`
                having `files`.`iid` = `f`.`iid`);');

    }

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