Skip to content

Generator optimization checklist

git Damru — Status of the migration script generator against the optimization checklist.

CategoryItemStatusNotes
Primary key resolutionDetect PK / composite PKUses sqlTable.primaryKey; composite supported in upsert filter.
Generate correct Mongo upsert filterSingle-field: { idField: docId }; composite: { f1: v1, f2: v2 }.
Avoid duplicate/null-coalescing artifactsSingle ID path for composite; minimal fallbacks for single PK.
Batch / cursor strategyFull-scan vs batched paginationConfig migration.batchSize; 0 = full scan, >0 = LIMIT/OFFSET.
Emit LIMIT/OFFSET or cursor-based loopBatched loop with ORDER BY for deterministic pages.
Configurable batch sizemigration.batchSize in config (default 0).
Relation handlingDetect foreign keysVia object fields + name matching (*_id, *id).
Decide embed vs reference⚠️Embed by default (nested object); reference via schema.
Generate preload map or lazy fetchPreload dependency collections into Maps.
MongoDB index generationCreate indexes for PK and FK fieldsScript ensures indexes before writes.
Apply unique: true where applicablePK and SQL unique constraints → unique index.
Field naming strategyPreserve original names OR camelCase⚠️Preserves SQL names; optional camelCase via schema/mapping.
Keep strategy configurable📋Future: config migration.fieldNaming.
Document shape strategyFlat vs nested documentsNested via NoSqlField object + fields.
Controlled depth for embedded relations⚠️Depth from schema; no explicit depth limit.
ID strategyNatural key vs generated _idNatural key from PK or first id-like field.
Support composite identifiersComposite PK used as multi-field filter.
Memory safetyAvoid loading full tablesBatched mode streams via LIMIT/OFFSET.
Stream or batch large tablesmigration.batchSize enables batching.
Dry-run / preview modeGenerate scripts that can simulate migrationmigration.dryRun: true in config.
No writes when enabledSkips all updateOne when dry run.
Progress loggingPeriodic counters (every N rows)migration.progressEvery (default 1000).
Table-level summary logsFinal migrated count and errors.
Error handling strategySkip-on-error vs fail-fastmigration.skipOnError (default false).
Row-level error loggingLogs row identifier and error when skip-on-error.
Config validationFail early on missing connection/schemaConfig file + Postgres connection checked.
Validate relation config⚠️Schema-driven; no extra relation config yet.
Re-runnable safetyIdempotent upsertsupdateOne with upsert: true.
No duplicate inserts on re-runSame filter → same document updated.
Extensibility hooksClearly marked GENERATED blocks// --- BEGIN GENERATED --- / // --- END GENERATED ---.
Safe manual edit zonesbuildDoc and config read outside generated block.
Production readinessIndex-first, write-later orderingScript creates indexes then migrates.
Deterministic ordering in queriesORDER BY on PK columns in batched query.

Legend: ✅ Done | ⚠️ Partial | 📋 Planned

Config (migration scripts)

Scripts read sql2nosql.config.json. Relevant keys:

json
{
  "connection": "postgres://...",
  "schema": "public",
  "mongodb": {
    "uri": "mongodb://localhost:27017",
    "database": "sql2nosql",
    "collectionPrefix": ""
  },
  "migration": {
    "batchSize": 0,
    "dryRun": false,
    "skipOnError": false,
    "progressEvery": 1000
  }
}
  • batchSize: 0 = load all rows; >0 = paginate with LIMIT/OFFSET.
  • dryRun: true = no MongoDB writes, only logs.
  • skipOnError: true = log and continue on row errors; false = throw and exit.
  • progressEvery: log progress every N rows (0 = only final summary).

Running migration scripts

Run all migrations with Node:

bash
cd packages/cli && node output/scripts/run-all.migrate.js

Scripts are generated under output/scripts/ (regenerated on each sql2nosql analyze). Ensure sql2nosql.config.json is at the project root; use migration.dryRun: true to test without writing to MongoDB.

Damru