Skip to content

Commit

Permalink
Auto sync replica if the replica database doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
richan-fongdasen committed Apr 16, 2024
1 parent e439f32 commit 730eb26
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/TursoLaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Connection;
use Illuminate\Database\DatabaseManager;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Process;
use PDO;
use RichanFongdasen\Turso\Commands\TursoSyncCommand;
use RichanFongdasen\Turso\Database\TursoConnection;
Expand Down Expand Up @@ -86,7 +87,12 @@ public function register(): void

$replicaPath = (string) data_get($config, 'db_replica');

if (($replicaPath !== '') && file_exists($replicaPath)) {
if ($replicaPath !== '') {
if (! file_exists($replicaPath)) {
Process::run('mkdir -p ' . dirname($replicaPath));
Turso::sync();
}

$connection->setReadPdo(new PDO('sqlite:' . $replicaPath));
}

Expand Down

0 comments on commit 730eb26

Please sign in to comment.