generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Turso's embedded replica feature
- Loading branch information
1 parent
6721b0e
commit 7f25612
Showing
17 changed files
with
536 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
<?php | ||
|
||
// config for RichanFongdasen/TursoLaravel | ||
return []; | ||
return [ | ||
'sync' => [ | ||
'script_filename' => 'turso-sync.mjs', | ||
'script_path' => realpath(__DIR__ . '/..'), | ||
'timeout' => 60, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"sync": "node turso-sync.js" | ||
}, | ||
"devDependencies": { | ||
"@libsql/client": "^0.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichanFongdasen\Turso\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Process; | ||
|
||
class TursoSyncCommand extends Command | ||
{ | ||
public $signature = 'turso:sync'; | ||
|
||
public $description = 'Sync changes from the remote database to the local replica manually.'; | ||
|
||
protected function compileRunProcess(): string | ||
{ | ||
return sprintf( | ||
'node %s "%s" "%s" "%s"', | ||
config('turso-laravel.sync.script_filename'), | ||
config('database.connections.turso.db_url'), | ||
config('database.connections.turso.access_token'), | ||
config('database.connections.turso.db_replica'), | ||
); | ||
} | ||
|
||
public function handle(): int | ||
{ | ||
$timeout = (int) config('turso-laravel.sync.timeout'); | ||
|
||
$result = Process::timeout($timeout) | ||
->path(config('turso-laravel.sync.script_path') ?? base_path()) | ||
->run($this->compileRunProcess()); | ||
|
||
if ($result->failed()) { | ||
$this->error($result->errorOutput()); | ||
|
||
return self::FAILURE; | ||
} | ||
|
||
$this->info($result->output()); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichanFongdasen\Turso\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
class TursoSyncJob implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
Artisan::call('turso:sync'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.