-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from one2tek/2.x
Added users table to logs db (with migrations)
- Loading branch information
Showing
5 changed files
with
140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateUsersTableOnLogsDb extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
if(!Schema::connection(config('laralog.database_connection'))->hasTable('users')){ | ||
Schema::connection(config('laralog.database_connection'))->create('users', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('name',191); | ||
$table->string('role',20); | ||
$table->timestamps(); | ||
}); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
if(Schema::connection(config('laralog.database_connection'))->hasTable('users')){ | ||
Schema::connection(config('laralog.database_connection'))->dropIfExists('users'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class DropMorphFromLogsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::connection(config('laralog.database_connection'))->table(config('laralog.table_name'), function (Blueprint $table) { | ||
if(Schema::hasColumn(config('laralog.table_name'),'causer_type')){ | ||
$table->dropColumn('causer_type'); | ||
$table->dropColumn('causer_id'); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
Schema::connection(config('laralog.database_connection'))->table(config('laralog.table_name'), function (Blueprint $table) { | ||
if(!Schema::hasColumn(config('laralog.table_name'),'causer_type')){ | ||
$table->nullableMorphs('causer', 'causer')->after('subject_id'); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class LogsTableCauserIdAdd extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::connection(config('laralog.database_connection'))->table(config('laralog.table_name'), function (Blueprint $table) { | ||
if(!Schema::hasColumn(config('laralog.table_name'),'causer_id')){ | ||
$table->bigInteger('causer_id')->unsigned()->nullable()->after('subject_id'); | ||
$table->foreign('causer_id')->references('id')->on('users'); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
Schema::connection(config('laralog.database_connection'))->table(config('laralog.table_name'), function (Blueprint $table) { | ||
if(Schema::hasColumn(config('laralog.table_name'),'causer_id')){ | ||
$table->dropForeign(['causer_id']); | ||
$table->dropColumn('causer_id'); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters