Beyond the First Import: Advanced Migration Workflows with My Migration Tool

Technical Director
  • Twitter
  • LinkedIn

Part 5 of a five-part series on SitecoreAI migration and my new migration tool.

A first plugin can work from one source export and produce one instruction file. A larger migration usually needs more context.

The target may already contain templates and page designs that must be reused. Presentation changes may need to preserve existing composition. Media files need a route from the source to the target. Generating the right instructions is only useful if the target can actually retrieve and apply them.

These are the V3 features and project patterns I would reach for as a migration moves beyond its first page.

Use a target export as a second repository

A target repository is an exported view of the destination, not a live connection.

It lets a plugin inspect existing target items before generating instructions. For example, the code can find a target template by path, resolve its ID and check whether a required page design exists. A more detailed project validator can inspect template fields and inheritance.

Configure the repositories in a job file:

{
  "schemaVersion": 1,
  "assembly": "bin/Debug/net8.0/Migration.Project.dll",
  "entries": ["MapProductPage"],
  "output": "output",
  "fieldCacheMemoryMb": 256,
  "repositories": [
    {
      "alias": "source",
      "provider": "ndjson",
      "source": "source-exports"
    },
    {
      "alias": "target",
      "provider": "yaml",
      "source": "target-items"
    }
  ]
}

Replace the assembly path and entry name with your own. Paths resolve relative to the job file, and each repository can use a different provider.

Assuming the published host is on your command path:

Migrate.exe generate --job .\migration-job.json --check
Migrate.exe generate --job .\migration-job.json

Inside an entry, the repositories are available by alias:

var source = job.Repositories.Get("source");
var target = job.Repositories.Get("target");

var heroTemplate = target.FindByPath(
    "/sitecore/templates/Project/SiteCollection/Site/Hero")
    ?? throw new InvalidOperationException(
        "The target Hero template is missing.");

Finding an item proves its existence in that snapshot, not its suitability for every use. A production mapping should also check the field contracts it depends on.

V3 does not automatically reconcile the two repositories or calculate a safe merge. The plugin owns those decisions. Refresh the target export as the implementation changes, and verify the live target again before import.

Combine exports without confusing them with instructions

The NDJSON provider can open a folder of source exports. That is useful when the source team supplies content, templates and media metadata separately.

Give each extracted file a distinct name, such as content.ndjson and media.ndjson. The provider recursively reads the folder and joins the item relationships into one repository.

Exports must not repeat the same item IDs. Exporting an item twice to supply different languages or versions does not create an automatic merge. Missing external parents can also limit traversal, so choose roots with the required structure and dependencies in mind.

Keep generated instruction files elsewhere. They also end in .ndjson, but they represent operations and do not belong in a source-item repository.

Rebuild or transform presentation deliberately

Presentation XML describes rendering instances, their definitions, data sources, placeholders and parameters. Shared __Renderings and versioned __Final Renderings contribute different parts of Sitecore's presentation model.

When the new component model is substantially different, I prefer to assemble the intended target composition from reviewed mappings. A migration that copies the old XML unchanged still points to the old rendering contracts.

For narrower edits, the target importer also supports XML Document Transform, or XDT. A value beginning with [[XDT]] in one of those two presentation fields is applied as a transform to the existing field XML.

This entry-method excerpt shows the instruction shape:

var fields = new FieldContainer()
    .SetFirstVersion(
        "en",
        "__Final Renderings",
        "[[XDT]]" + transformXml);

job.Instructions.UpdateFields(page.Item, fields);

The project supplies transformXml and selects page. The target needs the Microsoft.Web.XmlTransform assembly available to the importer.

An XDT transform still needs a precise match. Rendering-definition IDs, rendering-instance IDs and nested placeholder keys have different roles. Matching the wrong one can update several instances or none.

Review the effective result alongside page and partial designs. A transform applied to one raw layout field is not automatically a transformation of every inherited part of the rendered page.

Treat media metadata and file bytes separately

A media item contains Sitecore metadata, but the image or PDF also needs its binary content.

For YAML input, the field snapshot can contain a blob sentinel. The plugin resolves that sentinel into a source download reference before writing the instruction:

var fields = await current.GetFieldsAsync(cancellationToken: cancellationToken);

var projected = fields.Project()
    .Latest()
    .NormalizeToFirst()
    .Build();

var resolved = await projected.ResolveBlobSentinelsAsync(current, cancellationToken);

job.Instructions.CreateItemWithFields(current.Item, resolved);

This excerpt belongs inside a selected media-item loop. It uses the same SDK instruction helpers as ordinary content.

