diff --git a/.gitignore b/.gitignore index cf8aa04..88e91a0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ backend/bin/ backend/obj/ backend.tests/bin/ backend.tests/obj/ + +# SQLite dev database (created on first run) +backend/*.db +backend/*.db-shm +backend/*.db-wal diff --git a/backend/Data/AppDbContext.cs b/backend/Data/AppDbContext.cs new file mode 100644 index 0000000..28bf989 --- /dev/null +++ b/backend/Data/AppDbContext.cs @@ -0,0 +1,7 @@ +using Microsoft.EntityFrameworkCore; + +namespace backend.Data; + +public class AppDbContext(DbContextOptions options) : DbContext(options) +{ +} diff --git a/backend/Migrations/20260611181007_Initial.Designer.cs b/backend/Migrations/20260611181007_Initial.Designer.cs new file mode 100644 index 0000000..32c0531 --- /dev/null +++ b/backend/Migrations/20260611181007_Initial.Designer.cs @@ -0,0 +1,24 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using backend.Data; + +#nullable disable + +namespace backend.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260611181007_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.17"); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/Migrations/20260611181007_Initial.cs b/backend/Migrations/20260611181007_Initial.cs new file mode 100644 index 0000000..2552aec --- /dev/null +++ b/backend/Migrations/20260611181007_Initial.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace backend.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/backend/Migrations/AppDbContextModelSnapshot.cs b/backend/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..a8c6804 --- /dev/null +++ b/backend/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,21 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using backend.Data; + +#nullable disable + +namespace backend.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.17"); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/Program.cs b/backend/Program.cs index 5f8299f..0aa4404 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -1,8 +1,21 @@ -var builder = WebApplication.CreateBuilder(args); -var app = builder.Build(); - -app.MapGet("/", () => "Hello World!"); - -app.Run(); - -public partial class Program { } +using backend.Data; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddDbContext(opt => + opt.UseSqlite(builder.Configuration.GetConnectionString("Default"))); + +var app = builder.Build(); + +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.Migrate(); +} + +app.MapGet("/health", () => Results.Ok(new { ok = true })); + +app.Run(); + +public partial class Program { } diff --git a/backend/appsettings.json b/backend/appsettings.json index 4d56694..6496deb 100644 --- a/backend/appsettings.json +++ b/backend/appsettings.json @@ -1,9 +1,12 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} +{ + "ConnectionStrings": { + "Default": "Data Source=./assistant.db" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/backend/backend.csproj b/backend/backend.csproj index 08f689c..c6ceda2 100644 --- a/backend/backend.csproj +++ b/backend/backend.csproj @@ -6,4 +6,12 @@ enable + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + +