Project case study · Python · Salesforce

A Reusable, CSV-First Migration Pipeline: SAP Commerce to Salesforce

This project builds a reusable migration layer, currently connecting SAP Commerce (Hybris) CSV exports to Salesforce. It uses CSV as a simple data boundary, with client-specific mappings and rules kept configurable. Salesforce Bulk API 2.0 is the current destination connector; other platforms can be supported by adding destination-specific CSV mappings and a connector for their API.

01

Architecture at a glance

The pipeline is deliberately staged. Every boundary has a defined input, output, validation point, and operational responsibility, making the migration easier to test, restart, audit, and scale than a single all-in-one script.

Source

SAP Commerce CSV exports are profiled for schema, row counts, nulls, duplicates, delimiters, and volume before transformation begins.

Preparation

Run identity, optional root batching, relationship resolution, and scoped working data establish a deterministic input for later stages.

Transformation

Configured mappings, normalization, type conversion, filters, and business rules produce destination-shaped CSV files.

Target and proof

The current Salesforce Bulk API 2.0 connector retains job and row results; recovery, rollback, and reconciliation provide separate operational controls.

Reusable across client contexts

Client-specific source structures, field mappings, relationship rules, and migration behavior are configured around a shared pipeline, reducing the need to rebuild the workflow for each dataset.

CSV-first, connector-ready

CSV is the exchange contract between source preparation, transformation, and loading. Salesforce is the implemented destination for this use case; supporting another platform means adding its target mappings and an API connector that consumes the resulting CSVs.

02

High-level design (HLD)

The HLD shows two ways to prepare a run, followed by one shared path through validation, relationship resolution, transformation, Salesforce loading, reconciliation, and the target system. The batch and single-run examples show file types and processing rules without dataset volumes.

SAP Commerce to Salesforce migration pipeline: high-level design SAP Commerce CSV exports feed either root-batch preparation with DuckDB or a direct single-run setup. Both paths converge on object registry validation, relationship resolution, transformation, Salesforce Bulk API 2.0 loading, rollback tooling, and configured reconciliation reports. Optional profiling and source dictionary notebooks are available during run preparation. SAP COMMERCE CSV EXPORTS → SALESFORCE SAP Commerce source files Customer.csv · Address.csv · Order.csv · related CSVs CSV extraction File-based source boundary · no live SAP connection CHOOSE A RUN PREPARATION PATH A · ROOT-BATCHED RUN B · DIRECT SINGLE RUN config/batching_relationships.json prepare_root_batches.py DuckDB plans Customer-rooted batches Related Customer, Address, and Order files stay grouped Batch directories Each batch carries its own raw input files start_migration_run.ps1 Creates one run-scoped raw directory Customer · Address · Order source files Single run directory One source set follows the shared pipeline Optional source analysis notebooks 01_data_profiling_working.ipynb · 02_data_dict_source_working.ipynb Validate the object registry config/object_registry.json · validate_registry.py Checks definitions, mappings, dependencies, and load configuration Resolve source relationships run_all_relationship_resolutions.ps1 Address rules shown in the HLD Keep only Customer default addresses; expand rows when Billing or Shipping is TRUE. Transform to Salesforce-objects run_all_transformations.ps1 · MigrationRunId__c Account.csv · User.csv · ContactPointAddress.csv · Order.csv Load through Salesforce Bulk API 2.0 config/local/sf_loader_profiles.local.json run_sf_bulk2_loader.ps1 Run output: bulk2 · job state and row results Rollback tools · operator-run sf_bulk2_rollback --analyze sf_bulk2_rollback --execute Analyze, then execute when appropriate Reconciliation and reports config/reconciliation_checks.json run_overall_flow_report.ps1 · run_reconciliation_report.ps1 Local evidence · optional read-only SOQL · reports/ Salesforce target system Run-specific records are available for verification Run-scoped workspace raw/ Source CSVs in a single run or each prepared batch directory working/ · transform_input/ transfer_output/ bulk2/ reports/ Separated evidence for each stage
Both entry modes feed the same run-aware processing path; record volumes are omitted. Open the original detailed HLD

Batch or single-run preparation

The root-batch planner and the direct run script produce different input layouts, then converge at registry validation. The profiling and source-dictionary notebooks support preparation and analysis.

Relationship rules shape target records

Relationship resolution keeps the Customer default address and expands address rows when the Billing and Shipping flags are true. Transformations produce Salesforce-shaped Account, User, ContactPointAddress, and Order files.

Loading and recovery are explicit

