Files
GreadyPoang/GreadyPoang.Migrations/Program.cs
2025-09-03 23:38:57 +02:00

33 lines
1.4 KiB
C#

using GreadyPoang.DataLayer.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting; // Replace with your actual namespace
class Program
{
static void Main(string[] args)
{
using var host = CreateHostBuilder(args).Build();
// Resolve your DbContext
var context = host.Services.GetRequiredService<DataContext>();
context.Database.EnsureCreated();
// Optional: Apply migrations at runtime
context.Database.Migrate();
Console.WriteLine("Migration applied successfully.");
}
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((_, services) =>
{
var MauiDataPath = string.Empty;
MauiDataPath = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"));
var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
services.AddDbContext<DataContext>(options =>
options.UseSqlite($"Data Source={dbPath}"));
});
}
// dotnet ef migrations add FixHeatToRoundParams --project GreadyPoang.DataLayer --startup-project GreadyPoang.Migrations
// dotnet ef database update --project GreadyPoang.DataLayer --startup-project GreadyPoang.Migrations