phpvms/database/migrations/2017_06_08_0000_create_users_table.php

96 lines
3.2 KiB
PHP
Raw Normal View History

2017-06-09 02:28:26 +08:00
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
2017-06-09 02:28:26 +08:00
$table->string('email')->unique();
$table->string('password');
2017-06-09 09:02:52 +08:00
$table->string('code')->nullable();
$table->string('location')->nullable();
$table->string('hub')->nullable();
$table->unsignedBigInteger('flights')->nullable();
$table->float('hours')->nullable();
$table->float('pay')->nullable();
$table->boolean('confirmed')->nullable();
$table->boolean('retired')->nullable();
$table->dateTime('last_pirep')->nullable();
2017-06-09 02:28:26 +08:00
$table->rememberToken();
$table->timestamps();
});
// Create table for storing roles
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->timestamps();
});
// Create table for associating roles to users (Many-to-Many)
Schema::create('role_user', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['user_id', 'role_id']);
});
// Create table for storing permissions
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->timestamps();
});
// Create table for associating permissions to roles (Many-to-Many)
Schema::create('permission_role', function (Blueprint $table) {
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
});
# create a default user/role
2017-06-09 02:28:26 +08:00
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
Schema::drop('permission_role');
Schema::drop('permissions');
Schema::drop('role_user');
Schema::drop('roles');
2017-06-09 02:28:26 +08:00
}
}