Browse Source

update migration

jqh 4 years ago
parent
commit
46c82be81c
1 changed files with 32 additions and 25 deletions
  1. 32 25
      database/migrations/2016_01_04_173148_create_admin_tables.php

+ 32 - 25
database/migrations/2016_01_04_173148_create_admin_tables.php

@@ -2,9 +2,20 @@
 
 use Illuminate\Database\Migrations\Migration;
 use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
 
 class CreateAdminTables extends Migration
 {
+    public function getConnection()
+    {
+        return config('database.connection') ?: config('database.default');
+    }
+    
+    public function config($key)
+    {
+        return config('admin.'.$key);
+    }
+
     /**
      * Run the migrations.
      *
@@ -12,26 +23,24 @@ class CreateAdminTables extends Migration
      */
     public function up()
     {
-        $connection = config('admin.database.connection') ?: config('database.default');
-
-        Schema::connection($connection)->create(config('admin.database.users_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.users_table'), function (Blueprint $table) {
             $table->bigIncrements('id');
-            $table->string('username', 190)->unique();
-            $table->string('password', 60);
+            $table->string('username', 120)->unique();
+            $table->string('password', 80);
             $table->string('name');
             $table->string('avatar')->nullable();
             $table->string('remember_token', 100)->nullable();
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.roles_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.roles_table'), function (Blueprint $table) {
             $table->bigIncrements('id');
             $table->string('name', 50);
             $table->string('slug', 50)->unique();
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.permissions_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.permissions_table'), function (Blueprint $table) {
             $table->bigIncrements('id');
             $table->string('name', 50);
             $table->string('slug', 50)->unique();
@@ -42,7 +51,7 @@ class CreateAdminTables extends Migration
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.menu_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.menu_table'), function (Blueprint $table) {
             $table->bigIncrements('id');
             $table->bigInteger('parent_id')->default(0);
             $table->integer('order')->default(0);
@@ -53,35 +62,35 @@ class CreateAdminTables extends Migration
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.role_users_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.role_users_table'), function (Blueprint $table) {
             $table->bigInteger('role_id');
             $table->bigInteger('user_id');
             $table->unique(['role_id', 'user_id']);
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.role_permissions_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.role_permissions_table'), function (Blueprint $table) {
             $table->bigInteger('role_id');
             $table->bigInteger('permission_id');
             $table->unique(['role_id', 'permission_id']);
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.role_menu_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.role_menu_table'), function (Blueprint $table) {
             $table->bigInteger('role_id');
             $table->bigInteger('menu_id');
             $table->unique(['role_id', 'menu_id']);
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.permission_menu_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.permission_menu_table'), function (Blueprint $table) {
             $table->bigInteger('permission_id');
             $table->bigInteger('menu_id');
             $table->unique(['permission_id', 'menu_id']);
             $table->timestamps();
         });
 
-        Schema::connection($connection)->create(config('admin.database.operation_log_table'), function (Blueprint $table) {
+        Schema::create($this->config('database.operation_log_table'), function (Blueprint $table) {
             $table->bigIncrements('id');
             $table->bigInteger('user_id');
             $table->string('path');
@@ -100,17 +109,15 @@ class CreateAdminTables extends Migration
      */
     public function down()
     {
-        $connection = config('admin.database.connection') ?: config('database.default');
-
-        Schema::connection($connection)->dropIfExists(config('admin.database.users_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.roles_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.permissions_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.menu_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.user_permissions_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.role_users_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.role_permissions_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.role_menu_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.permission_menu_table'));
-        Schema::connection($connection)->dropIfExists(config('admin.database.operation_log_table'));
+        Schema::dropIfExists($this->config('database.users_table'));
+        Schema::dropIfExists($this->config('database.roles_table'));
+        Schema::dropIfExists($this->config('database.permissions_table'));
+        Schema::dropIfExists($this->config('database.menu_table'));
+        Schema::dropIfExists($this->config('database.user_permissions_table'));
+        Schema::dropIfExists($this->config('database.role_users_table'));
+        Schema::dropIfExists($this->config('database.role_permissions_table'));
+        Schema::dropIfExists($this->config('database.role_menu_table'));
+        Schema::dropIfExists($this->config('database.permission_menu_table'));
+        Schema::dropIfExists($this->config('database.operation_log_table'));
     }
 }