Skip to content

Commit a3bd955

Browse files
authored
Fix some DB stuff (#413)
* 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
1 parent cee53d7 commit a3bd955

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/NativeServiceProvider.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ public function packageRegistered()
4747
return new MigrateCommand($app['migrator'], $app['events']);
4848
});
4949

50-
$this->app->singleton(
51-
\Illuminate\Contracts\Debug\ExceptionHandler::class,
52-
Handler::class
53-
);
54-
5550
if (config('nativephp-internal.running')) {
51+
$this->app->singleton(
52+
\Illuminate\Contracts\Debug\ExceptionHandler::class,
53+
Handler::class
54+
);
55+
5656
Application::starting(function ($app) {
5757
$app->resolveCommands([
5858
LoadStartupConfigurationCommand::class,
5959
LoadPHPConfigurationCommand::class,
60+
MigrateCommand::class,
6061
]);
6162
});
6263

@@ -127,8 +128,10 @@ public function rewriteDatabase()
127128

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

130-
DB::statement('PRAGMA journal_mode=WAL;');
131-
DB::statement('PRAGMA busy_timeout=5000;');
131+
if (file_exists($databasePath)) {
132+
DB::statement('PRAGMA journal_mode=WAL;');
133+
DB::statement('PRAGMA busy_timeout=5000;');
134+
}
132135
}
133136

134137
public function removeDatabase()
@@ -137,13 +140,11 @@ public function removeDatabase()
137140

138141
if (config('app.debug')) {
139142
$databasePath = database_path('nativephp.sqlite');
140-
141-
if (! file_exists($databasePath)) {
142-
return;
143-
}
144143
}
145144

146-
unlink($databasePath);
145+
@unlink($databasePath);
146+
@unlink($databasePath.'-shm');
147+
@unlink($database.'-wal');
147148
}
148149

149150
protected function configureDisks(): void

0 commit comments

Comments
 (0)