2017-06-09 02:28:26 +08:00
|
|
|
<?php
|
|
|
|
|
2017-12-10 11:21:49 +08:00
|
|
|
use App\Models\Migrations\Migration;
|
2017-06-09 02:28:26 +08:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
|
|
|
|
class CreateUsersTable extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
Schema::create('users', function (Blueprint $table) {
|
2017-06-25 02:30:13 +08:00
|
|
|
$table->increments('id');
|
2017-06-11 09:10:31 +08:00
|
|
|
$table->string('name')->nullable();
|
2017-06-09 02:28:26 +08:00
|
|
|
$table->string('email')->unique();
|
|
|
|
$table->string('password');
|
2017-12-12 12:05:22 +08:00
|
|
|
$table->string('apikey', 40)->nullable();
|
2017-06-22 00:40:08 +08:00
|
|
|
$table->integer('airline_id')->nullable()->unsigned();
|
2017-06-22 02:44:30 +08:00
|
|
|
$table->integer('rank_id')->nullable()->unsigned();
|
2017-12-01 10:28:45 +08:00
|
|
|
$table->string('home_airport_id', 5)->nullable();
|
|
|
|
$table->string('curr_airport_id', 5)->nullable();
|
2017-12-13 02:43:58 +08:00
|
|
|
$table->string('last_pirep_id')->nullable();
|
2017-07-04 14:05:37 +08:00
|
|
|
$table->bigInteger('flights')->unsigned()->default(0);
|
|
|
|
$table->bigInteger('flight_time')->unsigned()->default(0);
|
2017-06-22 00:40:08 +08:00
|
|
|
$table->decimal('balance', 19, 2)->nullable();
|
2017-12-07 06:07:25 +08:00
|
|
|
$table->string('timezone', 64)->nullable();
|
2017-06-22 00:40:08 +08:00
|
|
|
$table->boolean('active')->nullable();
|
2017-06-09 02:28:26 +08:00
|
|
|
$table->rememberToken();
|
|
|
|
$table->timestamps();
|
2017-06-22 00:40:08 +08:00
|
|
|
$table->softDeletes();
|
2017-06-23 10:44:49 +08:00
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
$table->index('email');
|
2017-12-12 12:05:22 +08:00
|
|
|
$table->index('apikey');
|
2017-06-09 02:28:26 +08:00
|
|
|
});
|
2017-06-11 09:10:31 +08:00
|
|
|
|
|
|
|
// 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) {
|
2017-06-25 02:30:13 +08:00
|
|
|
$table->integer('user_id')->unsigned();
|
2017-06-11 09:10:31 +08:00
|
|
|
$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']);
|
2017-06-23 10:44:49 +08:00
|
|
|
$table->index(['role_id', 'user_id']);
|
2017-06-11 09:10:31 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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-12-10 11:21:49 +08:00
|
|
|
$roles = [
|
|
|
|
[
|
|
|
|
'id' => 1,
|
|
|
|
'name' => 'admin',
|
|
|
|
'display_name' => 'Administrators',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 2,
|
|
|
|
'name' => 'user',
|
|
|
|
'display_name' => 'Pilot'
|
|
|
|
],
|
|
|
|
];
|
2017-06-11 09:10:31 +08:00
|
|
|
|
2017-12-10 11:21:49 +08:00
|
|
|
|
|
|
|
$this->addData('roles', $roles);
|
2017-06-09 02:28:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
2017-12-13 01:49:35 +08:00
|
|
|
Schema::dropIfExists('users');
|
|
|
|
Schema::dropIfExists('permission_role');
|
|
|
|
Schema::dropIfExists('permissions');
|
|
|
|
Schema::dropIfExists('role_user');
|
|
|
|
Schema::dropIfExists('roles');
|
2017-06-09 02:28:26 +08:00
|
|
|
}
|
|
|
|
}
|