Data Import, Export, and Portability

Check an import before it writes anything. Keep ownership correct, recover from failures, and prove an export can be read and restored.

Content date: October 15, 2026.

Plain English

An import turns records from outside into app data. An export gives someone a copy of chosen data to use elsewhere. Both are powerful operations. A file can parse perfectly and still contain duplicate IDs, records that belong to another customer, a version you do not support, or data the person was never allowed to see.

Use this when

Use this when users bring existing records, ask for a copy of their data, or move between systems. Plan the format before you collect data nobody can read outside your app.

If you are just starting

Define a small format with a version number, required fields, and a size limit. Check the whole file and show a dry-run summary (what would change, with nothing written) first. Take ownership from the signed-in person's context, never from a column in the file. Decide what a failure does: roll back the whole batch, or save clear progress you can resume.

When your project grows

Cap upload size and processing time. Give each batch and row a stable ID, and decide what a retry does with duplicates. Check permission again when the import is applied, because a preview does not grant lasting access. Export only the fields and files the purpose needs, never other tenants' rows or secrets. If users open exports in Excel or Google Sheets, stop cells that start with =, +, -, or @ from running as formulas (OWASP calls this CSV injection). Test that meaning, links, and special characters survive a round trip, not just the row count.

Worked example

A two-row import has a valid first row and a second that reuses an existing ID. Validation reports the clash before either row is saved. In a separate test, a simulated storage failure during the real import rolls back everything. The export names its format version and tenant, and restoring it into an empty practice database gives back the same titles and IDs.

Practice

Dry run, fail, recover, and export

  1. Define a minimal versioned format for one tenant's documents.
  2. Check a good file, then files with duplicate IDs, missing values, or an owner field the file should not control.
  3. Confirm the dry run writes nothing. Then force a failure during the real import and check the rollback or saved progress matches your plan.
  4. Apply the good file, then apply it again, and confirm your duplicate rule held.
  5. Export, restore into an empty database, and compare records and links. Note any uploaded files outside the export.

Deliverable: A short import contract, your dry-run and failure results, and an export-and-restore comparison that says what it covers.

Common mistakes to watch for

  • A tutoring center uploads a CSV with an owner_center column, the importer believes it, and records land in another center's account.
  • Rows 1 to 40 save, row 41 fails, and nobody notices.
  • A user clicks Import twice after a slow response, and every student appears twice.
  • An export for one parent includes another family's rows or an internal notes field.
  • An export lists bookings but leaves out the files and student links needed to read them.

Prompting

A weak prompt

Import this CSV straight into the database, and export everything whenever someone asks.

A better prompt

Define the import and export for [describe the data, for example student rosters] for one authorized tenant, using a small format with a version number and size limit. Validate required fields, IDs, duplicates, and links before writing. Add a dry run, recheck permission when applying, and say whether a failure rolls back or resumes. With made-up data, test a malformed file, a row claiming another owner, a mid-batch failure, a retry, and an export restored into an empty database.

Imports and exports move many records at once, so one missing ownership or failure rule can damage or leak many people's data in a click.

Check before you move on

  • The file format has a version and a size limit.
  • Ownership comes from the signed-in context, not from the file.
  • The dry run writes nothing.
  • You know what a failure leaves behind and how to recover.
  • Retrying an import does not create duplicates.
  • You restored an export and compared contents, not just the count.

You are done when

  • A bad or unauthorized file cannot create partial or wrongly owned records.
  • You exported, restored into an empty database, and the titles, IDs, and links match.

Questions to think about

An admin previewed an import yesterday and clicks Apply today. Can the app trust yesterday's check?

No. Roles, records, or the file itself may have changed overnight. Check permission and the data again when the import actually runs.

You export 10 student records and restore 10 student records. What could still be wrong?

Fields may have changed meaning, IDs may be reassigned, links may be broken, accented characters may be garbled, or attached files may be missing.

A teammate says every import must be all-or-nothing. Is that the only safe design?

No. A resumable import also works if each row has a status, duplicates are blocked, and recovery is clear. Pick a failure rule and test it.

Official references