using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional namespace Microsoft.SelfService.Portal.Core.API.Migrations { /// public partial class AddGenericTargetModel : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_DeploymentExecutions_VirtualMachines_VirtualMachineId", table: "DeploymentExecutions"); migrationBuilder.DropForeignKey( name: "FK_DeploymentTargetAssignments_VirtualMachines_VirtualMachineId", table: "DeploymentTargetAssignments"); migrationBuilder.DropForeignKey( name: "FK_VirtualMachines_Domains_DomainID", table: "VirtualMachines"); migrationBuilder.DropPrimaryKey( name: "PK_VirtualMachines", table: "VirtualMachines"); migrationBuilder.RenameTable( name: "VirtualMachines", newName: "Targets"); migrationBuilder.RenameColumn( name: "VirtualMachineId", table: "DeploymentTargetAssignments", newName: "TargetId"); migrationBuilder.RenameIndex( name: "IX_DeploymentTargetAssignments_VirtualMachineId", table: "DeploymentTargetAssignments", newName: "IX_DeploymentTargetAssignments_TargetId"); migrationBuilder.RenameIndex( name: "IX_DeploymentTargetAssignments_DeploymentGroupId_VirtualMachineId_RoleKey", table: "DeploymentTargetAssignments", newName: "IX_DeploymentTargetAssignments_DeploymentGroupId_TargetId_RoleKey"); migrationBuilder.RenameColumn( name: "VirtualMachineId", table: "DeploymentJobTargets", newName: "TargetId"); migrationBuilder.RenameColumn( name: "VirtualMachineId", table: "DeploymentExecutions", newName: "TargetId"); migrationBuilder.RenameIndex( name: "IX_VirtualMachines_DomainID", table: "Targets", newName: "IX_Targets_DomainID"); migrationBuilder.AddColumn( name: "ProviderType", table: "Targets", type: "nvarchar(64)", maxLength: 64, nullable: false, defaultValue: "OnPrem"); migrationBuilder.AddColumn( name: "TargetType", table: "Targets", type: "nvarchar(64)", maxLength: 64, nullable: false, defaultValue: "VirtualMachine"); migrationBuilder.AddPrimaryKey( name: "PK_Targets", table: "Targets", column: "Id"); migrationBuilder.InsertData( table: "Targets", columns: new[] { "Id", "Created", "CreatedBy", "DomainID", "ExternalId", "MetadataJson", "Modified", "ModifiedBy", "Name", "ProviderType", "TargetType" }, values: new object[,] { { new Guid("30000000-0000-0000-0000-000000000006"), new DateTime(2026, 7, 7, 0, 0, 0, 0, DateTimeKind.Utc), "DemoSeed", null, "11111111-1111-1111-1111-111111111111", "{\"environment\":\"Production\",\"workload\":\"M365\"}", new DateTime(2026, 7, 7, 0, 0, 0, 0, DateTimeKind.Utc), "DemoSeed", "contoso.onmicrosoft.com", "Microsoft365", "Tenant" }, { new Guid("30000000-0000-0000-0000-000000000007"), new DateTime(2026, 7, 7, 0, 0, 0, 0, DateTimeKind.Utc), "DemoSeed", null, "Teams.StandardUsers", "{\"workload\":\"Teams\",\"scope\":\"StandardUsers\"}", new DateTime(2026, 7, 7, 0, 0, 0, 0, DateTimeKind.Utc), "DemoSeed", "Teams - Standard Users", "Microsoft365", "PolicyScope" } }); migrationBuilder.AddForeignKey( name: "FK_Targets_Domains_DomainID", table: "Targets", column: "DomainID", principalTable: "Domains", principalColumn: "Id"); migrationBuilder.AddForeignKey( name: "FK_DeploymentExecutions_Targets_TargetId", table: "DeploymentExecutions", column: "TargetId", principalTable: "Targets", principalColumn: "Id", onDelete: ReferentialAction.Cascade); migrationBuilder.AddForeignKey( name: "FK_DeploymentTargetAssignments_Targets_TargetId", table: "DeploymentTargetAssignments", column: "TargetId", principalTable: "Targets", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_DeploymentExecutions_Targets_TargetId", table: "DeploymentExecutions"); migrationBuilder.DropForeignKey( name: "FK_DeploymentTargetAssignments_Targets_TargetId", table: "DeploymentTargetAssignments"); migrationBuilder.DropForeignKey( name: "FK_Targets_Domains_DomainID", table: "Targets"); migrationBuilder.DeleteData( table: "Targets", keyColumn: "Id", keyValue: new Guid("30000000-0000-0000-0000-000000000006")); migrationBuilder.DeleteData( table: "Targets", keyColumn: "Id", keyValue: new Guid("30000000-0000-0000-0000-000000000007")); migrationBuilder.DropPrimaryKey( name: "PK_Targets", table: "Targets"); migrationBuilder.DropColumn( name: "ProviderType", table: "Targets"); migrationBuilder.DropColumn( name: "TargetType", table: "Targets"); migrationBuilder.RenameTable( name: "Targets", newName: "VirtualMachines"); migrationBuilder.RenameColumn( name: "TargetId", table: "DeploymentTargetAssignments", newName: "VirtualMachineId"); migrationBuilder.RenameIndex( name: "IX_DeploymentTargetAssignments_TargetId", table: "DeploymentTargetAssignments", newName: "IX_DeploymentTargetAssignments_VirtualMachineId"); migrationBuilder.RenameIndex( name: "IX_DeploymentTargetAssignments_DeploymentGroupId_TargetId_RoleKey", table: "DeploymentTargetAssignments", newName: "IX_DeploymentTargetAssignments_DeploymentGroupId_VirtualMachineId_RoleKey"); migrationBuilder.RenameColumn( name: "TargetId", table: "DeploymentJobTargets", newName: "VirtualMachineId"); migrationBuilder.RenameColumn( name: "TargetId", table: "DeploymentExecutions", newName: "VirtualMachineId"); migrationBuilder.RenameIndex( name: "IX_Targets_DomainID", table: "VirtualMachines", newName: "IX_VirtualMachines_DomainID"); migrationBuilder.AddPrimaryKey( name: "PK_VirtualMachines", table: "VirtualMachines", column: "Id"); migrationBuilder.AddForeignKey( name: "FK_VirtualMachines_Domains_DomainID", table: "VirtualMachines", column: "DomainID", principalTable: "Domains", principalColumn: "Id"); migrationBuilder.AddForeignKey( name: "FK_DeploymentExecutions_VirtualMachines_VirtualMachineId", table: "DeploymentExecutions", column: "VirtualMachineId", principalTable: "VirtualMachines", principalColumn: "Id", onDelete: ReferentialAction.Cascade); migrationBuilder.AddForeignKey( name: "FK_DeploymentTargetAssignments_VirtualMachines_VirtualMachineId", table: "DeploymentTargetAssignments", column: "VirtualMachineId", principalTable: "VirtualMachines", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } } }