diff --git a/Lutra/Lutra.API/Lutra.API.csproj b/Lutra/Lutra.API/Lutra.API.csproj
index 6959682..5629c87 100644
--- a/Lutra/Lutra.API/Lutra.API.csproj
+++ b/Lutra/Lutra.API/Lutra.API.csproj
@@ -11,7 +11,12 @@
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
diff --git a/Lutra/Lutra.API/Program.cs b/Lutra/Lutra.API/Program.cs
index 7605a85..cdeccbf 100644
--- a/Lutra/Lutra.API/Program.cs
+++ b/Lutra/Lutra.API/Program.cs
@@ -1,6 +1,9 @@
using Cortex.Mediator.DependencyInjection;
using Lutra.Application.Verspakketten;
+using Lutra.Application.Interfaces;
+using Lutra.Infrastructure.Sql;
+using Microsoft.EntityFrameworkCore;
namespace Lutra.API
{
@@ -15,6 +18,9 @@ namespace Lutra.API
options => options.AddDefaultBehaviors()
);
+ builder.Services.AddDbContext(options =>
+ options.UseNpgsql(builder.Configuration.GetConnectionString("LutraDb")));
+
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
diff --git a/Lutra/Lutra.API/appsettings.json b/Lutra/Lutra.API/appsettings.json
index 10f68b8..18a8f11 100644
--- a/Lutra/Lutra.API/appsettings.json
+++ b/Lutra/Lutra.API/appsettings.json
@@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
+ "ConnectionStrings": {
+ "LutraDb": "Host=db.m91.nl;Username=user;Password=password;Database=Lutra"
+ },
"AllowedHosts": "*"
}
diff --git a/Lutra/Lutra.AppHost/AppHost.cs b/Lutra/Lutra.AppHost/AppHost.cs
index 6b85fe1..501c50d 100644
--- a/Lutra/Lutra.AppHost/AppHost.cs
+++ b/Lutra/Lutra.AppHost/AppHost.cs
@@ -1,13 +1,13 @@
var builder = DistributedApplication.CreateBuilder(args);
-var sql = builder.AddSqlServer("sql")
- .WithLifetime(ContainerLifetime.Persistent);
+var db = builder.AddConnectionString("LutraDb");
-var db = sql.AddDatabase("database", "Lutra");
+var migrator = builder.AddProject("dbmigrator")
+ .WithReference(db);
var apiService = builder.AddProject("apiservice")
.WithHttpHealthCheck("/health")
.WithReference(db)
- .WaitFor(db);
+ .WaitForCompletion(migrator);
builder.Build().Run();
diff --git a/Lutra/Lutra.AppHost/Lutra.AppHost.csproj b/Lutra/Lutra.AppHost/Lutra.AppHost.csproj
index 7d13d71..bfb8064 100644
--- a/Lutra/Lutra.AppHost/Lutra.AppHost.csproj
+++ b/Lutra/Lutra.AppHost/Lutra.AppHost.csproj
@@ -12,11 +12,11 @@
-
+
diff --git a/Lutra/Lutra.AppHost/appsettings.json b/Lutra/Lutra.AppHost/appsettings.json
index 31c092a..cf598e4 100644
--- a/Lutra/Lutra.AppHost/appsettings.json
+++ b/Lutra/Lutra.AppHost/appsettings.json
@@ -1,4 +1,7 @@
{
+ "ConnectionStrings": {
+ "LutraDb": "Host=db.m91.nl;Username=user;Password=password;Database=Lutra"
+ },
"Logging": {
"LogLevel": {
"Default": "Information",
diff --git a/Lutra/Lutra.Infrastructure.Migrator/Lutra.Infrastructure.Migrator.csproj b/Lutra/Lutra.Infrastructure.Migrator/Lutra.Infrastructure.Migrator.csproj
new file mode 100644
index 0000000..c6b3a7f
--- /dev/null
+++ b/Lutra/Lutra.Infrastructure.Migrator/Lutra.Infrastructure.Migrator.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net10.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Lutra/Lutra.Infrastructure.Migrator/Program.cs b/Lutra/Lutra.Infrastructure.Migrator/Program.cs
new file mode 100644
index 0000000..94781d4
--- /dev/null
+++ b/Lutra/Lutra.Infrastructure.Migrator/Program.cs
@@ -0,0 +1,15 @@
+using Lutra.Infrastructure.Sql;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+
+var builder = Host.CreateApplicationBuilder(args);
+
+builder.Services.AddDbContext(options =>
+ options.UseNpgsql(builder.Configuration.GetConnectionString("LutraDb")));
+
+using var host = builder.Build();
+using var scope = host.Services.CreateScope();
+
+var dbContext = scope.ServiceProvider.GetRequiredService();
+await dbContext.Database.MigrateAsync();
diff --git a/Lutra/Lutra.Infrastructure/Lutra.Infrastructure.Sql.csproj b/Lutra/Lutra.Infrastructure/Lutra.Infrastructure.Sql.csproj
index 5c3afe2..17e36ef 100644
--- a/Lutra/Lutra.Infrastructure/Lutra.Infrastructure.Sql.csproj
+++ b/Lutra/Lutra.Infrastructure/Lutra.Infrastructure.Sql.csproj
@@ -8,6 +8,11 @@
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
diff --git a/Lutra/Lutra.Infrastructure/LutraDbContext.cs b/Lutra/Lutra.Infrastructure/LutraDbContext.cs
index e83173e..f03d5ec 100644
--- a/Lutra/Lutra.Infrastructure/LutraDbContext.cs
+++ b/Lutra/Lutra.Infrastructure/LutraDbContext.cs
@@ -4,14 +4,21 @@ using Microsoft.EntityFrameworkCore;
namespace Lutra.Infrastructure.Sql;
-public class LutraDbContext : ILutraDbContext
+public class LutraDbContext : DbContext, ILutraDbContext
{
- public DbSet Supermarkten => throw new NotImplementedException();
-
- public DbSet Verspaketten => throw new NotImplementedException();
-
- public Task SaveChangesAsync(CancellationToken cancellationToken)
+ public LutraDbContext(DbContextOptions options)
+ : base(options)
{
- throw new NotImplementedException();
+ }
+
+ public DbSet Supermarkten => Set();
+
+ public DbSet Verspaketten => Set();
+
+ public DbSet Beoordelingen => Set();
+
+ public override Task SaveChangesAsync(CancellationToken cancellationToken = default)
+ {
+ return base.SaveChangesAsync(cancellationToken);
}
}
diff --git a/Lutra/Lutra.Infrastructure/Migrations/20260326190730_InitialCreate.Designer.cs b/Lutra/Lutra.Infrastructure/Migrations/20260326190730_InitialCreate.Designer.cs
new file mode 100644
index 0000000..a1744c6
--- /dev/null
+++ b/Lutra/Lutra.Infrastructure/Migrations/20260326190730_InitialCreate.Designer.cs
@@ -0,0 +1,149 @@
+//
+using System;
+using Lutra.Infrastructure.Sql;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace Lutra.Infrastructure.Sql.Migrations
+{
+ [DbContext(typeof(LutraDbContext))]
+ [Migration("20260326190730_InitialCreate")]
+ partial class InitialCreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "10.0.5")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Beoordeling", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("Aanbevolen")
+ .HasColumnType("boolean");
+
+ b.Property("CijferBereiden")
+ .HasColumnType("integer");
+
+ b.Property("CijferSmaak")
+ .HasColumnType("integer");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ModifiedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Tekst")
+ .HasMaxLength(1024)
+ .HasColumnType("character varying(1024)");
+
+ b.Property("VerspakketId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VerspakketId");
+
+ b.ToTable("Beoordelingen");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Supermarkt", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ModifiedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Naam")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Supermarkten");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Verspakket", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AantalPersonen")
+ .HasColumnType("integer");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ModifiedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Naam")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property("SupermarktId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("SupermarktId");
+
+ b.ToTable("Verspaketten");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Beoordeling", b =>
+ {
+ b.HasOne("Lutra.Domain.Entities.Verspakket", null)
+ .WithMany("Beoordelingen")
+ .HasForeignKey("VerspakketId");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Verspakket", b =>
+ {
+ b.HasOne("Lutra.Domain.Entities.Supermarkt", "Supermarkt")
+ .WithMany()
+ .HasForeignKey("SupermarktId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Supermarkt");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Verspakket", b =>
+ {
+ b.Navigation("Beoordelingen");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Lutra/Lutra.Infrastructure/Migrations/20260326190730_InitialCreate.cs b/Lutra/Lutra.Infrastructure/Migrations/20260326190730_InitialCreate.cs
new file mode 100644
index 0000000..f30460d
--- /dev/null
+++ b/Lutra/Lutra.Infrastructure/Migrations/20260326190730_InitialCreate.cs
@@ -0,0 +1,100 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace Lutra.Infrastructure.Sql.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Supermarkten",
+ columns: table => new
+ {
+ Id = table.Column(type: "uuid", nullable: false),
+ Naam = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
+ CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
+ ModifiedAt = table.Column(type: "timestamp with time zone", nullable: false),
+ DeletedAt = table.Column(type: "timestamp with time zone", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Supermarkten", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Verspaketten",
+ columns: table => new
+ {
+ Id = table.Column(type: "uuid", nullable: false),
+ Naam = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
+ AantalPersonen = table.Column(type: "integer", nullable: false),
+ SupermarktId = table.Column(type: "uuid", nullable: false),
+ CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
+ ModifiedAt = table.Column(type: "timestamp with time zone", nullable: false),
+ DeletedAt = table.Column(type: "timestamp with time zone", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Verspaketten", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Verspaketten_Supermarkten_SupermarktId",
+ column: x => x.SupermarktId,
+ principalTable: "Supermarkten",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Beoordelingen",
+ columns: table => new
+ {
+ Id = table.Column(type: "uuid", nullable: false),
+ CijferSmaak = table.Column(type: "integer", nullable: false),
+ CijferBereiden = table.Column(type: "integer", nullable: false),
+ Aanbevolen = table.Column(type: "boolean", nullable: false),
+ Tekst = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
+ VerspakketId = table.Column(type: "uuid", nullable: true),
+ CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
+ ModifiedAt = table.Column(type: "timestamp with time zone", nullable: false),
+ DeletedAt = table.Column(type: "timestamp with time zone", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Beoordelingen", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Beoordelingen_Verspaketten_VerspakketId",
+ column: x => x.VerspakketId,
+ principalTable: "Verspaketten",
+ principalColumn: "Id");
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Beoordelingen_VerspakketId",
+ table: "Beoordelingen",
+ column: "VerspakketId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Verspaketten_SupermarktId",
+ table: "Verspaketten",
+ column: "SupermarktId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Beoordelingen");
+
+ migrationBuilder.DropTable(
+ name: "Verspaketten");
+
+ migrationBuilder.DropTable(
+ name: "Supermarkten");
+ }
+ }
+}
diff --git a/Lutra/Lutra.Infrastructure/Migrations/LutraDbContextModelSnapshot.cs b/Lutra/Lutra.Infrastructure/Migrations/LutraDbContextModelSnapshot.cs
new file mode 100644
index 0000000..4d5a9e8
--- /dev/null
+++ b/Lutra/Lutra.Infrastructure/Migrations/LutraDbContextModelSnapshot.cs
@@ -0,0 +1,146 @@
+//
+using System;
+using Lutra.Infrastructure.Sql;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace Lutra.Infrastructure.Sql.Migrations
+{
+ [DbContext(typeof(LutraDbContext))]
+ partial class LutraDbContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "10.0.5")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Beoordeling", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("Aanbevolen")
+ .HasColumnType("boolean");
+
+ b.Property("CijferBereiden")
+ .HasColumnType("integer");
+
+ b.Property("CijferSmaak")
+ .HasColumnType("integer");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ModifiedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Tekst")
+ .HasMaxLength(1024)
+ .HasColumnType("character varying(1024)");
+
+ b.Property("VerspakketId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VerspakketId");
+
+ b.ToTable("Beoordelingen");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Supermarkt", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ModifiedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Naam")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Supermarkten");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Verspakket", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AantalPersonen")
+ .HasColumnType("integer");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ModifiedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Naam")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property("SupermarktId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("SupermarktId");
+
+ b.ToTable("Verspaketten");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Beoordeling", b =>
+ {
+ b.HasOne("Lutra.Domain.Entities.Verspakket", null)
+ .WithMany("Beoordelingen")
+ .HasForeignKey("VerspakketId");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Verspakket", b =>
+ {
+ b.HasOne("Lutra.Domain.Entities.Supermarkt", "Supermarkt")
+ .WithMany()
+ .HasForeignKey("SupermarktId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Supermarkt");
+ });
+
+ modelBuilder.Entity("Lutra.Domain.Entities.Verspakket", b =>
+ {
+ b.Navigation("Beoordelingen");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}