Skip to content

Commit

Permalink
Merge pull request #198 from me-shaon/fix/issue-175
Browse files Browse the repository at this point in the history
fix: #175 'native:migrate fresh' command does not work
  • Loading branch information
simonhamp committed Apr 28, 2024
2 parents dc4142f + 7fc7de7 commit 89793a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Commands/FreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
17 changes: 17 additions & 0 deletions src/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@ public function configurePackage(Package $package): void
->name('nativephp')
->hasCommands([
MigrateCommand::class,
FreshCommand::class,
SeedDatabaseCommand::class,
MinifyApplicationCommand::class,
])
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 89793a9

Please sign in to comment.