<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1" -->

---
title: Writing Migration Schematics with ng update | daily.dev
description: Part 4 of a six-part series on Angular Schematics explains how to build migration schematics that run automatically via ng update when a library's consumers...
canonical: https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Writing Migration Schematics with ng update | daily.dev
og:description: Part 4 of a six-part series on Angular Schematics explains how to build migration schematics that run automatically via ng update when a library's consumers...
og:url: https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1
og:image: https://api.daily.dev/og/posts/7rdL70mU1.png
og:image:alt: Writing Migration Schematics with ng update
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing Migration Schematics with ng update

**[Angular.love](https://daily.dev/sources/angularlove)** · 13 min read · 0 upvotes · 0 comments

## Summary

Part 4 of a six-part series on Angular Schematics explains how to build migration schematics that run automatically via ng update when a library's consumers upgrade versions. It walks through the migrations.json manifest, version gating logic, and building two concrete migrations: renaming a component selector across HTML templates using tree.visit() with regex, and updating an app.config.ts provider registration using the addRootProvider utility. It also covers composing migrations with chain, safety guardrails (idempotency, scoping to src/, write-only-on-change), and how to test migrations locally with --from, --to, and --migrate-only flags.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://angular.love/angular-schematics-deep-dive-part-4-writing-migration-schematics-with-ng-update>

## Questions this post answers

### How does Angular's ng update decide which migrations to run when upgrading a library?

The Angular CLI reads the migrations.json manifest referenced by the ng-update field in package.json, compares the consumer's installed version against the target version, and runs only the migrations whose declared version falls within that range, executing them in version order. A consumer on 4.9.0 upgrading to 5.0.0 only gets migrations not yet applied, while one on 2.x gets every migration from 3.x onward.

_daily.dev surfaces practical guidance like this for teams planning library upgrade paths._

### How do I update the app.config.ts providers array from an Angular schematic without manually editing the file?

Use the addRootProvider utility exported from @schematics/angular/utility, which locates app.config.ts for a given project, finds the providers array, inserts a new provider expression, and adds the required import statement automatically, handling idempotency and formatting. It accepts a callback returning a code tagged template literal, e.g. code`${external('provideAcmeUi', '@acme/ui')}({ animations: true })`.

_Developers automating Angular config changes can find this kind of workflow detail via daily.dev._

### How can I test an Angular ng update migration locally before publishing it?

Run ng update with the --from and --to flags plus --migrate-only to simulate a version upgrade without changing the installed package or bumping package.json, and add --dry-run to preview changes without writing them. The --name flag targets a single migration by its schematic name, which is useful for iterating on one transformation at a time.

_daily.dev helps developers validating schematic changes stay on top of Angular tooling workflows._

## Similar posts on daily.dev

- [How to Migrate a Legacy Monolith Incrementally Without a Big-Bang Rewrite](https://daily.dev/posts/how-to-migrate-a-legacy-monolith-incrementally-without-a-big-bang-rewrite-kvyh32xa2) · freeCodeCamp · 0 upvotes · 0 comments
- [TypeScript 6.0 Migration Guide: What's Changed and How to Update](https://daily.dev/posts/typescript-6-0-migration-guide-what-s-changed-and-how-to-update-cjiclvukg) · SitePoint · 5 upvotes · 0 comments
- [Upgrading to TypeScript 6: A Real-World Migration](https://daily.dev/posts/upgrading-to-typescript-6-a-real-world-migration-wo1pvxrxk) · TypeScript.TV · 2 upvotes · 0 comments
- [Ng-News 26/01: Ng-Poland Outtakes - Keynote and Q&A](https://daily.dev/posts/ng-news-26-01-ng-poland-outtakes---keynote-and-q-a-rhtqe5mte) · This is Angular · 2 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#angular](https://daily.dev/tags/angular)

[View this post on daily.dev](https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Writing Migration Schematics with ng update","url":"https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1"},"datePublished":"2026-09-20T07:44:43.568Z","dateModified":"2026-09-20T07:48:40.031Z","description":"Part 4 of a six-part series on Angular Schematics explains how to build migration schematics that run automatically via ng update when a library's consumers...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2c72217aef2c19eb41a5388b30c40492?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2c72217aef2c19eb41a5388b30c40492?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Angular.love","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Angular.love","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/b638946cd9c74bf6a260e4e6a40212d7","url":"https://daily.dev/sources/angularlove"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"typescript,angular","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Angular.love","item":"https://daily.dev/sources/angularlove"},{"@type":"ListItem","position":3,"name":"Writing Migration Schematics with ng update"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/writing-migration-schematics-with-ng-update-7rdl70mu1#faq","mainEntity":[{"@type":"Question","name":"How does Angular's ng update decide which migrations to run when upgrading a library?","acceptedAnswer":{"@type":"Answer","text":"The Angular CLI reads the migrations.json manifest referenced by the ng-update field in package.json, compares the consumer's installed version against the target version, and runs only the migrations whose declared version falls within that range, executing them in version order. A consumer on 4.9.0 upgrading to 5.0.0 only gets migrations not yet applied, while one on 2.x gets every migration from 3.x onward. daily.dev surfaces practical guidance like this for teams planning library upgrade paths."}},{"@type":"Question","name":"How do I update the app.config.ts providers array from an Angular schematic without manually editing the file?","acceptedAnswer":{"@type":"Answer","text":"Use the addRootProvider utility exported from @schematics/angular/utility, which locates app.config.ts for a given project, finds the providers array, inserts a new provider expression, and adds the required import statement automatically, handling idempotency and formatting. It accepts a callback returning a code tagged template literal, e.g. code`${external('provideAcmeUi', '@acme/ui')}({ animations: true })`. Developers automating Angular config changes can find this kind of workflow detail via daily.dev."}},{"@type":"Question","name":"How can I test an Angular ng update migration locally before publishing it?","acceptedAnswer":{"@type":"Answer","text":"Run ng update with the --from and --to flags plus --migrate-only to simulate a version upgrade without changing the installed package or bumping package.json, and add --dry-run to preview changes without writing them. The --name flag targets a single migration by its schematic name, which is useful for iterating on one transformation at a time. daily.dev helps developers validating schematic changes stay on top of Angular tooling workflows."}}]}
```

