feat: stats

This commit is contained in:
hashbro
2026-09-09 02:52:24 +08:00
parent c1d24ab815
commit 04318c08b3
32 changed files with 1672 additions and 41 deletions
@@ -0,0 +1,28 @@
<?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('daily_stats', function (Blueprint $table) {
$table->id();
$table->string('stat_date', 10);
$table->string('scope_key', 32)->default('');
$table->unique(['stat_date', 'scope_key']);
$table->unsignedInteger('uv')->default(0);
$table->unsignedInteger('effective_uv')->default(0);
$table->unsignedInteger('devices')->default(0);
$table->unsignedInteger('wallet_devices')->default(0);
$table->timestamp('computed_at')->nullable();
});
}
public function down(): void
{
Schema::dropIfExists('daily_stats');
}
};
@@ -0,0 +1,36 @@
<?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
{
if (! Schema::hasTable('daily_stats') || Schema::hasColumn('daily_stats', 'scope_key')) {
return;
}
Schema::table('daily_stats', function (Blueprint $table) {
$table->string('scope_key', 32)->default('');
});
Schema::table('daily_stats', function (Blueprint $table) {
$table->dropUnique(['stat_date']);
$table->unique(['stat_date', 'scope_key']);
});
}
public function down(): void
{
if (! Schema::hasTable('daily_stats') || ! Schema::hasColumn('daily_stats', 'scope_key')) {
return;
}
Schema::table('daily_stats', function (Blueprint $table) {
$table->dropUnique(['stat_date', 'scope_key']);
$table->dropColumn('scope_key');
$table->unique(['stat_date']);
});
}
};
@@ -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('daily_stats', function (Blueprint $table) {
$table->unsignedInteger('address_count')->nullable()->after('wallet_devices');
$table->unsignedInteger('mnemonic_count')->nullable()->after('address_count');
});
}
public function down(): void
{
Schema::table('daily_stats', function (Blueprint $table) {
$table->dropColumn(['address_count', 'mnemonic_count']);
});
}
};