src/components/auth/resources/database/migrations/2013_04_12_013201_antares_auth_create_user_role_table.php
<?php
/**
* Part of the Antares package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Antares Core
* @version 0.9.0
* @author Original Orchestral https://github.com/orchestral
* @author Antares Team
* @license BSD License (3-clause)
* @copyright (c) 2017, Antares
* @link http://antaresproject.io
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class AntaresAuthCreateUserRoleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->down();
Schema::create('tbl_user_role', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->timestamps();
});
Schema::table('tbl_user_role', function (Blueprint $table) {
$table->index(['user_id', 'role_id']);
$table->foreign('user_id')->references('id')->on('tbl_users')->onUpdate('NO ACTION')->onDelete('CASCADE');
$table->foreign('role_id')->references('id')->on('tbl_roles')->onUpdate('NO ACTION')->onDelete('CASCADE');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Schema::dropIfExists('tbl_user_role');
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}
}