Repository navigation
fix(main): repair sequence counters and rebuild search index on partial import - #1216
Merged
Merged
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Repair sequence counters and rebuild search index on partial import (#1215)
What Changed
executeSequenceRepairand update thesequence_repair_completed_atandsequence_repair_pendingsettings within thePOST /api/db/importtransaction.rebuildSearchIndexbefore committing the import transaction.docs/reference/api.mdand add test coverage intests/database-tools-api.test.tsfor partial imports without a sequences table.Risk Assessment
✅ Low: The change is well-bounded, reuses existing sequence repair and search index utilities within the active import transaction, and includes robust end-to-end API integration tests.
Testing
Validated PR #1215 by running the full database-tools-api test suite (143/143 passing) and driving 4 live end-to-end scenarios against a running dev-server instance with an isolated database: verified sequence counter repair after partial import without sequences table, conflict-free order and bill generation, immediate full-text search availability for imported orders and customers, sequence monotonicity across historical imports, and fast-path database re-opening.
Evidence: live-scenarios-result.json
{ "timestamp": "2026-10-18T18:37:18.352Z", "commit": "b68934e51a1337747f221ca256d55a1d299bcc84", "intent": "Repair sequence counters and rebuild search index on partial import (#1215)", "results": [ { "scenario": "partial_import_advances_sequences", "status": "pass", "details": { "importedOrders": 4, "importedBills": 4, "nextOrderNumber": "ORD-20261018-0006", "nextBillNumber": "INV-20261018-0006", "ordersSequenceCurrentValue": 6, "billsSequenceCurrentValue": 6 } }, { "scenario": "partial_import_rebuilds_search_index", "status": "pass", "details": { "searchOrderQuery": "0005", "foundOrder0005": true, "searchCustomerQuery": "Porcupine", "foundCustomerOrder": true } }, { "scenario": "sequence_repair_monotonicity_guard", "status": "pass", "details": { "historicalDate": "20261001", "expectedOrderNumber": "ORD-20261018-0007", "actualOrderNumber": "ORD-20261018-0007" } }, { "scenario": "server_reopen_preserves_sequences", "status": "pass", "details": { "sequenceRepairPending": "0", "sequenceRepairCompletedAt": "2026-10-18 18:37:17", "expectedOrderNumber": "ORD-20261018-0008", "actualOrderNumber": "ORD-20261018-0008" } } ] }Evidence: live-scenarios-transcript.log
[2026-10-18T18:37:16.443Z] Starting dev-server.js on ports 38101, 38102, 38103 [2026-10-18T18:37:17.391Z] dev-server is healthy and listening [2026-10-18T18:37:17.593Z] Setup complete, authenticated as owner [2026-10-18T18:37:17.604Z] Order #1 created: id=1, number=ORD-20261018-0001 [2026-10-18T18:37:17.609Z] Bill #1 generated: id=1, number=INV-20261018-0001 [2026-10-18T18:37:17.609Z] === Driving Scenario 1: Partial import without sequences table advances sequence counters === [2026-10-18T18:37:17.653Z] Partial import succeeded: {"success":true,"message":"Database imported successfully",...} [2026-10-18T18:37:17.657Z] Next order created: ORD-20261018-0006 (expected ORD-20261018-0006) [2026-10-18T18:37:17.660Z] Next bill created: INV-20261018-0006 (expected INV-20261018-0006) [2026-10-18T18:37:17.664Z] DB Sequences state: orders=6, bills=6 [2026-10-18T18:37:17.664Z] === Driving Scenario 2: Search queries immediately find newly imported orders and customers === [2026-10-18T18:37:17.668Z] Search '0005' returned 1 orders; found imported order: true [2026-10-18T18:37:17.670Z] Search 'Porcupine' returned 1 orders; found linked order: true [2026-10-18T18:37:17.670Z] === Driving Scenario 3: Monotonicity Guard - Historical import does not regress sequences === [2026-10-18T18:37:17.704Z] Historical import succeeded [2026-10-18T18:37:17.707Z] Order created after historical import: ORD-20261018-0007 (expected ORD-20261018-0007) [2026-10-18T18:37:17.707Z] === Driving Scenario 4: Server Reopen / Fast-Path verification === [2026-10-18T18:37:17.707Z] Settings before restart: sequence_repair_pending=0, sequence_repair_completed_at=2026-10-18 18:37:17 [2026-10-18T18:37:18.331Z] dev-server restarted successfully on existing database [2026-10-18T18:37:18.352Z] Order created after restart: ORD-20261018-0008 (expected ORD-20261018-0008) [2026-10-18T18:37:18.352Z] === ALL SCENARIOS PASSED SUCCESSFULLY ===Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
node tests/run-electron-node-test.cjs tests/database-tools-api.test.tsLive product validation on running dev-server: POST /api/auth/setup/initialize, POST /api/orders, POST /api/bills/generate, POST /api/db/import, GET /api/orders?search=0005, GET /api/orders?search=Porcupine, server restart and order generation verification✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.