Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
xBaank committed Aug 14, 2024
1 parent ef003d6 commit ae4f403
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 2 additions & 2 deletions Console/Commands/MainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,7 +192,8 @@ public async ValueTask ExecuteAsync(IConsole console)

using var dbContext = serviceProvider.GetRequiredService<MyDbContext>();
using var settingsRepository = serviceProvider.GetRequiredService<SettingsRepository>();
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<PlayerController>();
Expand Down
25 changes: 16 additions & 9 deletions Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<TrimMode>full</TrimMode>
<PublishTrimmed>true</PublishTrimmed>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -25,15 +25,11 @@
<PackageReference Include="Terminal.Gui" Version="2.0.0-prealpha.216" />
<PackageReference Include="YoutubeExplodeMusic" Version="6.4.0-music.1" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Tests" />
</ItemGroup>

<ItemGroup>
<TrimmerRootAssembly Include="CliFx" />
<TrimmerRootAssembly Include="Microsoft.EntityFrameworkCore.Sqlite" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Tests" />
</ItemGroup>

<PropertyGroup>
<PortAudioPlatform>$(RuntimeIdentifier)</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">win-arm64</PortAudioPlatform>
Expand All @@ -48,6 +44,17 @@
<PortAudioFileName Condition="$(PortAudioPlatform.StartsWith('linux-'))">libportaudio.so</PortAudioFileName>
<PortAudioFileName Condition="'$(PortAudioFileName)' == ''">libportaudio.dylib</PortAudioFileName>
</PropertyGroup>

<Target Name="GenerateMigrationsAfterBuild" AfterTargets="Build">
<Exec Command="dotnet ef migrations script -o migrations.sql --no-build" LogStandardErrorAsError="true" />
<Copy SourceFiles="$(ProjectDir)/migrations.sql" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
</Target>

<!-- Generate migrations after publish -->
<Target Name="GenerateMigrationsAfterPublish" AfterTargets="Publish">
<Exec Command="dotnet ef migrations script -o migrations.sql --no-build" LogStandardErrorAsError="true" />
<Copy SourceFiles="$(ProjectDir)/migrations.sql" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
</Target>

<Target Name="Download PortAudio before build" BeforeTargets="PreBuildEvent">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadPortAudioBin.ps1&quot; -Platform $(PortAudioPlatform) -OutputPath &quot;$(ProjectDir)/$(PortAudioFileName)&quot;" LogStandardErrorAsError="true" />
Expand Down
15 changes: 15 additions & 0 deletions Console/Extensions/MyDbContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 16 additions & 1 deletion Console/Program.cs
Original file line number Diff line number Diff line change
@@ -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<int> Main() =>
await new CliApplicationBuilder().AddCommand<MainCommand>().Build().RunAsync();
}

0 comments on commit ae4f403

Please sign in to comment.