From 2012f123791a77d228ab57bb84727108ba06d458 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Wed, 12 Feb 2025 20:38:59 -0600 Subject: [PATCH] Fix MySQL migrations Fixes #168 --- LANCommander.SDK/LANCommander.SDK.csproj | 4 ++-- .../LANCommander.Server.Data.MySQL.csproj | 6 +----- ...> 20250213023250_InitialMigration.Designer.cs} | 15 ++++++--------- ...tion.cs => 20250213023250_InitialMigration.cs} | 2 +- .../Migrations/DatabaseContextModelSnapshot.cs | 13 +++++-------- LANCommander.Server.Data/DatabaseContext.cs | 2 +- .../LANCommander.Server.Data.csproj | 2 +- .../LANCommander.Server.Services.csproj | 2 +- LANCommander.Server/LANCommander.Server.csproj | 2 +- 9 files changed, 19 insertions(+), 29 deletions(-) rename LANCommander.Server.Data.MySQL/Migrations/{20250203083220_InitialMigration.Designer.cs => 20250213023250_InitialMigration.Designer.cs} (99%) rename LANCommander.Server.Data.MySQL/Migrations/{20250203083220_InitialMigration.cs => 20250213023250_InitialMigration.cs} (99%) diff --git a/LANCommander.SDK/LANCommander.SDK.csproj b/LANCommander.SDK/LANCommander.SDK.csproj index f0427d2d..ad2460cb 100644 --- a/LANCommander.SDK/LANCommander.SDK.csproj +++ b/LANCommander.SDK/LANCommander.SDK.csproj @@ -20,8 +20,8 @@ - - + + diff --git a/LANCommander.Server.Data.MySQL/LANCommander.Server.Data.MySQL.csproj b/LANCommander.Server.Data.MySQL/LANCommander.Server.Data.MySQL.csproj index 6161604a..2a339e16 100644 --- a/LANCommander.Server.Data.MySQL/LANCommander.Server.Data.MySQL.csproj +++ b/LANCommander.Server.Data.MySQL/LANCommander.Server.Data.MySQL.csproj @@ -9,15 +9,11 @@ - + - - - - diff --git a/LANCommander.Server.Data.MySQL/Migrations/20250203083220_InitialMigration.Designer.cs b/LANCommander.Server.Data.MySQL/Migrations/20250213023250_InitialMigration.Designer.cs similarity index 99% rename from LANCommander.Server.Data.MySQL/Migrations/20250203083220_InitialMigration.Designer.cs rename to LANCommander.Server.Data.MySQL/Migrations/20250213023250_InitialMigration.Designer.cs index e4cbff22..0175701c 100644 --- a/LANCommander.Server.Data.MySQL/Migrations/20250203083220_InitialMigration.Designer.cs +++ b/LANCommander.Server.Data.MySQL/Migrations/20250213023250_InitialMigration.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace LANCommander.Server.Data.MySQL.Migrations { [DbContext(typeof(DatabaseContext))] - [Migration("20250203083220_InitialMigration")] + [Migration("20250213023250_InitialMigration")] partial class InitialMigration { /// @@ -20,7 +20,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("ProductVersion", "9.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 64); MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); @@ -806,8 +806,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.Property("Description") .HasColumnType("longtext"); - b.Property("GameId") - .IsRequired() + b.Property("GameId") .HasColumnType("char(36)"); b.Property("MaxPlayers") @@ -1263,8 +1262,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.Property("Port") .HasColumnType("int"); - b.Property("ServerId") - .IsRequired() + b.Property("ServerId") .HasColumnType("char(36)"); b.Property("ServerId1") @@ -1524,8 +1522,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.Property("UpdatedOn") .HasColumnType("datetime(6)"); - b.Property("UserId") - .IsRequired() + b.Property("UserId") .HasColumnType("char(36)"); b.Property("Value") @@ -2201,7 +2198,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.HasOne("LANCommander.Server.Data.Models.StorageLocation", "StorageLocation") .WithMany("Media") .HasForeignKey("StorageLocationId") - .OnDelete(DeleteBehavior.SetNull) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("LANCommander.Server.Data.Models.Media", "Thumbnail") diff --git a/LANCommander.Server.Data.MySQL/Migrations/20250203083220_InitialMigration.cs b/LANCommander.Server.Data.MySQL/Migrations/20250213023250_InitialMigration.cs similarity index 99% rename from LANCommander.Server.Data.MySQL/Migrations/20250203083220_InitialMigration.cs rename to LANCommander.Server.Data.MySQL/Migrations/20250213023250_InitialMigration.cs index e70d261a..c17a39f9 100644 --- a/LANCommander.Server.Data.MySQL/Migrations/20250203083220_InitialMigration.cs +++ b/LANCommander.Server.Data.MySQL/Migrations/20250213023250_InitialMigration.cs @@ -1245,7 +1245,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations column: x => x.StorageLocationId, principalTable: "StorageLocations", principalColumn: "Id", - onDelete: ReferentialAction.SetNull); + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Media_Users_CreatedById", column: x => x.CreatedById, diff --git a/LANCommander.Server.Data.MySQL/Migrations/DatabaseContextModelSnapshot.cs b/LANCommander.Server.Data.MySQL/Migrations/DatabaseContextModelSnapshot.cs index cfe70325..e29529ec 100644 --- a/LANCommander.Server.Data.MySQL/Migrations/DatabaseContextModelSnapshot.cs +++ b/LANCommander.Server.Data.MySQL/Migrations/DatabaseContextModelSnapshot.cs @@ -17,7 +17,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("ProductVersion", "9.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 64); MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); @@ -803,8 +803,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.Property("Description") .HasColumnType("longtext"); - b.Property("GameId") - .IsRequired() + b.Property("GameId") .HasColumnType("char(36)"); b.Property("MaxPlayers") @@ -1260,8 +1259,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.Property("Port") .HasColumnType("int"); - b.Property("ServerId") - .IsRequired() + b.Property("ServerId") .HasColumnType("char(36)"); b.Property("ServerId1") @@ -1521,8 +1519,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.Property("UpdatedOn") .HasColumnType("datetime(6)"); - b.Property("UserId") - .IsRequired() + b.Property("UserId") .HasColumnType("char(36)"); b.Property("Value") @@ -2198,7 +2195,7 @@ namespace LANCommander.Server.Data.MySQL.Migrations b.HasOne("LANCommander.Server.Data.Models.StorageLocation", "StorageLocation") .WithMany("Media") .HasForeignKey("StorageLocationId") - .OnDelete(DeleteBehavior.SetNull) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("LANCommander.Server.Data.Models.Media", "Thumbnail") diff --git a/LANCommander.Server.Data/DatabaseContext.cs b/LANCommander.Server.Data/DatabaseContext.cs index eba213f3..1cd7a716 100644 --- a/LANCommander.Server.Data/DatabaseContext.cs +++ b/LANCommander.Server.Data/DatabaseContext.cs @@ -220,7 +220,7 @@ namespace LANCommander.Server.Data .HasOne(m => m.StorageLocation) .WithMany(l => l.Media) .IsRequired(true) - .OnDelete(DeleteBehavior.SetNull); + .OnDelete(DeleteBehavior.Cascade); builder.Entity() .Navigation(m => m.StorageLocation) diff --git a/LANCommander.Server.Data/LANCommander.Server.Data.csproj b/LANCommander.Server.Data/LANCommander.Server.Data.csproj index 6cb01d3f..b21ca287 100644 --- a/LANCommander.Server.Data/LANCommander.Server.Data.csproj +++ b/LANCommander.Server.Data/LANCommander.Server.Data.csproj @@ -13,7 +13,7 @@ - + diff --git a/LANCommander.Server.Services/LANCommander.Server.Services.csproj b/LANCommander.Server.Services/LANCommander.Server.Services.csproj index ef476fd0..e35a2e9f 100644 --- a/LANCommander.Server.Services/LANCommander.Server.Services.csproj +++ b/LANCommander.Server.Services/LANCommander.Server.Services.csproj @@ -17,7 +17,7 @@ - + diff --git a/LANCommander.Server/LANCommander.Server.csproj b/LANCommander.Server/LANCommander.Server.csproj index 1d6bafa6..7647d843 100644 --- a/LANCommander.Server/LANCommander.Server.csproj +++ b/LANCommander.Server/LANCommander.Server.csproj @@ -94,7 +94,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive