Renamed migration table. Added nullability to template variable migration

This commit is contained in:
2026-03-12 15:45:51 +00:00
parent 2fc371c219
commit 91887ec047
5 changed files with 359 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ public class DataContext : DbContext
builder => builder =>
{ {
builder.MigrationsAssembly(typeof(DataContext).Assembly); builder.MigrationsAssembly(typeof(DataContext).Assembly);
builder.MigrationsHistoryTable("__EFMigrationsHistory", "servers"); builder.MigrationsHistoryTable("MigrationsHistory", "servers");
} }
); );
} }

View File

@@ -23,8 +23,8 @@ public class DbMigrationService : IHostedLifecycleService
await using var scope = ServiceProvider.CreateAsyncScope(); await using var scope = ServiceProvider.CreateAsyncScope();
var context = scope.ServiceProvider.GetRequiredService<DataContext>(); var context = scope.ServiceProvider.GetRequiredService<DataContext>();
var appliedMigrations = await context.Database.GetAppliedMigrationsAsync(cancellationToken); var availableMigrations = context.Database.GetMigrations();
Logger.LogTrace("Applied migrations: {names}", string.Join(", ", appliedMigrations)); Logger.LogTrace("Available migrations: {names}", string.Join(", ", availableMigrations));
var pendingMigrations = await context.Database.GetPendingMigrationsAsync(cancellationToken); var pendingMigrations = await context.Database.GetPendingMigrationsAsync(cancellationToken);
var migrationNames = pendingMigrations.ToArray(); var migrationNames = pendingMigrations.ToArray();

View File

@@ -0,0 +1,313 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("HttpEndpointUrl")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Token")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("TokenId")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Nodes", "servers");
});
modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AllowUserDockerImageChange")
.HasColumnType("boolean");
b.Property<string>("Author")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<int?>("DefaultDockerImageId")
.HasColumnType("integer");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("DonateUrl")
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<string>("UpdateUrl")
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.Property<string>("Version")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.ComplexProperty(typeof(Dictionary<string, object>), "FilesConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.FilesConfig#FilesConfig", b1 =>
{
b1.IsRequired();
b1.ComplexCollection(typeof(List<Dictionary<string, object>>), "ConfigurationFiles", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.FilesConfig#FilesConfig.ConfigurationFiles#ConfigurationFile", b2 =>
{
b2.IsRequired();
b2.Property<string>("Parser")
.IsRequired();
b2.Property<string>("Path")
.IsRequired();
b2.ComplexCollection(typeof(List<Dictionary<string, object>>), "Mappings", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.FilesConfig#FilesConfig.ConfigurationFiles#ConfigurationFile.Mappings#ConfigurationFileMapping", b3 =>
{
b3.IsRequired();
b3.Property<string>("Key")
.IsRequired();
b3.Property<string>("Value");
});
});
b1
.ToJson("FilesConfig")
.HasColumnType("jsonb");
});
b.ComplexProperty(typeof(Dictionary<string, object>), "InstallationConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.InstallationConfig#InstallationConfig", b1 =>
{
b1.IsRequired();
b1.Property<string>("DockerImage")
.IsRequired();
b1.Property<string>("Script")
.IsRequired();
b1.Property<string>("Shell")
.IsRequired();
b1
.ToJson("InstallationConfig")
.HasColumnType("jsonb");
});
b.ComplexProperty(typeof(Dictionary<string, object>), "LifecycleConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.LifecycleConfig#LifecycleConfig", b1 =>
{
b1.IsRequired();
b1.PrimitiveCollection<string>("OnlineLogPatterns")
.IsRequired();
b1.Property<string>("StopCommand")
.IsRequired();
b1.ComplexCollection(typeof(List<Dictionary<string, object>>), "StartupCommands", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.LifecycleConfig#LifecycleConfig.StartupCommands#StartupCommand", b2 =>
{
b2.IsRequired();
b2.Property<string>("Command")
.IsRequired();
b2.Property<string>("DisplayName")
.IsRequired();
});
b1
.ToJson("LifecycleConfig")
.HasColumnType("jsonb");
});
b.ComplexProperty(typeof(Dictionary<string, object>), "MiscellaneousConfig", "MoonlightServers.Api.Infrastructure.Database.Entities.Template.MiscellaneousConfig#MiscellaneousConfig", b1 =>
{
b1.IsRequired();
b1.Property<bool>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<string>("ImageName")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<bool>("SkipPulling")
.HasColumnType("boolean");
b.Property<int>("TemplateId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("TemplateId");
b.ToTable("TemplateDockerImages", "servers");
});
modelBuilder.Entity("MoonlightServers.Api.Infrastructure.Database.Entities.TemplateVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("DefaultValue")
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<string>("EnvName")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("character varying(60)");
b.Property<int>("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
}
}
}

View File

@@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MoonlightServers.Api.Infrastructure.Database.Migrations
{
/// <inheritdoc />
public partial class AddedNullabilityForTemplateVariableDefaultValue : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "DefaultValue",
schema: "servers",
table: "TemplateVariablesVariables",
type: "character varying(1024)",
maxLength: 1024,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(1024)",
oldMaxLength: 1024);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
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);
}
}
}

View File

@@ -126,8 +126,7 @@ namespace MoonlightServers.Api.Infrastructure.Database.Migrations
b3.Property<string>("Key") b3.Property<string>("Key")
.IsRequired(); .IsRequired();
b3.Property<string>("Value") b3.Property<string>("Value");
.IsRequired();
}); });
}); });
@@ -239,7 +238,6 @@ namespace MoonlightServers.Api.Infrastructure.Database.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("DefaultValue") b.Property<string>("DefaultValue")
.IsRequired()
.HasMaxLength(1024) .HasMaxLength(1024)
.HasColumnType("character varying(1024)"); .HasColumnType("character varying(1024)");