A local Salesforce loader profile configures Bulk API 2.0 jobs. The rollback utility separates analysis from execution so recovery can be reviewed before it is applied.

Reconciliation leaves run evidence

The configured flow and reconciliation reports use run-scoped files and may perform read-only SOQL checks against Salesforce. Outputs are kept under the run’s reports directory.

03

Logical execution sequence

Each stage makes its inputs and outputs explicit, so the next stage receives a defined contract rather than discovering files or inferring run state on its own.

Profile the source boundary

Inspect schemas, row counts, nulls, duplicates, delimiters, and volume to establish a data-quality baseline before migration logic changes the data.

Establish run identity

A direct run creates a unique migration_run_id and canonical run root. The same identity scopes raw data, intermediate stages, load evidence, reports, and Salesforce records through MigrationRunId__c.

Partition when needed

The root-batch planner validates the relationship graph, partitions Customer-rooted data into restartable relational batches, and creates independent roots for standalone file graphs.

Resolve source relationships

Relationship resolution reconstructs foreign-key-like links across flat files, scopes child data, and records missing, orphaned, or ambiguous relationships in audit evidence.

Assemble deterministic inputs

Resolved files and required raw files are assembled under transform_input/, giving transformation a stable contract instead of ad hoc input discovery.

Apply mapping and business rules

Transformation normalizes fields, converts types, applies configured filters and business rules, and writes Salesforce-ready object files under transform_output/.

Load in dependency order

The loader validates the registry, file plan, dependencies, mode, and run identity before authentication or job creation. It streams files, chunks large inputs, polls asynchronous jobs, and downloads result evidence.

Reconcile for sign-off

Read-only reports compare local and optional Salesforce-side evidence. Complete, partial, and inconclusive results remain distinct; an inconclusive required check blocks sign-off.

04

Runtime boundaries and responsibilities

Configuration layer

Object registries, relationship graphs, source-file maps, loader metadata, mappings, and reconciliation rules define behavior outside the orchestration code.

Orchestration layer

PowerShell wrappers coordinate run-root-scoped Python entry points and expose operational parameters without hiding the stage sequence.

Processing layer

Python modules implement profiling, batching, relationship resolution, transformation, loader planning, result processing, reporting, and rollback.

Persistence layer

Canonical folders and JSON/CSV artifacts retain stage outputs, recovery state, result files, metrics, and report evidence for later analysis.

05

Run-root and artifact contract

Every run keeps its inputs, intermediate data, load evidence, recovery state, and reports under one canonical root: data/runs/<env>/<load-mode>/<migration-run-id>/

Run folderPurpose and retained evidence
raw/Original source CSVs for a direct run or each prepared batch.
working/Relationship-resolved, run-scoped working data and resolution evidence.
transform_input/Deterministic inputs assembled for the transformation stage.
transform_output/Salesforce-shaped object files produced by configured transformations.
bulk2/Loader summary, job state, row results, and recovery manifests and chunks.
reports/overall_flow_report.* and reconciliation_report.* outputs for the same migration run.

Run identity is consistent

All downstream stages and evidence use the same run root and migration_run_id.

Prepared roots are preserved

Planner-created roots are not reinitialized, and loader evidence stays inside its run root.

Evidence is scoped and reviewable

Stage artifacts remain available for later analysis; reports are read-only and do not delete records.

Credentials stay local

Local profiles and private keys remain outside source control.

06

Failure handling is a first-class path

Preflight failure

Missing or unexpected files, invalid mappings, unknown object keys, invalid registry configuration, and missing delta External IDs fail before authentication or job creation.

Interrupted load

Durable recovery manifests and chunks support resume without discarding the original run. Accepted, failed, and unprocessed results remain available for analysis.

Incorrect target records

Rollback is a separate, explicit Bulk API delete workflow. It is not an implicit side effect of recovery or reconciliation.

Untrustworthy evidence

An inconclusive required reconciliation check produces a failed, non-sign-off-eligible result. The system surfaces the evidence gap instead of masking it.

07

Scope and verification boundaries

File-based source input

The framework starts from SAP Commerce CSV exports. It does not connect to SAP or extract data from a live source system.

Reconciliation is read-only

Local checks and optional Salesforce SOQL checks inspect outcomes; they do not modify Salesforce records.

08

Engineering outcome

The framework turns a high-risk migration into a controlled sequence of contracts. It is configuration-driven, dependency-aware, conscious of large-file processing, recoverable, and auditable. The outcome is not simply that records can be loaded; it is that the load can be explained, resumed, challenged, and signed off using durable evidence.

09

Technology

High-level design