Skip to content

Latest commit

 

History

History

Migrations

Migrations

Umbraco Migrations allow you to control the structure of the database, create tables, columns, indexes, run custom SQL and generally do everything you need to prep any custom stuff you might have in the Database.

Changes from v8 to NetCore

Minimal: Namespaces and Execut method

  1. Namespaces have moved (remove and add new ones)
  2. Updater.Execute now takes ILogger and ILoggerFactory
  3. Updater is now called from within a INotificationHandler<UmbracoApplicationStarting> class, so we can check runtime level.

v8:

var upgrader = new Upgrader(new DoStuffMigrationPlan());
upgrader.Execute(scopeProvider, migrationBuilder, keyValueService, logger);

NetCore:

var upgrader = new Upgrader(new DoStuffMigrationPlan());
upgrader.Execute(scopeProvider, migrationBuilder, keyValueService, logger, loggerFactory);

Migration Plan

A Migration plan tells umbraco how to get from one state of your application to another, in general this will be how to install your app, create tables etc. but when you do upgrades it will also tell umbraco how to do them.

Migration

A Migration is a single element that does something, this is where you create a table or update and index etc.

in umbraco 8 there is a simple Migrate method that is called when umbraco is running the migrations -this is where you do stuff.

Post Migration

After all the migrations have ran, post migrations run, this is the place you might want to put code that happens as the end

Note about execution order

Its important to note that any SQL generated by a migration doesn't run there and then. instead it is bulked together by the Migration Runner and all ran together.

This is subtle but important, because if you add a migration and then immediately think you can do something in code with the data - you can't

To manipulate the data from a migration use a post migration step.

See also

Blogs from Stephan (Core team Dev)

Umbraco Source for their own Migrations