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.
Minimal: Namespaces and Execut method
- Namespaces have moved (remove and add new ones)
- Updater.Execute now takes
ILogger
andILoggerFactory
- Updater is now called from within a
INotificationHandler<UmbracoApplicationStarting>
class, so we can check runtime level.
var upgrader = new Upgrader(new DoStuffMigrationPlan());
upgrader.Execute(scopeProvider, migrationBuilder, keyValueService, logger);
var upgrader = new Upgrader(new DoStuffMigrationPlan());
upgrader.Execute(scopeProvider, migrationBuilder, keyValueService, logger, loggerFactory);
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.
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.
After all the migrations have ran, post migrations run, this is the place you might want to put code that happens as the end
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.
Blogs from Stephan (Core team Dev)
Umbraco Source for their own Migrations