For the PowerShell source exporter, binary data is excluded by default. Enable $IncludeMediaReferences = $true to hash selected source media streams and include relative download URLs instead. The export still does not contain the binary files.

Those references pass through the NDJSON provider and the same blob-resolution helper without another binary read. The reference can contain an MD5 checksum, which the target consumer uses to avoid replacing matching target bytes. Here, MD5 is a change-detection mechanism, not proof that a source is trustworthy.

To apply the instructions, copy the complete contents of Migrate-Data.ps1 into a script tab in the target Sitecore's PowerShell ISE. Configure the existing parameter defaults at the top of that pasted script with the instruction URL, source host and database. For this media example, the parameter block would be:

param(
    [string]$Url = "https://files.example.com/migrations/Media.ndjson",
    [string]$Path = $null,
    [switch]$DryRun = $true,
    [string]$Database = "master",
    [string]$SourceDownloadHost = "https://source-cm.example.com",
    [string]$SourceDatabase = "master",
    [switch]$ForceBlobUpdate = $false,
    [bool]$SilentEdits = $true,
    [switch]$VerboseOutput = $true
)

Execute the entire pasted script using the ISE's Run action. After reviewing the dry-run output, change the $DryRun default to $false and run the entire script again to apply the instructions. The block above configures the full importer; it is not a standalone import script.

The source endpoint must remain reachable from the target and serve the original media, including the correct language/version where applicable. A recorded URL does not preserve those bytes if the source disappears.

Version normalization retains source-routing metadata so that writing target version 1 can still retrieve the original source version. Set the $ForceBlobUpdate default to $true when a target blob deliberately needs replacement despite a matching checksum.

Dry runs do not download or attach the media. Validate the actual download path and resulting files in a lower environment before treating the transfer as proven.

Give the target a reachable instruction URL

The pasted importer's $Path parameter reads a path visible to the target Sitecore process. It cannot read your laptop's output directory just because you open Sitecore's PowerShell ISE in a browser on that laptop.

An HTTPS endpoint is often the simpler handoff. It must return raw NDJSON, rather than an interactive login page or a file-sharing website's HTML.

For a short development session, Cloudflare Quick Tunnels can make a local file server reachable. Start a server restricted to the intended output directory:

py -m http.server 8080 --bind 127.0.0.1 --directory .\output

In a second terminal:

cloudflared tunnel --url http://127.0.0.1:8080

The command prints a temporary HTTPS hostname. Append the instruction filename and use that URL with the target importer. Keep both processes running until the download has completed. Cloudflare Quick Tunnels

A Quick Tunnel is publicly reachable. Serve only the intended files, remember that field values may include unpublished content, and stop it when finished. For repeatable delivery or restricted content, choose an appropriately controlled endpoint instead. A random hostname is not authentication.

Reuse indexes and bound field loading

The repository metadata index makes item selection inexpensive after opening. A persisted protobuf index can avoid repeating the metadata scan during iterative work.

For an NDJSON source folder:

Migrate.exe index build `
  -s .\source-exports `
  --provider ndjson `
  -o .\indexes\source.pb

Add "index": "indexes/source.pb" to that repository in the job file. The index is a metadata snapshot, not a self-updating content cache. Rebuild it after export files change, including additions, removals and renames.

Fields are loaded on demand and cached separately. The fieldCacheMemoryMb setting bounds estimated retained field-cache memory; it is not a limit on total process memory. Binary payloads are outside the normal field cache.

The NDJSON provider also reuses readers. A sequential loop can read many items through one retained file reader, while concurrent loads can obtain independent readers within the configured limit. Migration authors do not need to manage file handles.

Parallel reads can help some transformations, but instruction dependencies and ordering still belong to the plugin. Keep the final creation/update sequence deterministic even if independent field reads happen concurrently.

Keep each handoff reviewable

At this scale, I want to be able to identify the source export, target snapshot, plugin build and generated instruction files used for a run.

Entries can produce separate files, and selected entries run in caller order. Successful output publication is atomic per file. It is not an all-or-nothing transaction across several files or a rollback mechanism for target mutations.

The target importer can warn, skip an operation or continue after a failure. Review its output and inspect the resulting items, media and pages. A completed process does not establish that every intended change succeeded.

That brings the series back to its starting point. A migration tool needs to support the transformation decisions and the operational handoffs around them. V3 makes those stages explicit; the project keeps ownership of the mappings, execution order and evidence that the new site works.

Authoring reference · Source exporter guide · Target importer