Skip to main content
Contentstack MCP profile hub is in general availability!

Audit your content model before a migration

•
12 min read

The short answer: before you migrate, inventory every content type and field, count entries per content type and how often each field is filled, find content types nobody uses or that duplicate each other, map how deep your references go and where they loop, check how global fields and modular blocks are reused, list your taxonomies and tags and clean up the terms, and check which locales actually have content. Then decide per content type whether to keep, merge, drop or refactor it, write down the target model and a mapping sheet from old fields to new ones, and only then run the migration.

Most migration tools copy the model you have. That is what you want for the move itself, but it means every unused field, every near-duplicate content type and every free-text tag comes along. This guide shows how to run the audit against a Contentstack stack with the CLI and the Content Management API (CMA). The method is the same for any source CMS: export the schema, count what is actually used, and decide before you move. If your source is Contentful, the Contentful migration guide covers the move. This guide is the step before it.

What you'll learn

  • How to export a stack's schema with csdx and the Content Management API

  • How to measure entries per content type and field fill rates with a small Node script

  • How to find reference chains and circular references, and check them against Contentstack limits

  • How to audit taxonomies and tags and rationalize terms

  • How to turn the numbers into keep, merge, drop or refactor decisions and a mapping sheet

  • What to change during the move and what to leave for after

Step 1: Export the schema

Start with a copy of the model you can read and diff. The CLI writes one JSON file per content type and global field:

csdx auth:tokens:add --management --alias audit-source \
  --stack-api-key <stack_api_key> --token <management_token>

csdx cm:stacks:export -a audit-source --branch main \
  --module content-types --data-dir ./export
csdx cm:stacks:export -a audit-source --branch main \
  --module global-fields --data-dir ./export
csdx cm:stacks:export -a audit-source --branch main \
  --module taxonomies --data-dir ./export
csdx cm:stacks:export -a audit-source --branch main \
  --module locales --data-dir ./export

Commit the export folder. It is your "before" snapshot, and every later model decision can be reviewed as a diff against it. If an export fails or hangs, csdx import and export failures covers the usual causes.

If your source is another CMS, use its own schema export. What matters is that you end up with a machine-readable list of content types, fields, field types and reference targets.

Step 2: Count what is actually used

A schema tells you what editors can fill in. It doesn't tell you what they do fill in. For that you need entry counts and fill rates, which means reading entries.

The script below uses the CMA with a management token. It lists content types with GET /v3/content_types, reads every entry of each content type with GET /v3/content_types/{uid}/entries, and counts how many entries have a value in each top-level field. It also collects reference targets, taxonomy terms and tags as it goes, so you only read the entries once.

// audit.mjs, run with: node audit.mjs
import { writeFile } from "node:fs/promises";

const HOST = process.env.CS_CMA_HOST ?? "https://api.contentstack.io";
const headers = {
  api_key: process.env.CS_API_KEY,
  authorization: process.env.CS_MANAGEMENT_TOKEN,
  branch: process.env.CS_BRANCH ?? "main",
};
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function get(path, params = {}) {
  const url = new URL(`/v3${path}`, HOST);
  for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
  for (let attempt = 1; attempt <= 5; attempt++) {
    const res = await fetch(url, { headers });
    if (res.status === 429) { await sleep(1000 * attempt); continue; }
    if (!res.ok) throw new Error(`${res.status} ${path}: ${await res.text()}`);
    await sleep(150); // stay well under 10 CMA reads per second
    return res.json();
  }
  throw new Error(`Still rate limited on ${path}`);
}

async function getAll(path, key, params = {}) {
  const items = [];
  for (let skip = 0; ; skip += 100) {
    const page = await get(path, { ...params, include_count: true, limit: 100, skip });
    items.push(...page[key]);
    if (page[key].length < 100 || items.length >= page.count) return items;
  }
}

// Flatten a schema into field paths, including groups, blocks and global fields
function walk(schema = [], prefix = "", out = []) {
  for (const field of schema) {
    const path = prefix + field.uid;
    out.push({ path, field });
    if (field.data_type === "group" || field.data_type === "global_field") walk(field.schema, `${path}.`, out);
    if (field.data_type === "blocks") for (const b of field.blocks ?? []) walk(b.schema, `${path}.${b.uid}.`, out);
  }
  return out;
}

const isEmpty = (v) =>
  v == null || v === "" || (Array.isArray(v) && v.length === 0) ||
  (typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 0);

const contentTypes = await getAll("/content_types", "content_types", { include_global_field_schema: true });
const report = { contentTypes: [], references: {}, terms: {}, tags: {} };

