From 8820cc7751f32fe399d3fb26a361a6cda8ea788c Mon Sep 17 00:00:00 2001 From: Gulum Date: Fri, 5 Jun 2026 23:34:00 +0200 Subject: [PATCH] ARCH-2: swap EF provider to Npgsql, drop SqlServer migrations + conn strings - Microsoft.EntityFrameworkCore.SqlServer -> Npgsql.EntityFrameworkCore.PostgreSQL 10.0.2 - UseSqlServer -> UseNpgsql (Aspire-injected gerbilmanager connection) - Removed hardcoded sa connection strings from appsettings*.json - Deleted SqlServer-flavored initial migration (fresh Npgsql one follows; no prod data) Co-Authored-By: Claude Opus 4.8 (1M context) --- .../GerbilManagerWebAPI.csproj | 2 +- .../20231030203950_initialCreate.Designer.cs | 134 ------------------ .../20231030203950_initialCreate.cs | 121 ---------------- .../ApplicationContextModelSnapshot.cs | 131 ----------------- GerbilManagerWebAPI/Program.cs | 2 +- .../appsettings.Development.json | 3 - GerbilManagerWebAPI/appsettings.json | 3 - 7 files changed, 2 insertions(+), 394 deletions(-) delete mode 100644 GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs delete mode 100644 GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs delete mode 100644 GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs diff --git a/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj b/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj index 2eccf0b..e37ad6c 100644 --- a/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj +++ b/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj @@ -13,7 +13,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs b/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs deleted file mode 100644 index 930b8f3..0000000 --- a/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.Designer.cs +++ /dev/null @@ -1,134 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace GerbilManagerWebAPI.Migrations -{ - [DbContext(typeof(ApplicationContext))] - [Migration("20231030203950_initialCreate")] - partial class initialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Breeder", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Breeders", (string)null); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("BreederId") - .HasColumnType("uniqueidentifier"); - - b.Property("Gender") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("LitterId") - .HasColumnType("uniqueidentifier"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("BreederId"); - - b.HasIndex("LitterId"); - - b.ToTable("Gerbils", (string)null); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.Property("FatherId") - .HasColumnType("uniqueidentifier"); - - b.Property("MotherId") - .HasColumnType("uniqueidentifier"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Strength") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("FatherId"); - - b.HasIndex("MotherId"); - - b.ToTable("Litters", (string)null); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => - { - b.HasOne("GerbilManagerWebAPI.Models.Breeder", "Breeder") - .WithMany() - .HasForeignKey("BreederId"); - - b.HasOne("GerbilManagerWebAPI.Models.Litter", "Litter") - .WithMany() - .HasForeignKey("LitterId"); - - b.Navigation("Breeder"); - - b.Navigation("Litter"); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => - { - b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Father") - .WithMany() - .HasForeignKey("FatherId"); - - b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Mother") - .WithMany() - .HasForeignKey("MotherId"); - - b.Navigation("Father"); - - b.Navigation("Mother"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs b/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs deleted file mode 100644 index ae300ed..0000000 --- a/GerbilManagerWebAPI/Migrations/20231030203950_initialCreate.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace GerbilManagerWebAPI.Migrations -{ - /// - public partial class initialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Breeders", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Breeders", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Gerbils", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Gender = table.Column(type: "nvarchar(max)", nullable: false), - LitterId = table.Column(type: "uniqueidentifier", nullable: true), - BreederId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Gerbils", x => x.Id); - table.ForeignKey( - name: "FK_Gerbils_Breeders_BreederId", - column: x => x.BreederId, - principalTable: "Breeders", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "Litters", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Date = table.Column(type: "datetime2", nullable: false), - Strength = table.Column(type: "int", nullable: true), - FatherId = table.Column(type: "uniqueidentifier", nullable: true), - MotherId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Litters", x => x.Id); - table.ForeignKey( - name: "FK_Litters_Gerbils_FatherId", - column: x => x.FatherId, - principalTable: "Gerbils", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Litters_Gerbils_MotherId", - column: x => x.MotherId, - principalTable: "Gerbils", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Gerbils_BreederId", - table: "Gerbils", - column: "BreederId"); - - migrationBuilder.CreateIndex( - name: "IX_Gerbils_LitterId", - table: "Gerbils", - column: "LitterId"); - - migrationBuilder.CreateIndex( - name: "IX_Litters_FatherId", - table: "Litters", - column: "FatherId"); - - migrationBuilder.CreateIndex( - name: "IX_Litters_MotherId", - table: "Litters", - column: "MotherId"); - - migrationBuilder.AddForeignKey( - name: "FK_Gerbils_Litters_LitterId", - table: "Gerbils", - column: "LitterId", - principalTable: "Litters", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Gerbils_Breeders_BreederId", - table: "Gerbils"); - - migrationBuilder.DropForeignKey( - name: "FK_Gerbils_Litters_LitterId", - table: "Gerbils"); - - migrationBuilder.DropTable( - name: "Breeders"); - - migrationBuilder.DropTable( - name: "Litters"); - - migrationBuilder.DropTable( - name: "Gerbils"); - } - } -} diff --git a/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs b/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs deleted file mode 100644 index 8e1d3bc..0000000 --- a/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs +++ /dev/null @@ -1,131 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace GerbilManagerWebAPI.Migrations -{ - [DbContext(typeof(ApplicationContext))] - partial class ApplicationContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Breeder", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Breeders", (string)null); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("BreederId") - .HasColumnType("uniqueidentifier"); - - b.Property("Gender") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("LitterId") - .HasColumnType("uniqueidentifier"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("BreederId"); - - b.HasIndex("LitterId"); - - b.ToTable("Gerbils", (string)null); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.Property("FatherId") - .HasColumnType("uniqueidentifier"); - - b.Property("MotherId") - .HasColumnType("uniqueidentifier"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Strength") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("FatherId"); - - b.HasIndex("MotherId"); - - b.ToTable("Litters", (string)null); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => - { - b.HasOne("GerbilManagerWebAPI.Models.Breeder", "Breeder") - .WithMany() - .HasForeignKey("BreederId"); - - b.HasOne("GerbilManagerWebAPI.Models.Litter", "Litter") - .WithMany() - .HasForeignKey("LitterId"); - - b.Navigation("Breeder"); - - b.Navigation("Litter"); - }); - - modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => - { - b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Father") - .WithMany() - .HasForeignKey("FatherId"); - - b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Mother") - .WithMany() - .HasForeignKey("MotherId"); - - b.Navigation("Father"); - - b.Navigation("Mother"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/GerbilManagerWebAPI/Program.cs b/GerbilManagerWebAPI/Program.cs index dabc360..fa5ac49 100644 --- a/GerbilManagerWebAPI/Program.cs +++ b/GerbilManagerWebAPI/Program.cs @@ -9,7 +9,7 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddDbContext(opts => opts.UseSqlServer(builder.Configuration.GetConnectionString("sqlConnection"))); +builder.Services.AddDbContext(opts => opts.UseNpgsql(builder.Configuration.GetConnectionString("gerbilmanager"))); builder.Services.AddScoped(); var app = builder.Build(); diff --git a/GerbilManagerWebAPI/appsettings.Development.json b/GerbilManagerWebAPI/appsettings.Development.json index 70e4a2b..0c208ae 100644 --- a/GerbilManagerWebAPI/appsettings.Development.json +++ b/GerbilManagerWebAPI/appsettings.Development.json @@ -4,8 +4,5 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - }, - "ConnectionStrings": { - "sqlConnection": "server=.; database=GerbilManagerDebug; User Id=sa;Password=StrongerThenYYou1;Encrypt=False;TrustServerCertificate=True" } } diff --git a/GerbilManagerWebAPI/appsettings.json b/GerbilManagerWebAPI/appsettings.json index 2699190..10f68b8 100644 --- a/GerbilManagerWebAPI/appsettings.json +++ b/GerbilManagerWebAPI/appsettings.json @@ -5,8 +5,5 @@ "Microsoft.AspNetCore": "Warning" } }, - "ConnectionStrings": { - "sqlConnection": "server=.; database=GerbilManagerDebug; User Id=sa;Password=StrongerThenYYou1;Encrypt=False;TrustServerCertificate=True" - }, "AllowedHosts": "*" }