Two-phase is definitely the right direction, but you need more granular control. Here’s what worked for us when we migrated 2000+ audit records:
First, implement proper bulk import error handling with these steps:
// Pseudocode - Bulk import with duplicate detection:
1. Query existing AUDIT_MASTER_DATA keys into HashSet
2. Filter import dataset: exclude records where key exists in HashSet
3. Batch remaining records into groups of 150 (optimal for TW 9.0)
4. For each batch: wrap in try-catch, log failures to separate table
5. Commit successful batches, collect failed records for manual review
// Reference: TrackWise Data Management Guide Section 7.3
For master data key uniqueness, the UK_AUDIT_TEMPLATE_ID constraint is enforced at database level, so you MUST validate before insert. Your source data validation isn’t enough - you need runtime validation against the live database state because other processes might be creating records concurrently.
For audit log reconciliation, implement a post-import verification process:
SELECT template_id, COUNT(*)
FROM AUDIT_MASTER_DATA
WHERE created_date >= [import_start_time]
GROUP BY template_id
HAVING COUNT(*) > 1
This query identifies any duplicate template IDs that slipped through. The reconciliation should compare your import manifest (what you intended to import) against what actually exists in the database after import completion. Create a reconciliation report that shows: records attempted, records succeeded, records failed with reasons, and records that need manual intervention.
Key architectural points: Use pessimistic locking if multiple import processes run concurrently. Implement idempotency by checking record existence before every insert operation. Set your transaction batch size to 150 records max - this is the sweet spot for TrackWise 9.0 performance without causing memory issues. Enable detailed audit logging for the import process itself so you can trace exactly which records failed and why.
The 600-record failure point you’re seeing is almost certainly a transaction boundary. TrackWise’s default transaction batch size in 9.0 is 500-600 records, so when it hits the first duplicate in that batch, the entire batch rolls back. Smaller batches will give you better error isolation and allow partial success rather than all-or-nothing failures.