From 91887ec04739ada93d2e2341e11003b3cd02fd49 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Thu, 12 Mar 2026 15:45:51 +0000 Subject: [PATCH] Renamed migration table. Added nullability to template variable migration --- .../Infrastructure/Database/DataContext.cs | 2 +- .../Database/DbMigrationService.cs | 4 +- ...orTemplateVariableDefaultValue.Designer.cs | 313 ++++++++++++++++++ ...labilityForTemplateVariableDefaultValue.cs | 42 +++ .../Migrations/DataContextModelSnapshot.cs | 4 +- 5 files changed, 359 insertions(+), 6 deletions(-) create mode 100644 MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.Designer.cs create mode 100644 MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.cs diff --git a/MoonlightServers.Api/Infrastructure/Database/DataContext.cs b/MoonlightServers.Api/Infrastructure/Database/DataContext.cs index 42bd737..6eef4ec 100644 --- a/MoonlightServers.Api/Infrastructure/Database/DataContext.cs +++ b/MoonlightServers.Api/Infrastructure/Database/DataContext.cs @@ -32,7 +32,7 @@ public class DataContext : DbContext builder => { builder.MigrationsAssembly(typeof(DataContext).Assembly); - builder.MigrationsHistoryTable("__EFMigrationsHistory", "servers"); + builder.MigrationsHistoryTable("MigrationsHistory", "servers"); } ); } diff --git a/MoonlightServers.Api/Infrastructure/Database/DbMigrationService.cs b/MoonlightServers.Api/Infrastructure/Database/DbMigrationService.cs index 403c09a..03b961d 100644 --- a/MoonlightServers.Api/Infrastructure/Database/DbMigrationService.cs +++ b/MoonlightServers.Api/Infrastructure/Database/DbMigrationService.cs @@ -23,8 +23,8 @@ public class DbMigrationService : IHostedLifecycleService await using var scope = ServiceProvider.CreateAsyncScope(); var context = scope.ServiceProvider.GetRequiredService(); - var appliedMigrations = await context.Database.GetAppliedMigrationsAsync(cancellationToken); - Logger.LogTrace("Applied migrations: {names}", string.Join(", ", appliedMigrations)); + var availableMigrations = context.Database.GetMigrations(); + Logger.LogTrace("Available migrations: {names}", string.Join(", ", availableMigrations)); var pendingMigrations = await context.Database.GetPendingMigrationsAsync(cancellationToken); var migrationNames = pendingMigrations.ToArray(); diff --git a/MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.Designer.cs b/MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.Designer.cs new file mode 100644 index 0000000..ce4c817 --- /dev/null +++ b/MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.Designer.cs @@ -0,0 +1,313 @@ +// +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MoonlightServers.Api.Infrastructure.Database; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace MoonlightServers.Api.Infrastructure.Database.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20260312153948_AddedNullabilityForTemplateVariableDefaultValue")] + partial class AddedNullabilityForTemplateVariableDefaultValue + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("servers") + .HasAnnotation("ProductVersion", "10.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("HttpEndpointUrl") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("TokenId") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "servers"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.Template", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AllowUserDockerImageChange") + .HasColumnType("boolean"); + + b.Property("Author") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("DefaultDockerImageId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("DonateUrl") + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("UpdateUrl") + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("Version") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.ComplexProperty(typeof(Dictionary), "FilesConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.FilesConfig#FilesConfig", b1 => + { + b1.IsRequired(); + + b1.ComplexCollection(typeof(List>), "ConfigurationFiles", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.FilesConfig#FilesConfig.ConfigurationFiles#ConfigurationFile", b2 => + { + b2.IsRequired(); + + b2.Property("Parser") + .IsRequired(); + + b2.Property("Path") + .IsRequired(); + + b2.ComplexCollection(typeof(List>), "Mappings", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.FilesConfig#FilesConfig.ConfigurationFiles#ConfigurationFile.Mappings#ConfigurationFileMapping", b3 => + { + b3.IsRequired(); + + b3.Property("Key") + .IsRequired(); + + b3.Property("Value"); + }); + }); + + b1 + .ToJson("FilesConfig") + .HasColumnType("jsonb"); + }); + + b.ComplexProperty(typeof(Dictionary), "InstallationConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.InstallationConfig#InstallationConfig", b1 => + { + b1.IsRequired(); + + b1.Property("DockerImage") + .IsRequired(); + + b1.Property("Script") + .IsRequired(); + + b1.Property("Shell") + .IsRequired(); + + b1 + .ToJson("InstallationConfig") + .HasColumnType("jsonb"); + }); + + b.ComplexProperty(typeof(Dictionary), "LifecycleConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.LifecycleConfig#LifecycleConfig", b1 => + { + b1.IsRequired(); + + b1.PrimitiveCollection("OnlineLogPatterns") + .IsRequired(); + + b1.Property("StopCommand") + .IsRequired(); + + b1.ComplexCollection(typeof(List>), "StartupCommands", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.LifecycleConfig#LifecycleConfig.StartupCommands#StartupCommand", b2 => + { + b2.IsRequired(); + + b2.Property("Command") + .IsRequired(); + + b2.Property("DisplayName") + .IsRequired(); + }); + + b1 + .ToJson("LifecycleConfig") + .HasColumnType("jsonb"); + }); + + b.ComplexProperty(typeof(Dictionary), "MiscellaneousConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.MiscellaneousConfig#MiscellaneousConfig", b1 => + { + b1.IsRequired(); + + b1.Property("UseLegacyStartup"); + + b1 + .ToJson("MiscellaneousConfig") + .HasColumnType("jsonb"); + }); + + b.HasKey("Id"); + + b.HasIndex("DefaultDockerImageId") + .IsUnique(); + + b.ToTable("Templates", "servers"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.TemplateDockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("ImageName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("SkipPulling") + .HasColumnType("boolean"); + + b.Property("TemplateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TemplateId"); + + b.ToTable("TemplateDockerImages", "servers"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.TemplateVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DefaultValue") + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("EnvName") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("character varying(60)"); + + b.Property("TemplateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TemplateId"); + + b.ToTable("TemplateVariablesVariables", "servers"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.Template", b => + { + b.HasOne("MoonlightServers.Api.Infrastructure.Database.Entities.TemplateDockerImage", "DefaultDockerImage") + .WithOne() + .HasForeignKey("MoonlightServers.Api.Infrastructure.Database.Entities.Template", "DefaultDockerImageId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("DefaultDockerImage"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.TemplateDockerImage", b => + { + b.HasOne("MoonlightServers.Api.Infrastructure.Database.Entities.Template", "Template") + .WithMany("DockerImages") + .HasForeignKey("TemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Template"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.TemplateVariable", b => + { + b.HasOne("MoonlightServers.Api.Infrastructure.Database.Entities.Template", "Template") + .WithMany("Variables") + .HasForeignKey("TemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Template"); + }); + + modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.Template", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.cs b/MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.cs new file mode 100644 index 0000000..a2239a7 --- /dev/null +++ b/MoonlightServers.Api/Infrastructure/Database/Migrations/20260312153948_AddedNullabilityForTemplateVariableDefaultValue.cs @@ -0,0 +1,42 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MoonlightServers.Api.Infrastructure.Database.Migrations +{ + /// + public partial class AddedNullabilityForTemplateVariableDefaultValue : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DefaultValue", + schema: "servers", + table: "TemplateVariablesVariables", + type: "character varying(1024)", + maxLength: 1024, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DefaultValue", + schema: "servers", + table: "TemplateVariablesVariables", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024, + oldNullable: true); + } + } +} diff --git a/MoonlightServers.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs b/MoonlightServers.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs index 124a7e0..34c9a09 100644 --- a/MoonlightServers.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs +++ b/MoonlightServers.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs @@ -126,8 +126,7 @@ namespace MoonlightServers.Api.Infrastructure.Database.Migrations b3.Property("Key") .IsRequired(); - b3.Property("Value") - .IsRequired(); + b3.Property("Value"); }); }); @@ -239,7 +238,6 @@ namespace MoonlightServers.Api.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("DefaultValue") - .IsRequired() .HasMaxLength(1024) .HasColumnType("character varying(1024)");