Closed jptissot closed 3 years ago
"tj5ogvh_IDX_WorkflowBlockingActivitiesIndex_DocumentId_Activity" already exists.
It's probably trying to execute a migration that has already created this index previously. If the index is already there then you should either remove it so that the migration executes successfully or just increment the migration number in the database table and leave it like it is to avoid getting an exception raised.
Now, why is it doing this is what we need to find though. One reason could be that someone uses Azure Shell configurations for development but that it's ASPNETCORE_ENVIRONMENT variable is not set to development. This can execute the migration on the prod server database before even having it published.
Log from the All Databases CI Artifact for the ComingSoon recipe.
https://github.com/OrchardCMS/OrchardCore/actions/runs/548869771
2021-02-08 18:22:20.6741||||Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager|WARN|No XML encryptor configured. Key {a898706b-b391-4aca-96c5-70865671e5d8} may be persisted to storage in unencrypted form.
2021-02-08 18:22:21.2780||||Microsoft.AspNetCore.Server.Kestrel|WARN|Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
2021-02-08 18:22:21.4220||||Microsoft.AspNetCore.Server.Kestrel|WARN|Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
2021-02-08 18:23:07.0382|t1v3mvk||acae604c-4d49eaba22c11046.||OrchardCore.Data.Migration.DataMigrationManager|ERROR|Error while running migration version 0 for 'OrchardCore.Workflows'. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> Npgsql.PostgresException (0x80004005): 42P07: relation "t1v3mvk_IDX_WorkflowBlockingActivitiesIndex_DocumentId_Activity" already exists
at Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in /_/Dapper/SqlMapper.cs:line 2813
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in /_/Dapper/SqlMapper.cs:line 572
at YesSql.Sql.SchemaBuilder.Execute(IEnumerable`1 statements)
at YesSql.Sql.SchemaBuilder.AlterTable(String name, Action`1 table)
at YesSql.Sql.SchemaBuilder.AlterIndexTable(Type indexType, Action`1 table, String collection)
at YesSql.Sql.SchemaBuilderExtensions.AlterIndexTable[T](ISchemaBuilder builder, Action`1 table, String collection)
at OrchardCore.Workflows.Migrations.Create() in /_/src/OrchardCore.Modules/OrchardCore.Workflows/Migrations.cs:line 87
Exception data:
Severity: ERROR
SqlState: 42P07
MessageText: relation "t1v3mvk_IDX_WorkflowBlockingActivitiesIndex_DocumentId_Activity" already exists
File: index.c
Line: 884
Routine: index_create
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId) in /_/src/OrchardCore/OrchardCore.Data/Migration/DataMigrationManager.cs:line 200 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId) in /_/src/OrchardCore/OrchardCore.Data/Migration/DataMigrationManager.cs:line 200
2021-02-08 18:23:07.1896|t1v3mvk||acae604c-4d49eaba22c11046.||Microsoft.AspNetCore.Server.Kestrel|ERROR|Connection id "0HM6CBPUHP1KS", Request id "0HM6CBPUHP1KS:0000002A": An unhandled exception was thrown by the application. Npgsql.PostgresException (0x80004005): 42P01: relation "t1v3mvk_ContentItemIndex" does not exist
at Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 418
at YesSql.Store.ProduceAsync[T](WorkerQueryKey key, Func`2 work, Object[] args)
at YesSql.Services.DefaultQuery.Query`1.ListImpl()
at OrchardCore.ContentManagement.DefaultContentManager.ImportAsync(IEnumerable`1 contentItems) in /_/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs:line 452
at OrchardCore.Contents.Recipes.ContentStep.ExecuteAsync(RecipeExecutionContext context) in /_/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs:line 33
at OrchardCore.Recipes.Services.RecipeExecutor.<>c__DisplayClass7_0.<<ExecuteStepAsync>b__0>d.MoveNext() in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 174
--- End of stack trace from previous location where exception was thrown ---
at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in /_/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs:line 243
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteStepAsync(RecipeExecutionContext recipeStep) in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 159
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, Object environment, CancellationToken cancellationToken) in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 103
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, Object environment, CancellationToken cancellationToken) in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 120
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, Object environment, CancellationToken cancellationToken)
at OrchardCore.Setup.Services.SetupService.SetupInternalAsync(SetupContext context) in /_/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs:line 196
at OrchardCore.Setup.Services.SetupService.SetupAsync(SetupContext context) in /_/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs:line 87
at OrchardCore.Setup.Controllers.SetupController.IndexPOST(SetupViewModel model) in /_/src/OrchardCore.Modules/OrchardCore.Setup/Controllers/SetupController.cs:line 181
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in /_/src/OrchardCore/OrchardCore/Modules/ModularTenantRouterMiddleware.cs:line 64
at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in /_/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs:line 243
at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in /_/src/OrchardCore/OrchardCore/Modules/ModularTenantContainerMiddleware.cs:line 61
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Exception data:
Severity: ERROR
SqlState: 42P01
MessageText: relation "t1v3mvk_ContentItemIndex" does not exist
Position: 73
File: parse_relation.c
Line: 1180
Routine: parserOpenTable at Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 418
at YesSql.Store.ProduceAsync[T](WorkerQueryKey key, Func`2 work, Object[] args)
at YesSql.Services.DefaultQuery.Query`1.ListImpl()
at OrchardCore.ContentManagement.DefaultContentManager.ImportAsync(IEnumerable`1 contentItems) in /_/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs:line 452
at OrchardCore.Contents.Recipes.ContentStep.ExecuteAsync(RecipeExecutionContext context) in /_/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs:line 33
at OrchardCore.Recipes.Services.RecipeExecutor.<>c__DisplayClass7_0.<<ExecuteStepAsync>b__0>d.MoveNext() in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 174
--- End of stack trace from previous location where exception was thrown ---
at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in /_/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs:line 243
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteStepAsync(RecipeExecutionContext recipeStep) in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 159
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, Object environment, CancellationToken cancellationToken) in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 103
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, Object environment, CancellationToken cancellationToken) in /_/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs:line 120
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, Object environment, CancellationToken cancellationToken)
at OrchardCore.Setup.Services.SetupService.SetupInternalAsync(SetupContext context) in /_/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs:line 196
at OrchardCore.Setup.Services.SetupService.SetupAsync(SetupContext context) in /_/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs:line 87
at OrchardCore.Setup.Controllers.SetupController.IndexPOST(SetupViewModel model) in /_/src/OrchardCore.Modules/OrchardCore.Setup/Controllers/SetupController.cs:line 181
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in /_/src/OrchardCore/OrchardCore/Modules/ModularTenantRouterMiddleware.cs:line 64
at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in /_/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs:line 243
at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in /_/src/OrchardCore/OrchardCore/Modules/ModularTenantContainerMiddleware.cs:line 61
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
I am pretty sure this is due to the fact that the ComingSoon recipe enables the Workflows module ?
Ok, there is definitely something going wrong with the indices there.
I think the issue is related with the indices name length. When we look at the Workflow migrations there is 2 new indices created.
SchemaBuilder.AlterIndexTable<WorkflowBlockingActivitiesIndex>(table => table
.CreateIndex("IDX_WorkflowBlockingActivitiesIndex_DocumentId_ActivityId",
"DocumentId",
"ActivityId",
"WorkflowTypeId",
"WorkflowId")
);
SchemaBuilder.AlterIndexTable<WorkflowBlockingActivitiesIndex>(table => table
.CreateIndex("IDX_WorkflowBlockingActivitiesIndex_DocumentId_ActivityName",
"DocumentId",
"ActivityName",
"WorkflowTypeId",
"WorkflowCorrelationId")
);
Here because of the PostgreSQL name length limit it uses only "IDX_WorkflowBlockingActivitiesIndex_DocumentId_Activity" for both.
Fix suggested is to create a new Upgrade step that will remove these and rename it with a shorter name :
IDX_WFBA_DocumentId_ActivityId IDX_WFBA_DocumentId_ActivityName
One thing I've noticed is that we always use the word "index" in our index names... which I think is not necessary. The IDX prefix already tells us it's an index ...
/cc @jtkech @sebastienros
@Skrypt Yes you're right
No luck, i did a func test on all databases, but i missed it after adding the last index related to ActivityName
.
Hmm, on google they say it is 63 chars and IDX_WorkflowBlockingActivitiesIndex_DocumentId_ActivityName
= 59 chars, maybe it depends on the version, would be interesting to know the real limitation, based on your test seems to be 55 chars.
At least we need to be aware of this limitation and to confirm the real limitation. Yes we can use an acronym and / or remove the Index
part, , maybe only for the very long ones, for now just those that exceeds the limitation.
Just found this one IDX_ContentPickerFieldIndex_DocumentId_SelectedContentItemId
I saw that we can't alter a column with sqlite, but good to know that we can drop indexes with all providers. So, because we aded all the DocumentId
indexes, maybe worth to add a migration step to all modules to remove all the redundant indexes, @Skrypt @deanmarcussen what you think? Maybe at least open an issue for this.
Oh yes, i didn't do it as we use drop index if exists
that is not supported with my 2014 version, as they say in the doc
IF EXISTS Applies to: SQL Server ( SQL Server 2016 (13.x) through current version).
Hmm, on google they say it is 63 chars and
IDX_WorkflowBlockingActivitiesIndex_DocumentId_ActivityName
= 59 chars, maybe it depends on the version, would be interesting to know the real limitation, based on your test seems to be 55 chars.
The issue is when you add a tenant prefix, you are pretty limited in length.
@jptissot
But it adds a prefix to the table name, not to the index names of this table, right?
Describe the bug
Error occurs on Postgresql when enabling our Hackathon feature. Works fine with SQLite but with postgresql, the site completely crashes.
To Reproduce
Create a tenant with a long enough name to go over the 64 character limit for table names on postgresql
Expected behavior
Migrations to execute without crashing the site.
Screenshots
I will add to this issue when I find more information. Just investigating right now.