Skip to content

Commit 9a9575a

Browse files
committed
🐛 Fixed database new polymorphic column
1 parent 6b9c361 commit 9a9575a

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.5.1
4+
5+
⚠️ Run `php artisan vendor:publish --tag=auth-checker`
6+
7+
- Fixed database new polymorphic column
8+
39
## 1.5.0
410

511
- Users now use MorphMany instead of HasMany

migrations/create_devices_table.php.stub

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class CreateDevicesTable extends Migration
1111
Schema::create('devices', function (Blueprint $table) {
1212
$table->bigIncrements('id');
1313
$table->bigInteger('user_id')->unsigned();
14-
$table->string('user_type');
1514
$table->string('platform')->nullable();
1615
$table->string('platform_version')->nullable();
1716
$table->string('browser')->nullable();

migrations/create_logins_table.php.stub

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class CreateLoginsTable extends Migration
1313
$table->ipAddress('ip_address');
1414
$table->string('type')->default(\Lab404\AuthChecker\Models\Login::TYPE_LOGIN);
1515
$table->bigInteger('user_id')->unsigned();
16-
$table->string('user_type');
1716
$table->bigInteger('device_id')->unsigned()->index()->nullable();
1817
$table->timestamps();
1918

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class UpdateLoginsAndDevicesTableUserRelation extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::table('logins', function (Blueprint $table) {
12+
$table->string('user_type')->after('user_id');
13+
});
14+
15+
Schema::table('devices', function (Blueprint $table) {
16+
$table->string('user_type')->after('user_id');
17+
});
18+
}
19+
20+
public function down()
21+
{
22+
Schema::table('logins', function (Blueprint $table) {
23+
$table->dropColumn('user_type');
24+
});
25+
26+
Schema::table('devices', function (Blueprint $table) {
27+
$table->dropColumn('user_type');
28+
});
29+
}
30+
}

src/AuthCheckerServiceProvider.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ public function boot(): void
2020
__DIR__.'/../config/auth-checker.php' => config_path('auth-checker.php')
2121
], 'auth-checker');
2222

23-
if (false === class_exists('CreateLoginsTable') && false === class_exists('CreateDevicesTable')) {
24-
$this->publishes([
25-
__DIR__.'/../migrations/create_devices_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_devices_table.php'),
26-
__DIR__.'/../migrations/create_logins_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_logins_table.php')
27-
], 'auth-checker');
23+
if ($this->app->runningInConsole()) {
24+
if (false === class_exists('CreateLoginsTable') && false === class_exists('CreateDevicesTable')) {
25+
$this->publishes([
26+
__DIR__.'/../migrations/create_devices_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_devices_table.php'),
27+
__DIR__.'/../migrations/create_logins_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_logins_table.php')
28+
], 'auth-checker');
29+
}
30+
31+
if (false === class_exists('UpdateLoginsAndDevicesTableUserRelation')) {
32+
$this->publishes([
33+
__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'),
34+
], 'auth-checker');
35+
}
2836
}
2937

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

0 commit comments

Comments
 (0)