<?php

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

class NewUserRole extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('backend_roles', function (Blueprint $table) {
            $table->string('initial_path', 255)->nullable();
        });

        \DB::insert("INSERT into backend_roles (id, name, short_name) values (7, 'Projects Editor', 'projects')");
        \DB::insert("INSERT into backend_role_permission (backend_role_id, backend_permission_id) (Select 7, p.id from backend_permissions p where p.id not in (4, 8, 9, 10, 12, 33, 38, 46, 51, 52, 57, 58, 63, 64, 84, 89, 97, 102, 103, 108, 109, 114, 115))");

        \DB::table('backend_roles')->whereIn('id', [1, 2, 3, 6])->update(['initial_path' => '/admin/content/index/page']);
        \DB::table('backend_roles')->whereIn('id', [5])->update(['initial_path' => '/admin/content/index/blog_post']);
        \DB::table('backend_roles')->whereIn('id', [7])->update(['initial_path' => '/admin/content/index/project']);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('backend_roles', function (Blueprint $table) {
            $table->dropColumn('initial_path');
        });
    }
}
