I've been working on updating Merchello for Umbraco 7.3.0 compatibility and have a few questions relating to Migrations.
For the past several version of Merchello, I've been using the MigrationRunner to push database changes for new features, similar to the way Umbraco does it's upgrade. When I started looking at this piece for the Umbraco 7.3.0 integration I started running into problems.
It may be that the way I've implemented Migrations in Merchello is not the way they were intended to be used. I could not figure out a good way to launch the installer the way Umbraco does upgrades from Merchello's bootstrapper so I've been doing a really simple check and then kicking off the Migration using the MigrationRunner myself. Hey they worked =)
The MigrationRunner in Umbraco (which has been public for several versions) has had been modified in Umbraco 7.3.0.
My Migrations failed completely when using the now obsoleted constructor
[Obsolete("Use the ctor that specifies all dependencies instead")]
public MigrationRunner(Version currentVersion, Version targetVersion, string productName)
: this(LoggerResolver.Current.Logger, currentVersion, targetVersion, productName)
{
}
I think because of the null setting for the migrations
[Obsolete("Use the ctor that specifies all dependencies instead")]
public MigrationRunner(ILogger logger, Version currentVersion, Version targetVersion, string productName)
: this(logger, currentVersion, targetVersion, productName, null)
{
}
Skipping that constructor, I am able to get to the execute my runner, but now have an issue that states Request is not available in this context
2015-09-28 09:21:48,834 [39] ERROR Umbraco.Core.CoreBootManager - An error occurred running OnApplicationStarted for handler Merchello.Web.UmbracoApplicationEventHandler
System.Web.HttpException (0x80004005): Request is not available in this context
at System.Web.HttpContextWrapper.get_Request()
at Umbraco.Web.HttpCookieExtensions.ExpireCookie(HttpContextBase http, String cookieName)
at Umbraco.Web.Strategies.Migrations.ClearCsrfCookiesAfterUpgrade.AfterMigration(MigrationRunner sender, MigrationEventArgs e)
at Umbraco.Web.Strategies.Migrations.MigrationStartupHander.MigrationRunner_Migrated(MigrationRunner sender, MigrationEventArgs e)
at Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e)
at Umbraco.Core.Events.EventExtensions.RaiseEvent[TSender,TArgs](TypedEventHandler`2 eventHandler, TArgs args, TSender sender)
at Umbraco.Core.Persistence.Migrations.MigrationRunner.Execute(Database database, DatabaseProviders databaseProvider, Boolean isUpgrade)
at Umbraco.Core.Persistence.Migrations.MigrationRunner.Execute(Database database, Boolean isUpgrade)
at Merchello.Core.Persistence.Migrations.CoreMigrationManager.UpgradeMerchello(Database database) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Core\Persistence\Migrations\CoreMigrationManager.cs:line 202
at Merchello.Core.Persistence.Migrations.CoreMigrationManager.EnsureMerchelloVersion() in c:\Working Repositories\GitHub\Merchello\src\Merchello.Core\Persistence\Migrations\CoreMigrationManager.cs:line 112
at Merchello.Web.UmbracoApplicationEventHandler.VerifyMerchelloVersion() in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\UmbracoApplicationEventHandler.cs:line 412
at Merchello.Web.UmbracoApplicationEventHandler.ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\UmbracoApplicationEventHandler.cs:line 115
at Umbraco.Core.ApplicationEventHandler.OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
at Umbraco.Core.CoreBootManager.<Complete>b__8(IApplicationEventHandler x)
at Umbraco.Core.EnumerableExtensions.ForEach[TItem](IEnumerable`1 items, Action`1 action)
at Umbraco.Core.CoreBootManager.Complete(Action`1 afterComplete)
at Umbraco.Web.WebBootManager.Complete(Action`1 afterComplete)
at Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e)
at Umbraco.Core.UmbracoApplicationBase.Application_Start(Object sender, EventArgs e)
2015-09-28 09:22:28,973 [39] INFO Umbraco.Core.UmbracoApplicationBase - Application shutdown. Reason: InitializationError
I'm guessing this has something to do with a notification of a Migration as I do see that a record has been added to the umbracoMigration table with the Merchello (product name) and my test version.
So after all of that, I'm left with the question - Should I continue to execute my migrations outside of an installer or is it intended that all migrations should be run through the Umbraco installer (or each package should create my own)? If I'm to create my own, how should I wire it in?
Also, I had heard that eventually of package actions will eventaully be deprecated and migrations will be preferable for package install and uninstall. I started working on this a while ago, and got stuck when considering a package uninstall. https://groups.google.com/forum/#!topic/umbraco-dev/c_1b6-418SA Based on what I've seen, it appears that starting this effort again is still premature ... correct?
Up to and including 7.3 umbraco migrations are still internal and not intended to be used for your own custom migrations. For that you'll still need to create your own custom migration handler. Something along the lines of how we've done it for "our" is a model you can use.
On ApplicationStarted, check if a text file exists in App_Data
If the file exists then do nothing, this migration already ran
If the file does not exists then the table probably needs to be created
BUT double check if the table exists anyway, just in case
Create the table
Create the text file to indicate to the StartupHandler that it
doesn't need to do anything
In the future, most likely, we'll have a core supported way of doing migrations, but for now, to be safe, you should create your own custom migration handlers.
Umbraco 7.3.0 Migrations
I've been working on updating Merchello for Umbraco 7.3.0 compatibility and have a few questions relating to Migrations.
For the past several version of Merchello, I've been using the MigrationRunner to push database changes for new features, similar to the way Umbraco does it's upgrade. When I started looking at this piece for the Umbraco 7.3.0 integration I started running into problems.
It may be that the way I've implemented Migrations in Merchello is not the way they were intended to be used. I could not figure out a good way to launch the installer the way Umbraco does upgrades from Merchello's bootstrapper so I've been doing a really simple check and then kicking off the Migration using the MigrationRunner myself. Hey they worked =)
The MigrationRunner in Umbraco (which has been public for several versions) has had been modified in Umbraco 7.3.0.
My Migrations failed completely when using the now obsoleted constructor
I think because of the null setting for the migrations
Skipping that constructor, I am able to get to the execute my runner, but now have an issue that states Request is not available in this context
I'm guessing this has something to do with a notification of a Migration as I do see that a record has been added to the umbracoMigration table with the Merchello (product name) and my test version.
So after all of that, I'm left with the question - Should I continue to execute my migrations outside of an installer or is it intended that all migrations should be run through the Umbraco installer (or each package should create my own)? If I'm to create my own, how should I wire it in?
Also, I had heard that eventually of package actions will eventaully be deprecated and migrations will be preferable for package install and uninstall. I started working on this a while ago, and got stuck when considering a package uninstall. https://groups.google.com/forum/#!topic/umbraco-dev/c_1b6-418SA Based on what I've seen, it appears that starting this effort again is still premature ... correct?
@Rusty
Up to and including 7.3 umbraco migrations are still internal and not intended to be used for your own custom migrations. For that you'll still need to create your own custom migration handler. Something along the lines of how we've done it for "our" is a model you can use.
https://github.com/umbraco/OurUmbraco/blob/master/OurUmbraco/Our/MigrationsHandler.cs
The approach is something like:
In the future, most likely, we'll have a core supported way of doing migrations, but for now, to be safe, you should create your own custom migration handlers.
Thanks Paul - Makes sense.
is working on a reply...