fix: 修复手工动账导入审计字段超长 (#1253)

Co-authored-by: 92451 <924518135@qq.com>
Co-committed-by: 92451 <924518135@qq.com>
This commit is contained in:
92451 2026-11-18 18:34:28 +08:00 committed by yutu
parent e4eca2d9af
commit c1c98f756b
2 changed files with 49 additions and 1 deletions

View File

@ -46,7 +46,7 @@ return new class extends Migration
if (! $schema->hasTable('fin_ledger_edit_events')) {
$schema->create('fin_ledger_edit_events', function (Blueprint $table): void {
$table->bigIncrements('id');
$table->string('entity_type', 20);
$table->string('entity_type', 64);
$table->string('entity_key', 200);
$table->json('changes');
$table->unsignedBigInteger('user_id')->nullable();

View File

@ -0,0 +1,48 @@
<?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
{
private function connectionName(): string
{
return (string) config('upstream_mirrors.connection', 'business_mirror');
}
public function up(): void
{
$schema = Schema::connection($this->connectionName());
if (! $schema->hasTable('fin_ledger_edit_events')
|| ! $schema->hasColumn('fin_ledger_edit_events', 'entity_type')) {
return;
}
$schema->table('fin_ledger_edit_events', function (Blueprint $table): void {
$table->string('entity_type', 64)->change();
});
}
public function down(): void
{
$schema = Schema::connection($this->connectionName());
if (! $schema->hasTable('fin_ledger_edit_events')
|| ! $schema->hasColumn('fin_ledger_edit_events', 'entity_type')) {
return;
}
$hasLongValues = DB::connection($this->connectionName())
->table('fin_ledger_edit_events')
->whereRaw('CHAR_LENGTH(entity_type) > 20')
->exists();
if ($hasLongValues) {
return;
}
$schema->table('fin_ledger_edit_events', function (Blueprint $table): void {
$table->string('entity_type', 20)->change();
});
}
};