using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace ScadaLink.ConfigurationDatabase.Migrations { /// public partial class AddTemplateFolders : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "FolderId", table: "Templates", type: "int", nullable: true); migrationBuilder.CreateTable( name: "TemplateFolders", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), ParentFolderId = table.Column(type: "int", nullable: true), SortOrder = table.Column(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); } /// 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"); } } }