diff --git a/changelog.md b/changelog.md index fc434c2..571fc57 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/migrations/create_devices_table.php.stub b/migrations/create_devices_table.php.stub index af745d5..56c928a 100644 --- a/migrations/create_devices_table.php.stub +++ b/migrations/create_devices_table.php.stub @@ -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(); diff --git a/migrations/create_logins_table.php.stub b/migrations/create_logins_table.php.stub index 9d275f8..016b0bb 100644 --- a/migrations/create_logins_table.php.stub +++ b/migrations/create_logins_table.php.stub @@ -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(); diff --git a/migrations/update_logins_and_devices_table_user_relation.php.stub b/migrations/update_logins_and_devices_table_user_relation.php.stub new file mode 100644 index 0000000..ea350fb --- /dev/null +++ b/migrations/update_logins_and_devices_table_user_relation.php.stub @@ -0,0 +1,30 @@ +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'); + }); + } +} diff --git a/src/AuthCheckerServiceProvider.php b/src/AuthCheckerServiceProvider.php index 9d30347..e13b1f8 100644 --- a/src/AuthCheckerServiceProvider.php +++ b/src/AuthCheckerServiceProvider.php @@ -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');