Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 29, 2016 @ 16:23
    Jeroen Breuer
    0

    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:

        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();
    }
    

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 29, 2016 @ 16:36
    Jeroen Breuer
    0

    I see in our DbConfiguration we do the following

    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.

    Jeroen

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jan 29, 2016 @ 21:09
    Shannon Deminick
    0

    Please log an issue with steps to reproduce and we can determine what is happening and where things are going wrong and why.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jan 30, 2016 @ 08:58
    Dave Woestenborghs
    0

    Hi Shannon,

    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.

    Will look further into it with Jeroen on Monday.

    Dave

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jan 31, 2016 @ 11:51
    Shannon Deminick
    0

    yeah but how/when is this executing?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 01, 2016 @ 09:40
    Dave Woestenborghs
    0

    On startup of the application. Trying to reproduce this today.

    Dave

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 01, 2016 @ 10:35
    Jeroen Breuer
    101

    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

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 01, 2016 @ 10:51
    Dave Woestenborghs
    0
Please Sign in or register to post replies

Write your reply to:

Draft