feat(db): EF migration AddTemplateFolders

This commit is contained in:
Joseph Doherty
2026-05-11 10:43:04 -04:00
parent e0b098d200
commit 978ac79ad8
3 changed files with 1408 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ScadaLink.ConfigurationDatabase.Migrations
{
/// <inheritdoc />
public partial class AddTemplateFolders : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "FolderId",
table: "Templates",
type: "int",
nullable: true);
migrationBuilder.CreateTable(
name: "TemplateFolders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
ParentFolderId = table.Column<int>(type: "int", nullable: true),
SortOrder = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TemplateFolders", x => x.Id);
table.ForeignKey(
name: "FK_TemplateFolders_TemplateFolders_ParentFolderId",
column: x => x.ParentFolderId,
principalTable: "TemplateFolders",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Templates_FolderId",
table: "Templates",
column: "FolderId");
migrationBuilder.CreateIndex(
name: "IX_TemplateFolders_ParentFolderId_Name",
table: "TemplateFolders",
columns: new[] { "ParentFolderId", "Name" },
unique: true,
filter: "[ParentFolderId] IS NOT NULL");
migrationBuilder.AddForeignKey(
name: "FK_Templates_TemplateFolders_FolderId",
table: "Templates",
column: "FolderId",
principalTable: "TemplateFolders",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Templates_TemplateFolders_FolderId",
table: "Templates");
migrationBuilder.DropTable(
name: "TemplateFolders");
migrationBuilder.DropIndex(
name: "IX_Templates_FolderId",
table: "Templates");
migrationBuilder.DropColumn(
name: "FolderId",
table: "Templates");
}
}
}

View File

@@ -845,6 +845,9 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
.HasMaxLength(2000)
.HasColumnType("nvarchar(2000)");
b.Property<int?>("FolderId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
@@ -855,6 +858,8 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
b.HasKey("Id");
b.HasIndex("FolderId");
b.HasIndex("Name")
.IsUnique();
@@ -982,6 +987,34 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
b.ToTable("TemplateCompositions");
});
modelBuilder.Entity("ScadaLink.Commons.Entities.Templates.TemplateFolder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<int?>("ParentFolderId")
.HasColumnType("int");
b.Property<int>("SortOrder")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ParentFolderId", "Name")
.IsUnique()
.HasFilter("[ParentFolderId] IS NOT NULL");
b.ToTable("TemplateFolders");
});
modelBuilder.Entity("ScadaLink.Commons.Entities.Templates.TemplateScript", b =>
{
b.Property<int>("Id")
@@ -1152,6 +1185,11 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
modelBuilder.Entity("ScadaLink.Commons.Entities.Templates.Template", b =>
{
b.HasOne("ScadaLink.Commons.Entities.Templates.TemplateFolder", null)
.WithMany()
.HasForeignKey("FolderId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("ScadaLink.Commons.Entities.Templates.Template", null)
.WithMany()
.HasForeignKey("ParentTemplateId")
@@ -1191,6 +1229,14 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
.IsRequired();
});
modelBuilder.Entity("ScadaLink.Commons.Entities.Templates.TemplateFolder", b =>
{
b.HasOne("ScadaLink.Commons.Entities.Templates.TemplateFolder", null)
.WithMany()
.HasForeignKey("ParentFolderId")
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity("ScadaLink.Commons.Entities.Templates.TemplateScript", b =>
{
b.HasOne("ScadaLink.Commons.Entities.Templates.Template", null)