fix: 加速账户账单店铺模糊筛选 #148
@ -247,6 +247,7 @@ return [
|
||||
['shop_id', 'fee_time', 'Id'],
|
||||
['fee_time', 'Id'],
|
||||
['channel', 'fee_time', 'Id', 'inout_type', 'amount'],
|
||||
['channel', 'shop_id', 'fee_time', 'Id', 'inout_type', 'amount', 'fee_name'],
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
private const TABLE = 'ops_jst_original_bill_info';
|
||||
private const INDEX = 'idx_original_bill_channel_shop';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (config('system_database.mode', 'bootstrap') === 'bootstrap') return;
|
||||
$schema = Schema::connection((string) config('upstream_mirrors.connection', 'business_mirror'));
|
||||
if (! $schema->hasTable(self::TABLE) || $schema->hasIndex(self::TABLE, self::INDEX)) return;
|
||||
$schema->table(self::TABLE, static function (Blueprint $table): void {
|
||||
$table->index(['channel', 'shop_id', 'fee_time', 'Id', 'inout_type', 'amount', 'fee_name'], self::INDEX);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (config('system_database.mode', 'bootstrap') === 'bootstrap') return;
|
||||
$schema = Schema::connection((string) config('upstream_mirrors.connection', 'business_mirror'));
|
||||
if (! $schema->hasTable(self::TABLE) || ! $schema->hasIndex(self::TABLE, self::INDEX)) return;
|
||||
$schema->table(self::TABLE, static fn (Blueprint $table) => $table->dropIndex(self::INDEX));
|
||||
}
|
||||
};
|
||||
@ -188,6 +188,22 @@ class StoreReceivingAlipayBillMirrorRepositoryTest extends TestCase
|
||||
$this->assertEquals($before, (array) $table->first());
|
||||
}
|
||||
|
||||
public function test_shop_filter_index_migration_and_rollback_preserve_rows(): void
|
||||
{
|
||||
config(['system_database.mode' => 'connected']);
|
||||
$table = DB::connection('business_mirror')->table('ops_jst_original_bill_info');
|
||||
$table->insert($this->row(1, 7, '2026-08-01 09:00:00', '1', 10));
|
||||
$before = (array) $table->first();
|
||||
$migration = require base_path('database/migrations/2026_09_09_190000_index_account_bill_shop_filters.php');
|
||||
$migration->up();
|
||||
$migration->up();
|
||||
$this->assertTrue(Schema::connection('business_mirror')->hasIndex('ops_jst_original_bill_info', 'idx_original_bill_channel_shop'));
|
||||
$this->assertEquals($before, (array) $table->first());
|
||||
$migration->down();
|
||||
$this->assertFalse(Schema::connection('business_mirror')->hasIndex('ops_jst_original_bill_info', 'idx_original_bill_channel_shop'));
|
||||
$this->assertEquals($before, (array) $table->first());
|
||||
}
|
||||
|
||||
public function test_common_filters_use_the_existing_daily_summary_acceleration(): void
|
||||
{
|
||||
$this->markReady();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user