Skip to content

Commit

Permalink
add db exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed May 2, 2024
1 parent 16769a2 commit d4e9c39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/Console/Commands/DbExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Psl\File;
use Psl\Filesystem;
use Psl\Json;
use Psl\Vec;
use stdClass;

class DbExport extends Command
{
protected $signature = 'db:export';

public function handle(): void
{
$dir = storage_path('export-' . date('Y-m-d') . '-' . time());
/** @phpstan-ignore-next-line */
Filesystem\create_directory($dir);

$tables = Vec\flat_map(
DB::select('show tables'),
fn (stdClass $r) => (array) $r,
);

foreach ($tables as $table) {
$data = DB::table($table)->get();

File\write("{$dir}/{$table}.json", Json\encode($data, true));
}
}
}
1 change: 1 addition & 0 deletions storage/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
testing.sqlite
testing.sqlite-journal
/export-*/

0 comments on commit d4e9c39

Please sign in to comment.