diff --git a/src/Commands/FreshCommand.php b/src/Commands/FreshCommand.php index 843822c..0fd5059 100644 --- a/src/Commands/FreshCommand.php +++ b/src/Commands/FreshCommand.php @@ -3,19 +3,22 @@ namespace Native\Laravel\Commands; use Illuminate\Console\Command; +use Illuminate\Database\Console\Migrations\FreshCommand as BaseFreshCommand; use Native\Laravel\NativeServiceProvider; -class FreshCommand extends Command +class FreshCommand extends BaseFreshCommand { - protected $description = 'Run the database migrations in the NativePHP development environment'; + protected $description = 'Drop all tables and re-run all migrations in the NativePHP development environment'; - protected $signature = 'native:migrate fresh'; + protected $signature = 'native:migrate:fresh'; public function handle() { - unlink(config('nativephp-internal.database_path')); + $nativeServiceProvider = new NativeServiceProvider($this->laravel); - (new NativeServiceProvider($this->laravel))->rewriteDatabase(); + $nativeServiceProvider->removeDatabase(); + + $nativeServiceProvider->rewriteDatabase(); $this->call('native:migrate'); } diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 9ff9ed4..396478a 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -4,6 +4,7 @@ use Illuminate\Console\Application as Artisan; use Illuminate\Support\Arr; +use Native\Laravel\Commands\FreshCommand; use Native\Laravel\Commands\LoadPHPConfigurationCommand; use Native\Laravel\Commands\LoadStartupConfigurationCommand; use Native\Laravel\Commands\MigrateCommand; @@ -21,6 +22,7 @@ public function configurePackage(Package $package): void ->name('nativephp') ->hasCommands([ MigrateCommand::class, + FreshCommand::class, SeedDatabaseCommand::class, MinifyApplicationCommand::class, ]) @@ -109,6 +111,21 @@ public function rewriteDatabase() config(['database.default' => 'nativephp']); } + public function removeDatabase() + { + $databasePath = config('nativephp-internal.database_path'); + + if (config('app.debug')) { + $databasePath = database_path('nativephp.sqlite'); + + if (! file_exists($databasePath)) { + return; + } + } + + unlink($databasePath); + } + protected function configureDisks(): void { $disks = [