for (const ct of contentTypes) {
  const fields = walk(ct.schema);
  const topLevel = ct.schema.map((f) => f.uid);
  const entries = await getAll(`/content_types/${ct.uid}/entries`, "entries");
  const filled = Object.fromEntries(topLevel.map((uid) => [uid, 0]));
  let lastUpdated = null;

  for (const entry of entries) {
    for (const uid of topLevel) if (!isEmpty(entry[uid])) filled[uid]++;
    for (const t of entry.taxonomies ?? []) {
      const key = `${t.taxonomy_uid}/${t.term_uid}`;
      report.terms[key] = (report.terms[key] ?? 0) + 1;
    }
    for (const tag of entry.tags ?? []) report.tags[tag] = (report.tags[tag] ?? 0) + 1;
    if (!lastUpdated || entry.updated_at > lastUpdated) lastUpdated = entry.updated_at;
  }

  report.references[ct.uid] = [...new Set(fields
    .filter(({ field }) => field.data_type === "reference")
    .flatMap(({ field }) => [].concat(field.reference_to)))];

  report.contentTypes.push({
    uid: ct.uid,
    entries: entries.length,
    lastUpdated,
    totalFields: fields.length,
    modularBlocksFields: ct.schema.filter((f) => f.data_type === "blocks").length,
    globalFields: fields.filter(({ field }) => field.data_type === "global_field").map((f) => f.path),
    fillRate: Object.fromEntries(topLevel.map((uid) =>
      [uid, entries.length ? Math.round((filled[uid] / entries.length) * 100) : 0])),
  });
}

await writeFile("audit-report.json", JSON.stringify(report, null, 2));
console.table(report.contentTypes.map(({ uid, entries, totalFields, lastUpdated }) =>
  ({ uid, entries, totalFields, lastUpdated })));

Set CS_API_KEY, CS_MANAGEMENT_TOKEN and CS_BRANCH, and set CS_CMA_HOST if your stack is not in AWS North America. Use a management token, not your user authtoken, for scripts like this.

A few things to know before you trust the numbers:

  • The CMA allows 10 read requests per second per organization by default, shared with everything else that calls it. The script waits between requests and backs off on 429. On a large stack it takes a while, so run it outside working hours.

  • Get all entries accepts a locale parameter. The script doesn't pass one, so add it and run the script per locale if your locales differ a lot.

  • The emptiness check is shallow. A JSON RTE field with an empty paragraph, or a group whose sub-fields are all blank, counts as filled. Spot-check the fields that score high but look suspicious.

Step 3: Find unused and duplicate content types

Sort the table by entries and lastUpdated. Three patterns show up in almost every stack:

  • Content types with zero or a handful of entries. Often a test, a one-off campaign, or a type someone started and abandoned. Check with the owner, then plan to drop it.

  • Content types nobody has touched in a long time. If the newest entry is years old and the frontend no longer renders it, it is archive content. Decide whether it migrates at all.

  • Fields under 10 percent fill rate. Either the field is optional for a real reason, or nobody uses it. Ask the editors which one it is.

Duplicates take one more step. Add this to the end of audit.mjs to flag pairs of content types that share most of their top-level fields:

const ids = Object.fromEntries(report.contentTypes.map((c) => [c.uid, new Set(Object.keys(c.fillRate))]));
for (const [a, fa] of Object.entries(ids)) for (const [b, fb] of Object.entries(ids)) {
  if (a >= b) continue;
  const shared = [...fa].filter((f) => fb.has(f)).length;
  const overlap = shared / new Set([...fa, ...fb]).size;
  if (overlap > 0.7) console.log(`${a} and ${b} share ${Math.round(overlap * 100)}% of fields`);
}

news_article and press_release with the same fields are usually one content type with a taxonomy term for the kind of article.

Step 4: Map reference depth and circular references

report.references is a graph: each content type points at the content types its reference fields allow. Walk it at the end of the script to find the longest chain and any loops:

const cycles = new Set();
let deepest = [];
function visit(node, path) {
  if (path.includes(node)) return cycles.add([...path.slice(path.indexOf(node)), node].join(" -> "));
  const next = [...path, node];
  if (next.length > deepest.length) deepest = next;
  for (const target of report.references[node] ?? []) visit(target, next);
}
for (const uid of Object.keys(report.references)) visit(uid, []);
console.log("Deepest chain:", deepest.join(" -> "));
console.log("Cycles:", [...cycles]);

Compare the result with the limits that bite at delivery and publish time:

  • include_all_depth on the REST Delivery API goes up to 5 levels, with at most 100 reference paths per request.

  • Multiple content type reference fields resolve up to 3 levels, and the GraphQL Content Delivery API stops at 3 levels too.

  • Nested reference publishing sends references along up to 5 levels deep.

A chain like page, section, card, author, company is already past what GraphQL resolves. A cycle such as article referencing related articles is normal, but a long loop through four content types usually means the model is doing the job of a taxonomy or a navigation structure. To check one content type by hand, GET /v3/content_types/{uid}/references lists the content types that reference it, directly or nested. Nested references empty or error 141 shows what deep chains look like from the frontend, and Contentstack limits on one page has the full list.

