diff --git a/.gitignore b/.gitignore index d8064f8..8e44c14 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,10 @@ bld/ *.so *.dll *.dylib +*.a + +## migrations, they are autogenerated on build and publsish +*.sql # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/Console/Commands/MainCommand.cs b/Console/Commands/MainCommand.cs index 1c3ff9d..2a1012a 100644 --- a/Console/Commands/MainCommand.cs +++ b/Console/Commands/MainCommand.cs @@ -7,7 +7,6 @@ using Console.Extensions; using Console.Repositories; using Console.Views; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Terminal.Gui; using YoutubeExplode; @@ -193,7 +192,8 @@ public async ValueTask ExecuteAsync(IConsole console) using var dbContext = serviceProvider.GetRequiredService(); using var settingsRepository = serviceProvider.GetRequiredService(); - await dbContext.Database.MigrateAsync(); + //TODO change to dapper and use fluent migrations cause this will never work + await dbContext.MigrateAOTAsync("migrations.sql"); await settingsRepository.InitializeAsync(); await using var playerController = serviceProvider.GetRequiredService(); diff --git a/Console/Console.csproj b/Console/Console.csproj index 19fca67..a5241ae 100644 --- a/Console/Console.csproj +++ b/Console/Console.csproj @@ -2,7 +2,7 @@ Exe true - full + true net8.0 enable enable @@ -25,15 +25,11 @@ - - - - - - - - + + + + $(RuntimeIdentifier) win-arm64 @@ -48,6 +44,17 @@ libportaudio.so libportaudio.dylib + + + + + + + + + + + diff --git a/Console/Extensions/MyDbContextExtensions.cs b/Console/Extensions/MyDbContextExtensions.cs new file mode 100644 index 0000000..c8d46ef --- /dev/null +++ b/Console/Extensions/MyDbContextExtensions.cs @@ -0,0 +1,15 @@ +using Console.Database; +using Microsoft.EntityFrameworkCore; + +namespace Console.Extensions; + +internal static class MyDbContextExtensions +{ + public static async ValueTask MigrateAOTAsync(this MyDbContext context, string filename) + { + using Stream stream = File.OpenRead(filename); + using StreamReader reader = new(stream); + var sql = reader.ReadToEnd(); + await context.Database.ExecuteSqlRawAsync(sql); + } +} diff --git a/Console/Program.cs b/Console/Program.cs index 0f71743..71a249d 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -1,10 +1,25 @@ -using CliFx; +using System.Diagnostics.CodeAnalysis; +using CliFx; using Console.Commands; +using Console.Database; +using Console.Migrations; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; namespace Console; public static class Program { + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MainCommand))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MyDbContext))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(InitialCreate))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(RemoveDescription))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Order))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Settings))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Volume_as_int))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MyDbContextModelSnapshot))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Migration))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ModelSnapshot))] public static async Task Main() => await new CliApplicationBuilder().AddCommand().Build().RunAsync(); }