Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration type identification error #16248

Closed
hyzx86 opened this issue Jun 5, 2024 · 9 comments · Fixed by #16257
Closed

Migration type identification error #16248

hyzx86 opened this issue Jun 5, 2024 · 9 comments · Fixed by #16257
Milestone

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Jun 5, 2024

Error while running migration version 0 for 'OrchardCore.Contents'. 
OrchardCore.Recipes.Models.RecipeExecutionException: SQLite Error 1: 'no such table: DeploymentPlanIndex'.

It should have something to do with #15793.
/cc @gvkries

/// </summary>
private IDataMigration[] GetDataMigrations(string featureId)
{
var migrations = _dataMigrations
.Where(dm => _typeFeatureProvider.GetFeaturesForDependency(dm.GetType()).Any(feature => feature.Id == featureId))
.ToArray();
return migrations;
}
/// <summary>

When OrchardCore.Contents is passed in, it recognises its submodule's migration type as its own, e.g. ExportContentToDeploymentTargetMigrations, which is actually the ExportContentToDeploymentTarget is part of the ExportContentToDeploymentTarget feature.

src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetMigrations.cs

Originally posted by @hyzx86 in #16212 (comment)

Full Log

Error while running migration version 0 for 'OrchardCore.Contents'. OrchardCore.Recipes.Models.RecipeExecutionException: SQLite Error 1: 'no such table: DeploymentPlanIndex'.
 ---> Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: DeploymentPlanIndex'.
   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
   at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements()+MoveNext()
   at Microsoft.Data.Sqlite.SqliteCommand.GetStatements()+MoveNext()
   at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
   at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 434
   at YesSql.Store.<>c__DisplayClass44_0`2.<<ProduceAwaitedAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at YesSql.Data.WorkDispatcher`2.ScheduleAsync[TState](TKey key, TState state, Func`3 valueFactory)
   at YesSql.Store.ProduceAwaitedAsync[T,TState](WorkerQueryKey key, Func`3 work, TState state)
   at YesSql.Services.DefaultQuery.Query`1.ListImpl()
   at YesSql.Services.DefaultQuery.Query`1.ListImpl()
   at OrchardCore.Deployment.DeploymentPlanService.CreateOrUpdateDeploymentPlansAsync(IEnumerable`1 deploymentPlans) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore.Modules\OrchardCore.Deployment\DeploymentPlanService.cs:line 97
   at OrchardCore.Recipes.Services.RecipeExecutor.<>c__DisplayClass8_0.<<ExecuteStepAsync>b__0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 188
--- End of stack trace from previous location ---
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 275
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteStepAsync(RecipeExecutionContext recipeStep) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 171
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 103
   --- End of inner exception stack trace ---
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 128
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 147
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 157
   at OrchardCore.Recipes.Services.RecipeMigrator.ExecuteAsync(String recipeFileName, IDataMigration migration) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeMigrator.cs:line 55
   at OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget.ExportContentToDeploymentTargetMigrations.CreateAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore.Modules\OrchardCore.Contents\Deployment\ExportContentToDeploymentTarget\ExportContentToDeploymentTargetMigrations.cs:line 31
   at OrchardCore.Data.Migration.DataMigrationManager.InvokeMethodAsync(MethodInfo method, IDataMigration migration) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 254
   at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 216    at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 128
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 147
   at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeExecutor.cs:line 157
   at OrchardCore.Recipes.Services.RecipeMigrator.ExecuteAsync(String recipeFileName, IDataMigration migration) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Recipes.Core\Services\RecipeMigrator.cs:line 55
   at OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget.ExportContentToDeploymentTargetMigrations.CreateAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore.Modules\OrchardCore.Contents\Deployment\ExportContentToDeploymentTarget\ExportContentToDeploymentTargetMigrations.cs:line 31
   at OrchardCore.Data.Migration.DataMigrationManager.InvokeMethodAsync(MethodInfo method, IDataMigration migration) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 254
   at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 216

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 5, 2024

It looks like we should keep the FeatureAttribute on the migration type of the submodule

image

@Piedone
Copy link
Member

Piedone commented Jun 5, 2024

How is this different to #16223?

@gvkries
Copy link
Contributor

gvkries commented Jun 5, 2024

Do you have an easy way to reproduce the issue?

@gvkries
Copy link
Contributor

gvkries commented Jun 6, 2024

The problem is that the migration manager is not allowing a migration to have more than one feature. But after removing the FeatureAttribute from migrations, they will always be assigned to the main feature of their parent module and afterwards to the more specific feature via DI. So they will have two features if more than one migration is contained in a assembly.

There are two solutions possible:

  1. The data migration manager can always just use the last feature for a migration. This will always be the right feature as long as migrations are added to a single startup only. But this will not be obvious for anyone looking at the migration manager and may break if we change something in future.
  2. We can introduce a way to force types to be assigned to a single feature only.

I tend to suggest the second option.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 6, 2024

Just like this ?

public class MyMigration :DataMigration<MyFeatureStartup>

It has the advantage of introducing strong type-checking and not needing to log those strings anymore~

@gvkries
Copy link
Contributor

gvkries commented Jun 6, 2024

That would be the same as applying the FeatureAttribute like before. We wanted to avoid having to do that manually each time. I think we can add something to the base interface IDataMigration.

Copy link
Contributor

github-actions bot commented Jun 6, 2024

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

@Piedone
Copy link
Member

Piedone commented Jun 6, 2024

But after removing the FeatureAttribute from migrations, they will always be assigned to the main feature of their parent module and afterwards to the more specific feature via DI.

Why is that the case? Shouldn't just the second happen?

@gvkries
Copy link
Contributor

gvkries commented Jun 6, 2024

All public types were previously added to the main feature as well, even if they were not in DI or had no attribute. So to keep it compatible, this feature assignment was kept. But I haven't thought enough about the migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants