feat: new chain

This commit is contained in:
hashbro
2026-08-11 02:26:43 +08:00
parent ec2d9f2308
commit 9bf769b2bd
56 changed files with 3806 additions and 325 deletions
@@ -0,0 +1,31 @@
<?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('transfer_records', function (Blueprint $table) {
$table->id();
$table->string('from_address', 128)->index();
$table->string('to_address', 128)->nullable()->index();
$table->string('chain', 32)->index();
$table->string('tx_hash', 128)->nullable()->index();
$table->string('amount', 64)->nullable();
$table->string('type', 32)->default('out');
$table->string('asset', 32);
$table->string('operator', 128)->nullable()->index();
$table->string('status', 32)->index();
$table->text('error')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('transfer_records');
}
};
@@ -0,0 +1,72 @@
<?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
{
if (! Schema::hasTable('users')) {
return;
}
if (Schema::hasColumn('users', 'bot_token')) {
if (Schema::hasColumn('users', 'bot_id')) {
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_id');
});
}
return;
}
Schema::table('users', function (Blueprint $table) {
$table->string('bot_token', 255)->nullable()->after('chat_id');
});
if (Schema::hasColumn('users', 'bot_id')) {
$driver = Schema::getConnection()->getDriverName();
if ($driver === 'sqlite') {
DB::statement('UPDATE users SET bot_token = bot_id WHERE bot_id IS NOT NULL');
} else {
DB::table('users')->whereNotNull('bot_id')->orderBy('id')->chunkById(100, function ($rows) {
foreach ($rows as $row) {
DB::table('users')->where('id', $row->id)->update(['bot_token' => $row->bot_id]);
}
});
}
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_id');
});
}
}
public function down(): void
{
if (! Schema::hasTable('users') || ! Schema::hasColumn('users', 'bot_token')) {
return;
}
if (! Schema::hasColumn('users', 'bot_id')) {
Schema::table('users', function (Blueprint $table) {
$table->string('bot_id', 128)->nullable()->after('chat_id');
});
}
DB::table('users')->whereNotNull('bot_token')->orderBy('id')->chunkById(100, function ($rows) {
foreach ($rows as $row) {
DB::table('users')->where('id', $row->id)->update([
'bot_id' => is_string($row->bot_token) ? substr($row->bot_token, 0, 128) : $row->bot_token,
]);
}
});
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_token');
});
}
};
@@ -0,0 +1,51 @@
<?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
{
if (! Schema::hasColumn('users', 'bot_token')) {
Schema::table('users', function (Blueprint $table) {
$table->string('bot_token', 255)->nullable()->after('chat_id');
});
}
if (Schema::hasColumn('users', 'bot_id')) {
$rows = DB::table('users')->select(['id', 'bot_id'])->whereNotNull('bot_id')->get();
foreach ($rows as $row) {
DB::table('users')->where('id', $row->id)->update([
'bot_token' => $row->bot_id,
]);
}
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_id');
});
}
}
public function down(): void
{
if (! Schema::hasColumn('users', 'bot_id')) {
Schema::table('users', function (Blueprint $table) {
$table->string('bot_id', 128)->nullable()->after('chat_id');
});
}
if (Schema::hasColumn('users', 'bot_token')) {
$rows = DB::table('users')->select(['id', 'bot_token'])->whereNotNull('bot_token')->get();
foreach ($rows as $row) {
DB::table('users')->where('id', $row->id)->update([
'bot_id' => is_string($row->bot_token) ? substr($row->bot_token, 0, 128) : null,
]);
}
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_token');
});
}
}
};
@@ -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
{
if (! Schema::hasColumn('users', 'bot_token')) {
Schema::table('users', function (Blueprint $table) {
$table->string('bot_token', 255)->nullable()->after('chat_id');
});
}
if (Schema::hasColumn('users', 'bot_id')) {
$rows = DB::table('users')->select(['id', 'bot_id'])->whereNotNull('bot_id')->get();
foreach ($rows as $row) {
$token = trim((string) $row->bot_id);
if ($token === '') {
continue;
}
DB::table('users')->where('id', $row->id)->update(['bot_token' => $token]);
}
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_id');
});
}
}
public function down(): void
{
if (! Schema::hasColumn('users', 'bot_id')) {
Schema::table('users', function (Blueprint $table) {
$table->string('bot_id', 128)->nullable()->after('chat_id');
});
}
if (Schema::hasColumn('users', 'bot_token')) {
$rows = DB::table('users')->select(['id', 'bot_token'])->whereNotNull('bot_token')->get();
foreach ($rows as $row) {
$token = trim((string) $row->bot_token);
if ($token === '') {
continue;
}
DB::table('users')->where('id', $row->id)->update([
'bot_id' => mb_substr($token, 0, 128),
]);
}
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('bot_token');
});
}
}
};
@@ -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->boolean('album_storage')->default(true)->after('telegram_notified');
});
}
public function down(): void
{
Schema::table('devices', function (Blueprint $table) {
$table->dropColumn('album_storage');
});
}
};