umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.4k stars 2.66k forks source link

V13: Exception when trying to upgrade a V12 site #14992

Open AndyButland opened 10 months ago

AndyButland commented 10 months ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.0.0--rc.preview.28.g42bc50e

Bug summary

When starting up Umbraco, I go to /install and run the upgrade. It fails with the following message:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.\r\n ---> Umbraco.Cms.Core.Install.InstallException: The database failed to upgrade. ERROR: The database configuration failed with the following message: Unable to resolve service for type 'Umbraco.Cms.Infrastructure.Migrations.IEFCoreMigrationExecutor' while attempting to activate 'Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_12_1_0.AddOpenIddict'.\n Please check log file for additional information (can be found in 'LoggingSettings.Directory')
   at Umbraco.Cms.Infrastructure.Install.InstallSteps.DatabaseUpgradeStep.ExecuteAsync(Object model)
   at InvokeStub_InstallSetupStep`1.ExecuteAsync(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Umbraco.Cms.Web.BackOffice.Install.InstallApiController.ExecuteStepAsync(InstallSetupStep step, Object instruction)
   at Umbraco.Cms.Web.BackOffice.Install.InstallApiController.PostPerformInstall(InstallInstructions installModel)

Running a second time I get:

The database configuration failed with the following message: There is already an object named 'umbracoOpenIddictApplications' in the database

Specifics

I'm was originally upgrading from a 12.0.1 website and got the first error.

I then retried first going to 12.2.0, and that was OK, apart from the second error. When I deleted the tables, I could proceed and complete. And then when I upgraded to the 13 preview, no further upgrade was needed.

I'm not sure quite what happened with the first issue unless you can replicate when trying a similar upgrade from 12.0,1.

But probably the upgrade step that adds the OpenIddict tables should be made idempotent, so it just skips over tables that already exist and doesn't try to create them again.

Steps to reproduce

Try to upgrade from 12.0.1 to 13.0.0--rc.preview.28.g42bc50e

Expected result / actual result

Should upgrade without error, and should be able to re-run the migrations without an error due to tables already existing.

Zeegaan commented 10 months ago

Wierd one indeed, this works for me πŸ› I installed 12.0.1 using dotnet new install Umbraco.Templates::12.0.1 I installed and just created a content. Then updated to 13.0.0--rc.preview.28.g42bc50e That worked just fine πŸ€”

AndyButland commented 10 months ago

Hmm... maybe ignore the first issue then, as it wasn't really clear to my why it happened and why I was able to migrate via 12.2, as it ran the same things.

But perhaps there is something to think about with regard the newer migrations that I see are now using EF Core.

The existing migrations tend to do a check to see if something exists before creating it - e.g. like this one.

With the new ones though, there's not that equivalent - so that might cause issues if re-running migrations on a database that's already updated. I know we do that in development a fair bit when switching branches. Not sure if there are other cases where someone using Umbraco might run into it though. At least it's different though, so probably should be thought about and maybe see if a check for existence should be added to the EF core migrations.

Zeegaan commented 10 months ago

Agreed, we should probably look into this. EFCore does that the __EFMigrationsHistory which should keep track of which migrations has been run, but we should probably keep them idempotent anyways πŸ€”

marcloveUSN commented 10 months ago

Hi Folks,

I am also hitting this error however I haven't been able to resolve it. The migration will not run. All I see is the Migration record getting added to umbracoKeyValue. When @AndyButland said 'When I deleted the tables', what tables did you actually delete?

Trying to go from 12.0.1 to 12.2.0

Cheers,

Marc

AndyButland commented 10 months ago

When @AndyButland said 'When I deleted the tables', what tables did you actually delete?

The umbracoOpenIddict* ones - that the migration was trying to add and would fail if they already existed.

marcloveUSN commented 10 months ago

Hi Andy, thanks for getting back so quickly. I dont get these tables created. Migration just fails. User in connection string has full permissions to create tables so a bit lost at why the migration is failing.

mattbrailsford commented 10 months ago

I think I'm seeing the same issue as Marc here. I'm upgrading a v12 site to v13 and I'm getting an error SqliteException: SQLite Error 1: 'no such table: umbracoOpenIddictApplications'.

As you can see, I'm using SQLite and so I'm wondering if this is part of the issue? (not sure what Marc using)

When I look in the DB the table doesn't exist so the migration hasn't run, but more interesting, there isn't a __EFMigrationsHistory table either so I'm wondering if this is what is causing this migration to fail seeing as that table is created via an EFCore migration.

mattbrailsford commented 10 months ago

Hmm, deleting the core migration line in umbracoKeyValue and re-running the migrations seems to have done it. Weirdly, but prior and after migration, my DB record states the value as {C76D9C9A-635B-4D2C-A301-05642A523E9D} yet I can't see a migration step with that ID in the Umbraco migration plan πŸ€”

Zeegaan commented 10 months ago

We've just had a go at this, and could still not reproduce. I'm wondering what version you tried to upgrade from? πŸ€”

We've tried from 12.0.1, but I do see this migration in 12.1 To<V_12_1_0.AddOpenIddict>("{47DE85CE-1E16-42A0-8AF6-3EC3BCEF5471}");

enkelmedia commented 5 months ago

Just got the same error when upgrading to v14 beta

SqliteException: SQLite Error 1: 'no such table: umbracoOpenIddictApplications'.
Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(int rc, sqlite3 db)
Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements()+MoveNext()
Microsoft.Data.Sqlite.SqliteCommand.GetStatements()+MoveNext()
Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
Microsoft.Data.Sqlite.SqliteCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable<T>+AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable<T>+AsyncEnumerator.MoveNextAsync()
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable<TResult>+ConfiguredValueTaskAwaiter.GetResult()