generate_database_seed_script Database

Generate SQL seed scripts from confirmed field mappings

Overview

Takes a confirmed field mapping and the full source data to produce a SQL seed script ready for import into the target platform's database. Downloads the source file, applies the mapped transformations record by record, generates INSERT statements in dependency order, and wraps everything in a transaction. The resulting .sql file is uploaded to Backblaze B2 for download.

How It Works

  1. Loads the confirmed field map and all its entries.
  2. Downloads the full source file from Backblaze B2.
  3. Applies each field mapping record by record: field routing, transformations (multiply_100, slugify, etc.), UUID generation with platform-specific prefixes, FK linkage between related entities.
  4. Assembles metadata JSONB for fields routed to metadata columns.
  5. Emits SQL INSERTs in the target's dependency order, wrapped in BEGIN/COMMIT with ON CONFLICT handling.
  6. Uploads the .sql file to B2 and records metadata (statement count, table counts, warnings).

Input Parameters

ParameterTypeRequiredDescription
job_id string required Clone job ID
field_map_id string required ID of a confirmed field map (status must be 'confirmed')

What You Get Back

Example Use Case

After confirming a WooCommerce → Medusa v2 field mapping, generate the seed script. It produces SQL that inserts products (with prod_ prefixed IDs), variants (with variant_ prefixed IDs), price sets with amounts in cents, categories, tags, and all join table records — in the correct dependency order.

Tips

The field map must have status 'confirmed' before generating a seed script.
The generated SQL uses ON CONFLICT DO NOTHING for safe re-running.
Review table_counts to verify all expected entities were generated.
Download the .sql file and review it before running against your target database.

Related Tools