Ends in:
7 DAYS
16 HRS
40 MIN
13 SEC
Ends in:
7 D
16 H
40 M
13 S
Open Closed

Abp microservices framework template not allowing to migrate to mysql #5170


User avatar
0
smansuri created
  • ABP Framework version: v7.2.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): angular identity server separated with microservices
  • Exception message and stack trace: no option to delete the sql related dlls and entityframeworkcore related dlls
  • Steps to reproduce the issue:" download the commercial solution from abp suite using microservices template. open the solution in visual studio 2022 and and try to remove the Volo.Abp.EntityFrameworkCore.SqlServer NuGet package dependency from the .EntityFrameworkCore project. but it does not allow to remove when you right click the package. We are following https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Other-DBMS article to migrate to mysql.

8 Answer(s)
  • User Avatar
    0
    jfistelmann created

    Hello,

    if the UI in Visual Studio does not allow for it, you can always edit the .csproj directly and make the adjustments needed. You're looking for <PackageReference> entries.

    Example in VS Code:

    Example in Visual Studio: Double Click on your *.EntityFrameworkCore Project

    It will then open the .csproj file for you to edit

    Does that help you?

    Kind regards Jack

  • User Avatar
    0
    smansuri created

    Is there any way we can download the solution with microservices template having mysql as database?

  • User Avatar
    0
    jfistelmann created

    Is there any way we can download the solution with microservices template having mysql as database?

    No, that is not possible as of today. You may want to upvote this feature request here or create a new one

  • User Avatar
    0
    smansuri created

    I have downloaded the fresh solution from abp commercial. Now without making any changes im trying to build all projects. Im able to build all project wituout any issue except "PublicWeb" project under "apps" folder.

    Im getting below error even though the project file has the reference to the G1.Clinic.Doctorz.ProductService.HttpApi.Client.csproj : Severity Code Description Project File Line Suppression State Error NU1105 Unable to find project information for 'D:\G1_abp\G1.Clinic.Doctorz\services\product\src\G1.Clinic.Doctorz.ProductService.HttpApi.Client\G1.Clinic.Doctorz.ProductService.HttpApi.Client.csproj'. If you are using Visual Studio, this may be because the project is unloaded or not part of the current solution so run a restore from the command-line. Otherwise, the project file may be invalid or missing targets required for restore. G1.Clinic.Doctorz.PublicWeb D:\G1_abp\G1.Clinic.Doctorz\apps\public-web\src\G1.Clinic.Doctorz.PublicWeb\G1.Clinic.Doctorz.PublicWeb.csproj 1

    Similar behaviour is not happening for any other reference project like EntityFrameworkCore.

  • User Avatar
    0
    jfistelmann created

    Hello,

    please execute dotnet build /graphBuild like described here

    Does that solve your issue?

    kind regards Jack

  • User Avatar
    0
    smansuri created

    Hello,

    please execute dotnet build /graphBuild like described here

    Does that solve your issue?

    kind regards Jack

    Hi Support,

    Could you please provide detailed steps to migrate to mysql database for microservices template. we are using the url: https://docs.abp.io/en/abp/latest/Entity-Framework-Core-MySQL to migrate and swithch the sql database to mysql.

    When we ran the migrator project we are getting below errors:

    Failed executing DbCommand (33ms) [Parameters=[@__providerName_0='?' (Size = 64)], CommandType='Text', CommandTimeout='30'] SELECT "a.Id, a.Name, a.ProviderKey, a.ProviderName, a.Value FROM AbpSettings AS a WHERE (a.ProviderName = @__providerName_0) AND a.ProviderKey IS NULL" [13:34:30 ERR] An exception occurred while iterating over the results of a query for context type 'G1.Microservice.AdministrationService.EntityFrameworkCore.AdministrationServiceDbContext'.

    When we run the migration on individual service host we get following error; Starting G1.Microservice.AdministrationService.HttpApi.Host. [17:15:15 FTL] G1.Microservice.AdministrationService.HttpApi.Host terminated unexpectedly! Microsoft.Extensions.Hosting.HostAbortedException: The host was aborted. at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.ThrowHostAborted() at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.OnNext(KeyValuePair`2 value) at System.Diagnostics.DiagnosticListener.Write(String name, Object value) at Microsoft.Extensions.Hosting.HostBuilder.ResolveHost(IServiceProvider serviceProvider, DiagnosticListener diagnosticListener) at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build() at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build() at G1.Microservice.AdministrationService.Program.Main(String[] args) in F:\AbpSuiteMicroservices\G1.Microservice\services\administration\src\G1.Microservice.AdministrationService.HttpApi.Host\Program.cs:line 28 To undo this action, use Remove-Migration.

  • User Avatar
    0
    jfistelmann created

    Hey,

    So here are my steps according to the documentation: I had to make some adjustments. If you exactly to the steps I describe here, you should be fine to go (as they worked out for me).

    Step 1 - Replace packages

    all good

    Step 2 - Replace module dependency

    ✅ all good

    Step 3 - UseMySql()

    ⚠️ Changed things

    This is okay:

    YourProjectNameEntityFrameworkCoreModule.cs inside the .EntityFrameworkCore project. Replace UseSqlServer() with UseMySQL().
    

    This is something I made a bit different:

    YourProjectNameDbContextFactory.cs inside the .EntityFrameworkCore project. Replace UseSqlServer() with UseMySql(). Then add a new parameter (ServerVersion) to UseMySql() method. Example: .UseMySql(configuration.GetConnectionString("Default"), ServerVersion.Parse("8.0.21-mysql")). See this issue for more information about ServerVersion)
    

    My change looks like this:

    public AdministrationServiceDbContext CreateDbContext(string[] args)
        {
            AdministrationServiceEfCoreEntityExtensionMappings.Configure();
    
            var connectionString = GetConnectionStringFromConfiguration();
    
            var builder = new DbContextOptionsBuilder<AdministrationServiceDbContext>()
                .UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), b =>
                {
                    b.MigrationsHistoryTable("__AdministrationService_Migrations");
                });
    
            return new AdministrationServiceDbContext(builder.Options);
        }
    

    *In addition to that, some of the ServiceDbContext.cs file needed more adjustment.

    before:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.ConfigureWarnings(w => w.Ignore(SqlServerEventId.SavepointsDisabledBecauseOfMARS));
            base.OnConfiguring(optionsBuilder);
        }
    

    after:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }
    

    Step 4 - Change Connection string

    pretty straight forward.

    My new connection string look like this:

    "ConnectionStrings": {
        "ProductService": "server=127.0.0.1;port=3306;user=mysuperduperuser;pwd=mysuperduperpasswort;database=Doctorz_ProductService",
        "IdentityService": "server=127.0.0.1;port=3306;user=mysuperduperuser;pwd=mysuperduperpasswort;database=Doctorz_Identity",
        "AdministrationService": "server=127.0.0.1;port=3306;user=mysuperduperuser;pwd=mysuperduperpasswort;database=Doctorz_Administration",
        "SaasService": "server=127.0.0.1;port=3306;user=mysuperduperuser;pwd=mysuperduperpasswort;database=Doctorz_Saas"
      },
    

    Step 5 - Create new migrations

    Did exactly what the docs told me

    ⚠️ Adjustments needed to be made

    First: Deleted everything inside the migrations folders Second: executed dotnet build /graphBuild on solution level Third: Wanted to add initial migrations

    PM> Add-Migration "Initial"
    Build started...
    Build succeeded.
    The Entity Framework tools version '7.0.1' is older than that of the runtime '7.0.2'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.
    [14:44:46 INF] Starting G1.Clinic.Doctorz.AdministrationService.HttpApi.Host.
    [14:44:46 FTL] G1.Clinic.Doctorz.AdministrationService.HttpApi.Host terminated unexpectedly!
    Microsoft.Extensions.Hosting.HostAbortedException: The host was aborted.
       at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.ThrowHostAborted()
       at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.OnNext(KeyValuePair`2 value)
       at System.Diagnostics.DiagnosticListener.Write(String name, Object value)
       at Microsoft.Extensions.Hosting.HostBuilder.ResolveHost(IServiceProvider serviceProvider, DiagnosticListener diagnosticListener)
       at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
       at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
       at G1.Clinic.Doctorz.AdministrationService.Program.Main(String[] args) in C:\G1.Clinic.Doctorz\services\administration\src\G1.Clinic.Doctorz.AdministrationService.HttpApi.Host\Program.cs:line 28
    To undo this action, use Remove-Migration.
    

    Used this answer https://stackoverflow.com/a/76170042

    my program.cs now looks like this:

    public async static Task&lt;int&gt; Main(string[] args)
        {
            var assemblyName = typeof(Program).Assembly.GetName().Name;
    
            SerilogConfigurationHelper.Configure(assemblyName!);
    
            try
            {
                Log.Information($"Starting {assemblyName}.");
                var builder = WebApplication.CreateBuilder(args);
                builder.Host
                    .AddAppSettingsSecretsJson()
                    .UseAutofac()
                    .UseSerilog();
                await builder.AddApplicationAsync&lt;AdministrationServiceHttpApiHostModule&gt;();
                var app = builder.Build();
                await app.InitializeApplicationAsync();
                await app.RunAsync();
                return 0;
            }
            catch (Exception ex) when (ex is not HostAbortedException)
            {
                Log.Fatal(ex, $"{assemblyName} terminated unexpectedly! \nEX: {ex}\nStackTrace: {ex.StackTrace}\nINNER{ex.InnerException}");
                return 1;
            }
            finally
            {
                Log.CloseAndFlush();
            }
    

    After that, I was able to create the migrations.

    I executed dotnet build /graphBuild again just to ensure I did everything correctly (solution still buildable) and it went through.

    Fourth: Run the DbMigrator

    [16:01:56 INF] Loaded ABP modules:
    ...
    [16:01:56 DBG] Started background worker: Volo.Abp.OpenIddict.Tokens.TokenCleanupBackgroundWorker
    [16:01:56 INF] Initialized all ABP modules.
    [16:01:56 INF] Migrating Host side...
    [16:01:56 INF] Migrating SaasService database...
    [16:01:57 INF] Migrating AdministrationService database...
    [16:01:59 INF] Migrating IdentityService database...
    [16:02:00 INF] Migrating ProductService database...
    [16:02:01 INF] All databases have been successfully migrated (HOST).
    [16:02:04 INF] Migrating tenants...
    [16:02:04 INF] Migration completed!
    [16:02:04 DBG] Stopped background worker: Volo.Abp.OpenIddict.Tokens.TokenCleanupBackgroundWorker
    
    C:\G1.Clinic.Doctorz\shared\G1.Clinic.Doctorz.DbMigrator\bin\Debug\net7.0\G1.Clinic.Doctorz.DbMigrator.exe (process 43416) exited with code 0.
    To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
    Press any key to close this window . . .
    

    Step 4 - Run the application

    ⚠️

    adjust run-tye.yaml. You do not need sql-server-db. you may replace it with mysql server also adjust ms sql stuff from build/etc/docker to match your requirements

    Now, execute run-tye.ps1 from the solution directory.

  • User Avatar
    0
    smansuri created

    thanks that worked

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06