fix: remove unsupported small payment mirror index

This commit is contained in:
yueyang 2026-09-08 15:18:28 +08:00
parent d876822a6e
commit 34eedd93e5
2 changed files with 59 additions and 1 deletions

View File

@ -279,7 +279,6 @@ return [
'businessFieldList', 'createTime', 'updateTime',
],
'indexes' => [
['woTypeId', 'woNo', 'Id'],
['created', 'Id'],
],
],

View File

@ -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 = [[