Step 5: Review global fields and modular blocks

Use totalFields, modularBlocksFields and globalFields from the report to check each content type against the schema limits:

  • A content type can hold 400 fields, counting everything inside modular blocks, groups and global fields.

  • A content type can have 5 modular blocks fields and 25 global fields, and blocks nest 2 levels deep.

Then look for the reuse you are missing and the reuse you are faking. The same set of SEO fields copied into six content types is a global field waiting to happen. A modular block that editors fill in with the same testimonial on ten pages should be a reference, because a global field shares the structure, not the values. Modular blocks, references or global fields has a decision table for these calls.

Step 6: Audit taxonomies and tags

List the stack's taxonomies and their terms with GET /v3/taxonomies and GET /v3/taxonomies/{taxonomy_uid}/terms, or read them from the export folder. Then compare with report.terms:

  • Terms with zero entries are candidates to drop.

  • Terms with near-identical names in one taxonomy, or the same idea in two taxonomies, are candidates to merge.

  • Tags are free text. Sort report.tags and you will find "Next.js", "nextjs" and "next" next to each other. Tags you filter or build listings on should move into a taxonomy, where editors pick from a controlled list.

Check the target against the taxonomy limits: 25 terms per entry, 10,000 terms per taxonomy, 10 levels deep, and one Taxonomy field per content type, which can hold several taxonomies. Taxonomies are your query layer explains why small, closed taxonomies make better filters than a long list of topics, and Querying content by taxonomy shows how the result is queried.

Step 7: Check locales

List locales with GET /v3/locales or from the export. For each one, ask whether it has real content and whether anyone maintains it. A locale with a few dozen translated entries out of thousands is usually relying on fallback. Contentstack supports one level of fallback, so a chain like de-at to de-de to en-us in your old CMS needs a decision: flatten it, or translate the missing content.

Step 8: Decide keep, merge, drop or refactor

Put every content type on one list and give it one decision:

  • Keep: used, owned, and the shape fits. Migrates as is.

  • Merge: overlaps another content type. Pick the survivor, map the other's fields onto it, and add a taxonomy term if the difference was the kind of content.

  • Drop: unused, abandoned or archive-only. Export the entries somewhere safe, then leave them out.

  • Refactor: used, but the shape is wrong. Deep chains, copied field sets, tags that should be terms.

Do the same for low fill-rate fields, and get the decisions signed off by whoever owns the content.

Step 9: Write the target model and a mapping sheet

The mapping sheet is the contract between the audit and the migration. One row per source field:

source_type,source_field,decision,target_type,target_field,transform,owner
news_article,headline,merge,article,title,none,content team
press_release,title,merge,article,title,none,content team
press_release,,merge,article,taxonomies,add term article_type/press_release,content team
article,legacy_banner,drop,,,,web team
article,tags,refactor,article,taxonomies,map tag spellings to subjects terms,content team

What to refactor during the move and what to leave for after

Drop and merge during the move. Migrating content you will delete next month costs time, rate limit and a second cleanup. Converting tags to taxonomy terms also fits here, because the mapping is mechanical.

Leave refactors that need large frontend changes for after the move. If the migration also rewrites your data layer, every model change adds code changes on top. The Contentful tooling, for example, records a field mapping and rewrites queries for a one-to-one move, and treats global fields as an optional refactor rather than part of the migration. Get to a working site first. The what migrates and how to verify chapter has the checklist for that point.

After the move, make model changes on a branch. Script them with cm:stacks:migration, diff them against main with cm:branches:diff, and merge them, or point your frontend at an alias and repoint it when the new model is ready. Keep changes additive: add new fields before you remove old ones. Taxonomies are global across branches, so plan term deletions separately. Safe content model changes with branches and aliases walks through the full loop.

Next steps

Frequently asked questions

  • What should I check in a content model before a CMS migration?

    Inventory content types and fields, measure how many entries each content type has and how often each field is filled, find unused and duplicate content types, map reference depth and circular references, review global fields and modular blocks, rationalize taxonomies and tags, and check locales. Then decide per content type whether to keep, merge, drop or refactor it, and write a mapping sheet.

  • How do I count entries per content type in Contentstack?

    Call GET /v3/content_types/{content_type_uid}/entries on the Content Management API with include_count=true. The response includes a count next to the entries. Page through with limit and skip, because one request returns at most 100 entries.

  • Should I refactor the content model during the migration or after it?

    Drop and merge during the move, because that is cheaper than migrating content you will delete. Keep renames and restructures that need code changes small during the move, and do larger refactors afterwards on a branch, where you can diff, merge and roll back.

  • Does the Contentful migration tool clean up my content model?

    No. It converts the model you have into a Contentstack bundle, field by field. Global fields are an optional refactor, not part of the one-to-one migration. Audit the model first and change it before or after the move.