Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Reconciliation checks require the soda-reconciliation package from the private PyPI, which is available with an Enterprise license. Need access? Contact us.

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.yml

Install 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/simple

For 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_diff compares the column names and data types.

  • row_count_diff compares the number of rows.

  • metric_diff compares a total computed on each side.

  • rows_diff matches 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.

The Checks tab of the warehouse fact_internet_sales dataset in Soda Cloud, with the row count check passed and the schema, sales total and row checks failed
Reconciliation results after a faulty migration

Next steps

Last updated

Was this helpful?