Skip to content

Commit 89793a9

Browse files
authored
Merge pull request #198 from me-shaon/fix/issue-175
fix: #175 'native:migrate fresh' command does not work
2 parents dc4142f + 7fc7de7 commit 89793a9

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;
@@ -21,6 +22,7 @@ public function configurePackage(Package $package): void
2122
->name('nativephp')
2223
->hasCommands([
2324
MigrateCommand::class,
25+
FreshCommand::class,
2426
SeedDatabaseCommand::class,
2527
MinifyApplicationCommand::class,
2628
])
@@ -109,6 +111,21 @@ public function rewriteDatabase()
109111
config(['database.default' => 'nativephp']);
110112
}
111113

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

0 commit comments

Comments
 (0)