<?php

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

class CreateUser2groupTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user2group', function (Blueprint $table) {
            $table->integer('useroid')->unsigned();
            $table->integer('groupoid')->unsigned();

            $table->foreign('useroid')->references('oid')->on('user')->onDelete('cascade');
            $table->foreign('groupoid')->references('oid')->on('group')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS = 0');
        Schema::dropIfExists('user2group');
        DB::statement('SET FOREIGN_KEY_CHECKS = 1');
    }
}
