We're using Umbraco migrations for creating custom database tables. This has always worked without any issues until now. When I try to run a migration the creation of the table works, but I get this exception afterwards:
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 Project.Data.PetaPoco.DbConfiguration.InstallOrUpgrade() in d:\data\inetpub\project\Sources\Project.Data.PetaPoco\DbConfiguration.cs:line 69
So after the migration is completed it tries to delete a cookie. Because this doesn't work the version in the umbracoMigration doesn't go up. The table does exist in the database afterwards. Any idea what could cause this problem?
This is the migration:
/// <summary>
/// Runs on upgrade
/// </summary>
public override void Up()
{
this.Create.Table("paymentLog")
.WithColumn("Id").AsInt32().Identity().PrimaryKey("PK_paymentLog")
.WithColumn("Date").AsDateTime().NotNullable()
.WithColumn("Status").AsString(100).Nullable()
.WithColumn("Request").AsCustom("nvarchar(MAX)").Nullable()
.WithColumn("Response").AsCustom("nvarchar(MAX)").Nullable();
}
try
{
migrationsRunner.Execute(this.db, true);
}
catch (HttpException e)
{
// because umbraco runs some other migrations after the migration runner is executed we get httpexception
// we cacht this error, but don't do anything
}
catch (Exception e)
{
// we catch all other errors
LogHelper.Error<DbConfiguration>("Error running migrations", e);
}
So we catch that httpexception. But still the version number in the table doesn't go up.
This is the code we have for running the migrations :
public class DbConfiguration : IDbConfiguration
{
private readonly Database db;
/// <summary>
/// Initializes a new instance of the <see cref="DbConfiguration"/> class.
/// </summary>
public DbConfiguration()
{
this.db = DatabaseHelper.GetDatabase();
}
/// <summary>
/// Installs or upgrades db tables when needed
/// </summary>
public void InstallOrUpgrade()
{
var currentVersion = new SemVersion(0, 0, 0);
var migrations = ApplicationContext.Current.Services.MigrationEntryService.GetAll(Constants.ProductName);
var latestRunMigration = migrations.OrderByDescending(x => x.Version).FirstOrDefault();
if (latestRunMigration != null)
{
currentVersion = latestRunMigration.Version;
}
var targetVersion = new SemVersion(Constants.Version);
if (currentVersion == targetVersion)
{
// we do no need to run migrations
return;
}
var migrationsRunner = new MigrationRunner(
ApplicationContext.Current.Services.MigrationEntryService,
ApplicationContext.Current.ProfilingLogger.Logger,
currentVersion,
targetVersion,
Constants.ProductName);
try
{
migrationsRunner.Execute(this.db, true);
}
catch (HttpException e)
{
// because umbraco runs some other migrations after the migration runner is executed we get httpexception
// we cacht this error, but don't do anything
}
catch (Exception e)
{
// we catch all other errors
LogHelper.Error<DbConfiguration>("Error running migrations", e);
}
}
}
It's the first migration that we have the error with. We already did more than 50 succesfully. I personnaly think it's a edge case.
Umbraco migration suddenly not working
Hello,
We're using Umbraco migrations for creating custom database tables. This has always worked without any issues until now. When I try to run a migration the creation of the table works, but I get this exception afterwards:
So after the migration is completed it tries to delete a cookie. Because this doesn't work the version in the umbracoMigration doesn't go up. The table does exist in the database afterwards. Any idea what could cause this problem?
This is the migration:
Jeroen
I see in our DbConfiguration we do the following
So we catch that httpexception. But still the version number in the table doesn't go up.
Jeroen
Please log an issue with steps to reproduce and we can determine what is happening and where things are going wrong and why.
Hi Shannon,
This is the code we have for running the migrations :
It's the first migration that we have the error with. We already did more than 50 succesfully. I personnaly think it's a edge case.
Will look further into it with Jeroen on Monday.
Dave
yeah but how/when is this executing?
On startup of the application. Trying to reproduce this today.
Dave
We found the issue. This website already has been upgraded a couple of times. Also to Umbraco 7.3.0. Our own migration also reached this number. The code which checks the version number doesn't check the product name: https://github.com/umbraco/Umbraco-CMS/blob/d50e49ad37fd5ca7bad2fd6e8fc994f3408ae70c/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs#L292
When we used a version number that's not inserted by an Umbraco migration it works again.
Also created an issue for this: http://issues.umbraco.org/issue/U4-7872
Jeroen
Pull request is submitted : https://github.com/umbraco/Umbraco-CMS/pull/1078
is working on a reply...