Designing and Testing Transforms
This page is a step-by-step process for building a transform config for a migration and proving that it is correct, first on sample documents, then on a full dataset, then on live changes. It works the same whether you write the config by hand or have an AI agent write it.
You do not need exact knowledge of the source data or a final destination schema to start. The process is built to find the surprises: legacy documents, fields that hold different types in different documents, and destination requirements that change.
Start the web-api once; steps 3 to 7 use it:
docker run -e DSYNCT_MODE=simple -p 8080:8080 markadiom/dsynct --host-port 0.0.0.0:8080 web-api --simple-onlyTransform Studio and the Sync Tester are under Tools in the web UI. See Web-API.
What You Need
Read access to the source, in a test environment and later in production.
A destination you can write test data to and delete from.
For each destination table or collection, a description of the shape you want. It does not have to be precise.
Step 1: Decide Whether You Need a Transform
Go through When You Need a Transform. Then read What Transforms Cannot Do with your target shape in mind. If the target needs joins, aggregation, or an ID built from non-ID fields, settle that before writing any config.
Step 2: Learn What the Source Emits
A transform works on what the connector emits, which is not always what you see in the database. Read the Emitted Format section of your source connector's reference page. Note four things:
The data type: JSON or BSON.
The ID: which fields, in which order, and with which types.
Fields the connector adds or removes.
What CDC events look like, and whether deletes and inserts are reported as such.
Step 3: Collect Sample Documents
Aim for about 20 documents per namespace. Three ways to get them:
From the source through Dsync. For sources that support fetching by ID (MongoDB, Cosmos DB NoSQL), use the Sample menu in the Sync Tester, or the
sample-idscommand, to pick random IDs, then preview the documents in the Sync Tester. This shows documents exactly as the connector emits them.From the database directly. Export documents with the database's own tools. Then adjust them to the emitted format from step 2, for example by removing system fields.
By hand. Write documents from what you know of the schema. Use this only to get started.
Random samples miss rare shapes. Add documents on purpose:
The oldest and the newest documents in each namespace.
Documents with optional fields missing, null or empty.
For schemaless sources, one document for each type a field can hold (a number in one document, a string in another).
Documents with the largest arrays and the deepest nesting.
Every ID shape in use (for example ObjectIDs and strings in the same collection).
Keep the samples in files. They become your regression set in Changing a Transform Later.
Step 4: Write the First Config
Start from the template for your source and destination. It handles the data type and the ID.
Add one mapping per source namespace, or a
defaultmappingif all namespaces follow the same rule.Add field recipes for the differences between the source documents and the target shape.
Leave everything else out. Fields without a mapping are copied as they are.
Rules that prevent most first-time mistakes:
The destination ID must be computed from the source
idonly, in bothmapidand thecelentry for the ID field, with the same resulting type. See CDC Events.Every field in
addneeds acelentry.Numbers from a JSON source need
int(self)ordouble(self)before arithmetic. See Values as CEL Sees Them.Misspelled options are ignored without an error.
Step 5: Iterate on Samples
Open Tools > Transform Studio, paste the config and one sample document, and run it. Nothing is written anywhere. The steps and field descriptions are in Transform Studio.
For each sample, check:
The
Dataresult has the fields, names and types you want. BSON output is shown as extended JSON, so{"$numberLong": "7"}and{"$numberInt": "7"}tell you the exact type.The ID in the
UpdateandDeleteresults equals the ID field in theDataresult, including its type.No mode shows an error.
Run every sample, not only the first one. A config that works for a typical document often fails on the legacy ones.
To run all samples in one go, or to let an AI agent do it, call the same function through the API. See Transform API.
Step 6: Copy Real Documents End to End
Transform Studio shows what the transform produces. It does not show whether the destination accepts it, or what the destination stores. Copy a small set of real documents and read them back.
Pick the IDs: the sampled IDs from step 3 plus the edge cases.
Run Test Sync in the Sync Tester, or the
testsynccommand, with the transform, into a test destination.Read the documents from the destination database with its own client. Check the stored types there: dates as dates, integers as the intended width, decimals as decimals.
Compare the number of documents written with the number of IDs submitted.
The source must support fetching by ID. For other sources (SQL Batch, DynamoDB), skip to step 8 with a small test table.
Step 7: Test CDC
CDC uses parts of the config that the initial sync does not: mapid, and the handling of deletes.
First, in Transform Studio. For each sample, look at the Insert, Update and Delete results. If your source sends partial updates, tick Show partial update as well.
Then, against real databases. Run a sync that skips the initial copy and only streams changes:
With Temporal, pass --skip-initial-sync to dsynct run instead.
While it runs, make these changes on the source and check the destination after each one:
Insert a new document
The document appears, transformed.
Update a field that the transform converts or renames
The same document changes. No second document appears.
Update a document that was copied earlier by testsync or an initial sync
The existing document changes. A duplicate here means mapid and the ID field mapping disagree.
Delete a document
The document is removed. If it stays, the delete ID does not match the stored ID.
Insert a document that the transform filters out
Nothing appears.
Check the source connector's reference page for event types it does not produce. For example, SQL Batch reports inserts as updates.
Step 8: Run the Full Dataset in a Test Environment
Samples cannot cover every document. A full run in a test environment finds the rest.
Survey run. The goal is a complete list of problems in one pass, without stopping at the first one.
Set
filtererrors: trueat the top of the transform config. Documents that fail to transform are skipped and logged, one line per document, with the ID and the reason.Start the sync with
--ignore-write-failures, so that documents the destination rejects do not stop the sync.Let the initial sync finish.
Collect the results:
Transform failures: the
transform.conversion_errorcounter per namespace gives the count. Thefilter-errorlog lines give the ID and the reason for each document.Write failures: check the
dsynct.writtenmetric withsuccess=false, and compare document counts per namespace between source and destination.Destination shape: inspect the fields and types that were actually stored, for example with a schema analysis tool on the destination.
Fix the config, add the failing documents to your samples, and repeat steps 5 to 8 until the survey run is clean.
What each error means and where to find it is in Troubleshooting Transforms.
Strict run. Remove filtererrors and --ignore-write-failures, clear the destination and run again. This is the configuration to use in production: any failure stops the sync and is visible, instead of silently skipping data.
Verify. Run verification on the result. With a transform, use sample-ids and verify-ids with the same transform config to compare a sample of documents.
Step 9: Run in Production
Production data often contains shapes that the test environment does not.
If you can, repeat the survey run from step 8 against production data into a non-production destination.
If a full survey is too expensive, run it for the namespaces with the oldest or least uniform data, and use
sample-idswith a large--countandtestsyncfor the others.Run the real migration with the strict configuration.
Watch the Progress view in the Web-API for activity errors, the
transform.conversion_errorcounter, and thedsynct.get_transformanddsynct.writtenmetrics withsuccess=false. See Observability.Before cutover, verify as in step 8.
Changing a Transform Later
Destination schemas change during a project. To change a transform without breaking what already works:
Keep the sample documents from step 3 and the output you accepted for each, as files.
After editing the config, run all samples again through the Transform API and compare with the accepted output. Only the fields you meant to change should differ.
Repeat step 6 for the affected namespaces.
Restart every worker on the queue with the new file. Workers on the same queue must not run different configs.
Documents already on the destination were written with the old config. If the change affects stored fields, plan to re-sync the affected namespaces.
Reverse Sync
A reverse sync copies changes from the new database back to the old one, usually as a fallback after cutover. It is a separate sync with source and destination swapped, and it needs its own transform file that undoes the forward mapping. Dsynct has no --reverse option: start the reverse sync as a new sync (or run with Temporal) with the connectors swapped, the reverse transform file as the third argument, and --skip-initial-sync, so that only changes made after the cutover are copied back.
Write the reverse config. For each forward mapping, swap
namespaceandmapnamespace, invert the ID mapping, and convert types back. See Reverse Sync Pairs.Test it with steps 5 to 7, like any other transform. The "source" is now the new database.
Check the round trip: take a sample document from the old database, run it through the forward config, run the result through the reverse config, and compare with the original. Differences in types (a number that returns as a string) need an explicit conversion in the reverse config.
Things that do not reverse on their own:
Fields the forward transform deleted are gone. The reverse sync cannot restore them.
One-way conversions, such as hashes and fake data.
IDs where the forward mapping dropped a part. If a two-part source ID was collapsed by keeping only one part, the reverse mapping cannot rebuild the other. Keep all parts in the destination ID (for example joined with a separator) if you plan to reverse.
New documents created on the new database need an ID that is valid on the old one.
Working With an AI Agent
An agent can do steps 4, 5 and the regression check on its own if it has the right inputs:
This page, the Config Reference, IDs, Data Types and CDC Events, Templates, the CEL Reference and the reference page of your source connector. Add
.mdto any page URL to get Markdown.The sample documents from step 3, per namespace, in the emitted format.
The target shape for each destination namespace.
The address of a running web-api, so that it can test each config with the Transform API and read the errors.
Ask it to return, for each namespace, the config, the output for every sample, and a list of samples it could not handle. Review the ID mapping and every type conversion yourself, then continue with step 6.
Last updated