Skip to content

Commit 2fec19a

Browse files
committed
fix: #175 'native:migrate fresh' command does not work
1 parent 03ce978 commit 2fec19a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/Commands/FreshCommand.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
namespace Native\Laravel\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Database\Console\Migrations\FreshCommand as BaseFreshCommand;
67
use Native\Laravel\NativeServiceProvider;
78

8-
class FreshCommand extends Command
9+
class FreshCommand extends BaseFreshCommand
910
{
10-
protected $description = 'Run the database migrations in the NativePHP development environment';
11+
protected $description = 'Drop all tables and re-run all migrations in the NativePHP development environment';
1112

12-
protected $signature = 'native:migrate fresh';
13+
protected $signature = 'native:migrate:fresh';
1314

1415
public function handle()
1516
{
16-
unlink(config('nativephp-internal.database_path'));
17+
$nativeServiceProvider = new NativeServiceProvider($this->laravel);
1718

18-
(new NativeServiceProvider($this->laravel))->rewriteDatabase();
19+
$nativeServiceProvider->removeDatabase();
20+
21+
$nativeServiceProvider->rewriteDatabase();
1922

2023
$this->call('native:migrate');
2124
}

src/NativeServiceProvider.php

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Application as Artisan;
66
use Illuminate\Support\Arr;
7+
use Native\Laravel\Commands\FreshCommand;
78
use Native\Laravel\Commands\LoadPHPConfigurationCommand;
89
use Native\Laravel\Commands\LoadStartupConfigurationCommand;
910
use Native\Laravel\Commands\MigrateCommand;
@@ -20,6 +21,7 @@ public function configurePackage(Package $package): void
2021
->name('nativephp')
2122
->hasCommands([
2223
MigrateCommand::class,
24+
FreshCommand::class,
2325
MinifyApplicationCommand::class,
2426
])
2527
->hasConfigFile()
@@ -107,6 +109,21 @@ public function rewriteDatabase()
107109
config(['database.default' => 'nativephp']);
108110
}
109111

112+
public function removeDatabase()
113+
{
114+
$databasePath = config('nativephp-internal.database_path');
115+
116+
if (config('app.debug')) {
117+
$databasePath = database_path('nativephp.sqlite');
118+
119+
if (! file_exists($databasePath)) {
120+
return;
121+
}
122+
}
123+
124+
unlink($databasePath);
125+
}
126+
110127
protected function configureDisks(): void
111128
{
112129
$disks = [

0 commit comments

Comments
 (0)