Contentful to Sanity Migration: How I Move Content, Assets and Locales
A contentful to sanity migration is mostly a data-mapping exercise with a few sharp edges: rich text, assets, and locales. Done as a script you can re-run, it is low drama. Done by hand in a CMS UI, it becomes a month of copy-pasting. This is the order I work in. When the Contentful bill is the trigger Most migrations I see start with an invoice, not a technical complaint. A site outgrows the…
The migration from Contentful to Sanity involves several key steps. First, the data must be exported and audited using the Contentful CLI. This generates a JSON file containing content types, entries, assets, and locales. Each content type is then marked as keep, merge, or drop. Dead content types that have not been touched in two years can be deleted during this phase.
Next, the content model must be mapped from Contentful to Sanity schemas. While the concepts are similar, there are differences in how they are structured. Contentful content types correspond to Sanity document types, while Contentful rich text is converted to Portable Text format. A decision must be made on which content types should be standalone documents and which should be inline objects. Factors like query cost and avoiding query waterfalls should be considered during this process.
Finally, deterministic IDs are generated to ensure the import process is idempotent. Contentful IDs are mapped to Sanity document IDs, allowing references to be written before the target document exists. Weak references are used during import to avoid ordering issues, and then strengthened once all data has been imported. This structured approach minimizes the effort and risk involved in migrating from Contentful to Sanity.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.