Skip to content

Commit

Permalink
🐛 Fixed database new polymorphic column
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceauKa committed Jan 3, 2020
1 parent 6b9c361 commit 9a9575a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.5.1

⚠️ Run `php artisan vendor:publish --tag=auth-checker`

- Fixed database new polymorphic column

## 1.5.0

- Users now use MorphMany instead of HasMany
Expand Down
1 change: 0 additions & 1 deletion migrations/create_devices_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class CreateDevicesTable extends Migration
Schema::create('devices', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('user_id')->unsigned();
$table->string('user_type');
$table->string('platform')->nullable();
$table->string('platform_version')->nullable();
$table->string('browser')->nullable();
Expand Down
1 change: 0 additions & 1 deletion migrations/create_logins_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class CreateLoginsTable extends Migration
$table->ipAddress('ip_address');
$table->string('type')->default(\Lab404\AuthChecker\Models\Login::TYPE_LOGIN);
$table->bigInteger('user_id')->unsigned();
$table->string('user_type');
$table->bigInteger('device_id')->unsigned()->index()->nullable();
$table->timestamps();

Expand Down
30 changes: 30 additions & 0 deletions migrations/update_logins_and_devices_table_user_relation.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class UpdateLoginsAndDevicesTableUserRelation extends Migration
{
public function up()
{
Schema::table('logins', function (Blueprint $table) {
$table->string('user_type')->after('user_id');
});

Schema::table('devices', function (Blueprint $table) {
$table->string('user_type')->after('user_id');
});
}

public function down()
{
Schema::table('logins', function (Blueprint $table) {
$table->dropColumn('user_type');
});

Schema::table('devices', function (Blueprint $table) {
$table->dropColumn('user_type');
});
}
}
18 changes: 13 additions & 5 deletions src/AuthCheckerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ public function boot(): void
__DIR__.'/../config/auth-checker.php' => config_path('auth-checker.php')
], 'auth-checker');

if (false === class_exists('CreateLoginsTable') && false === class_exists('CreateDevicesTable')) {
$this->publishes([
__DIR__.'/../migrations/create_devices_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_devices_table.php'),
__DIR__.'/../migrations/create_logins_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_logins_table.php')
], 'auth-checker');
if ($this->app->runningInConsole()) {
if (false === class_exists('CreateLoginsTable') && false === class_exists('CreateDevicesTable')) {
$this->publishes([
__DIR__.'/../migrations/create_devices_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_devices_table.php'),
__DIR__.'/../migrations/create_logins_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_logins_table.php')
], 'auth-checker');
}

if (false === class_exists('UpdateLoginsAndDevicesTableUserRelation')) {
$this->publishes([
__DIR__.'/../migrations/update_logins_and_devices_table_user_relation.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_update_logins_and_devices_table_user_relation.php'),
], 'auth-checker');
}
}

$this->mergeConfigFrom(__DIR__.'/../config/auth-checker.php', 'auth-checker');
Expand Down

0 comments on commit 9a9575a

Please sign in to comment.