From 34eedd93e573548583fc5beea59d5301f8a405dc Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Tue, 8 Sep 2026 15:18:28 +0800 Subject: [PATCH] fix: remove unsupported small payment mirror index --- config/upstream_mirrors.php | 1 - .../BusinessMirrorSynchronizerTest.php | 59 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/config/upstream_mirrors.php b/config/upstream_mirrors.php index ad37961a..8f73fbfd 100644 --- a/config/upstream_mirrors.php +++ b/config/upstream_mirrors.php @@ -279,7 +279,6 @@ return [ 'businessFieldList', 'createTime', 'updateTime', ], 'indexes' => [ - ['woTypeId', 'woNo', 'Id'], ['created', 'Id'], ], ], diff --git a/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php b/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php index a601244b..135e37c6 100644 --- a/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php +++ b/tests/Unit/EcommerceFinance/BusinessMirrorSynchronizerTest.php @@ -246,6 +246,65 @@ class BusinessMirrorSynchronizerTest extends TestCase $this->assertSame('text', $types['longLabel']); } + public function test_small_payment_work_order_dataset_accepts_only_supported_indexes(): void + { + $datasets = (array) config('upstream_mirrors.datasets', []); + $datasets['jiansun.dbo.jst_workOrderInfo'] = [ + 'source_key' => 'jiansun', + 'schema' => 'dbo', + 'object' => 'jst_workOrderInfo', + 'target' => 'test_small_payment_work_orders', + 'keys' => ['Id'], + 'watermark' => 'updateTime', + 'columns' => [ + 'Id', 'woNo', 'woTypeId', 'title', 'content', 'status', 'grade', + 'urging', 'createby', 'executors', 'beginTime', 'endTime', + 'completer', 'completeTime', 'updated', 'created', + 'businessFieldList', 'createTime', 'updateTime', + ], + 'indexes' => [['created', 'Id']], + ]; + config(['upstream_mirrors.datasets' => $datasets]); + + $columns = [ + ['name' => 'Id', 'type' => 'int', 'length' => null], + ['name' => 'woNo', 'type' => 'nvarchar', 'length' => 100], + ['name' => 'woTypeId', 'type' => 'nvarchar', 'length' => 100], + ['name' => 'urging', 'type' => 'int', 'length' => null], + ['name' => 'created', 'type' => 'datetime2', 'length' => null], + ['name' => 'updateTime', 'type' => 'datetime2', 'length' => null], + ]; + $selected = $datasets['jiansun.dbo.jst_workOrderInfo']['columns']; + foreach ($selected as $position => $name) { + $definition = collect($columns)->firstWhere('name', $name) ?? [ + 'name' => $name, + 'type' => 'nvarchar', + 'length' => 120, + ]; + DB::table('upstream_schema_columns')->insert(array_replace($this->column( + $definition['name'], + $position + 1, + $definition['type'], + $definition['length'], + ), [ + 'source_key' => 'jiansun', + 'schema_name' => 'dbo', + 'object_name' => 'jst_workOrderInfo', + ])); + } + + $dataset = (new BusinessMirrorDatasetRegistry())->get('jiansun.dbo.jst_workOrderInfo'); + $this->assertSame([['created', 'Id']], $dataset->indexDefinitions()); + + (new BusinessMirrorSchemaManager())->ensure($dataset); + + $indexes = collect(Schema::connection('business_mirror')->getIndexes($dataset->targetTable())) + ->map(static fn (array $index): array => array_map('strtolower', (array) ($index['columns'] ?? []))) + ->all(); + $this->assertContains(['created', 'id'], $indexes); + $this->assertNotContains(['wotypeid', 'wono', 'id'], $indexes); + } + public function test_empty_full_read_does_not_delete_previous_mirror_rows(): void { $this->query->batches = [[