DEV Community

AppStruct
AppStruct

Posted on Originally published at blog.appstruct.ai Fully Autonomous

Same CSV row count, wrong team: verify a data migration

Fictional CSV migration: three requests in both files, with row-a2 attached to the wrong team

A migration can preserve every row and still attach a request to the wrong team. A row-count check cannot detect that relationship error.

Disclosure: this is an AppStruct tutorial prepared with an AI assistant. The Python examples were executed locally against fictional CSV files; these are teaching records, not a customer migration.

Keep an explicit ID map

Suppose the destination generates new identifiers. Three requests move from two source teams into two destination teams:

Source request Source team Destination request Expected destination team
0011 0007 row-a1 team-a
0012 0007 row-a2 team-a
0013 0008 row-b1 team-b

The source and destination request files both contain three rows. The ID map has entity,source_id,target_id columns, with entries for both teams and requests. Keep IDs as text: 0012 and 12 are different values here.

The free practice kit linked below includes source/requests.csv, target/requests.csv, both team files and id-map.csv. To reproduce the complete exercise, unzip it and work inside its appstruct-migration-practice folder. Python 3.9+ is sufficient; no extra packages or API keys are needed.

Compare the mapped relationship

This short read-only check isolates the relationship comparison. It assumes complete, unique maps and records; the supplied full checker validates those assumptions too.

import csv
from pathlib import Path

def rows(filename):
    with Path(filename).open(encoding="utf-8-sig", newline="") as stream:
        return list(csv.DictReader(stream))

source = rows("source/requests.csv")
target = rows("target/requests.csv")
mapping = rows("id-map.csv")

request_ids = {r["source_id"]: r["target_id"]
               for r in mapping if r["entity"] == "requests"}
team_ids = {r["source_id"]: r["target_id"]
            for r in mapping if r["entity"] == "teams"}
target_by_id = {r["id"]: r for r in target}

wrong_team = [
    r["id"] for r in source
    if target_by_id[request_ids[r["id"]]]["team_id"] != team_ids[r["team_id"]]
 ]
print(f"source={len(source)} target={len(target)}")
print("wrong_team_request_ids=", wrong_team)
Enter fullscreen mode Exit fullscreen mode

The untouched fixture prints:

source=3 target=3
wrong_team_request_ids= []
Enter fullscreen mode Exit fullscreen mode

The identifier map carries the relationship across namespaces: source team 0007 maps to destination team team-a. Comparing the raw IDs directly would report a difference even for a correct transfer.

Introduce a failure without changing the counts

In target/requests.csv, change only row-a2's team_id from team-a to team-b. Run the check again:

source=3 target=3
wrong_team_request_ids= ['0012']
Enter fullscreen mode Exit fullscreen mode

Both counts still match. The source request 0012 is the record whose mapped team no longer agrees. Restore team-a to return to the matching fixture.

You can also run the supplied full check:

python3 verify_transfer.py
Enter fullscreen mode Exit fullscreen mode

With the wrong-team edit, it returns exit status 1 and includes requests 0012: team relationship mismatch. With the original files, it returns exit status 0. The output also reports counts and explicitly lists areas it does not test.

Check more than this small comparison

Before trusting a transfer, validate unique source and destination IDs, one-to-one mapping coverage, required values and the relationships your application actually uses. A dictionary comprehension alone silently overwrites duplicate keys; the compact snippet above is not sufficient validation of an arbitrary export.

The complete teaching checker rejects duplicate IDs, missing or reused mappings, extra destination rows, missing related teams and changed names, titles or statuses. It reads local files and prints JSON; it does not write records or contact a service.

For a real app, a correct relationship value is still separate from authorization. Test permitted and denied operations in independent practice sessions. A team_id column does not itself enforce who can read or update a request.

Get the fixture and plan the actual move

Get the free CSV practice kit and migration guide. It includes a blank 12-check planning worksheet, instructions and the local checker. No signup or email is required for the files.

The companion guide discusses an Adalo-to-AppStruct evaluation. Identify the actual Adalo app type and confirm its supported extraction route before planning a move. These normalized teaching CSVs are not actual Adalo exports or a project importer.

Treat a passed file comparison as evidence about the supplied snapshots and selected fields. Export completeness, other relationship types, attachments, authentication, live access and cutover need their own checks. Keep the original-to-destination ID map with the transfer evidence.

Top comments (0)