Test data before migration
Check data quality in the source before a migration, then reconcile the target with the source to prove the data arrived intact.
This guide shows how to use Soda in a data migration. Before you migrate, a contract on the source table confirms that the data is fit to move. After you migrate, a contract on the target table uses reconciliation checks to compare it with the source: the schema, the row count, a total, and every row.
Run the reconciliation after each migration run in staging, fix what it reports, and run it again after the production migration.
Example migration
A team moves the fact_internet_sales table from a legacy PostgreSQL database to a new PostgreSQL warehouse. Soda connects to both as two data sources, legacy and warehouse. The source and the target can also be different engines, for example a migration from PostgreSQL to Snowflake: give each data source its own configuration file, and use each engine's dataset name in the contracts.
The project has this layout:
soda/
├── legacy.yml
├── warehouse.yml
├── sc_config.yml
└── contracts/
├── legacy_fact_internet_sales.yml
└── warehouse_fact_internet_sales.ymlInstall Soda
Install the Soda package for your data sources and the reconciliation extension from the private PyPI. Use your Soda Cloud API key as the credentials. This example uses the US region; for the EU region, use enterprise.pypi.cloud.soda.io.
pip install "soda-postgres>4" "soda-reconciliation" \
-i "https://${SODA_API_KEY_ID}:${SODA_API_KEY_SECRET}@enterprise.pypi.us.soda.io" \
--extra-index-url=https://pypi.cloud.soda.io/simpleFor the private PyPI repositories of each license and region, see Soda Core installation.
Connect to the source and the target
Create one data source configuration file for each database. The values in ${env.…} are read from environment variables.
Create a Soda Cloud configuration file to publish the results. Use cloud.us.soda.io or cloud.soda.io, depending on your Soda region.
Test the connections from the soda folder:
Check the source before migrating
Data that is wrong in the source is wrong in the target. Verify the source table first, and fix what fails before you migrate.
To create a first contract for an existing table, you can also use Contract Autopilot in Soda Cloud.
Reconcile the target with the source
The target contract names the source table under reconciliation.sources and compares the two with four checks:
schema_diffcompares the column names and data types.row_count_diffcompares the number of rows.metric_diffcompares a total computed on each side.rows_diffmatches the rows by key and compares the values in each row.
Pass both data source files to --data-source, so Soda can query the source and the target:
For every reconciliation check and its options, see Reconciliation checks.
Results
When the migration copies the table correctly, all four checks pass.
When it doesn't, the checks show what went wrong. For example, a migration that maps sales_amount to an integer column rounds every amount. All the rows arrive, so Row count matches the legacy table passes. Schema matches the legacy table fails on the data type, Sales total matches the legacy table fails on the rounded total, and Every sale matches the legacy table fails on the rows whose amounts changed.

Next steps
Learn the use cases and performance considerations of Data reconciliation.
Run the reconciliation as a task after the migration job. See Test data quality in an Airflow pipeline.
Keep verifying the migrated table after go-live on a schedule.
Last updated
Was this helpful?
