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
- Loads the confirmed field map and all its entries.
- Downloads the full source file from Backblaze B2.
- 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.
- Assembles metadata JSONB for fields routed to metadata columns.
- Emits SQL INSERTs in the target's dependency order, wrapped in BEGIN/COMMIT with ON CONFLICT handling.
- Uploads the .sql file to B2 and records metadata (statement count, table counts, warnings).
Input Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
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
- Seed script ID
- B2 download URL for the .sql file
- Total SQL statement count
- Per-table record counts (e.g. product: 150, product_variant: 320)
- Warnings about unmappable data or transformation issues
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.
