Skip to content

Commit

Permalink
Fix some DB stuff (#413)
Browse files Browse the repository at this point in the history
* Resolve native:migrate command so we can call it

* Only run exception handler in native context

* Only configure DB if we have one

* Silently unlink all SQlite files
  • Loading branch information
simonhamp authored Nov 15, 2024
1 parent cee53d7 commit a3bd955
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ public function packageRegistered()
return new MigrateCommand($app['migrator'], $app['events']);
});

$this->app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
Handler::class
);

if (config('nativephp-internal.running')) {
$this->app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
Handler::class
);

Application::starting(function ($app) {
$app->resolveCommands([
LoadStartupConfigurationCommand::class,
LoadPHPConfigurationCommand::class,
MigrateCommand::class,
]);
});

Expand Down Expand Up @@ -127,8 +128,10 @@ public function rewriteDatabase()

config(['database.default' => 'nativephp']);

DB::statement('PRAGMA journal_mode=WAL;');
DB::statement('PRAGMA busy_timeout=5000;');
if (file_exists($databasePath)) {
DB::statement('PRAGMA journal_mode=WAL;');
DB::statement('PRAGMA busy_timeout=5000;');
}
}

public function removeDatabase()
Expand All @@ -137,13 +140,11 @@ public function removeDatabase()

if (config('app.debug')) {
$databasePath = database_path('nativephp.sqlite');

if (! file_exists($databasePath)) {
return;
}
}

unlink($databasePath);
@unlink($databasePath);
@unlink($databasePath.'-shm');
@unlink($database.'-wal');
}

protected function configureDisks(): void
Expand Down

0 comments on commit a3bd955

Please sign in to comment.