using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Hcs.WebApp.Data.Hcs.Migrations { /// public partial class CreateHcsSchema : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Campaigns", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Type = table.Column(type: "nvarchar(max)", nullable: false), InitiatorId = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), StartedAt = table.Column(type: "datetime2", nullable: true), EndedAt = table.Column(type: "datetime2", nullable: true), Step = table.Column(type: "int", nullable: false), FailureReason = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Campaigns", x => x.Id); }); migrationBuilder.CreateTable( name: "Operations", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CampaignId = table.Column(type: "int", nullable: false), Type = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), StartedAt = table.Column(type: "datetime2", nullable: true), EndedAt = table.Column(type: "datetime2", nullable: true), MessageGuid = table.Column(type: "nvarchar(max)", nullable: true), FailureReason = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Operations", x => x.Id); table.ForeignKey( name: "FK_Operations_Campaigns_CampaignId", column: x => x.CampaignId, principalTable: "Campaigns", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Registries", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Number = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), IsCommon = table.Column(type: "bit", nullable: false), SyncedAt = table.Column(type: "datetime2", nullable: true), LastSyncOperationId = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Registries", x => x.Id); table.ForeignKey( name: "FK_Registries_Operations_LastSyncOperationId", column: x => x.LastSyncOperationId, principalTable: "Operations", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Elements", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), RegistryId = table.Column(type: "uniqueidentifier", nullable: false), Code = table.Column(type: "nvarchar(max)", nullable: false), GUID = table.Column(type: "nvarchar(max)", nullable: false), Json = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Elements", x => x.Id); table.ForeignKey( name: "FK_Elements_Registries_RegistryId", column: x => x.RegistryId, principalTable: "Registries", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Elements_RegistryId", table: "Elements", column: "RegistryId"); migrationBuilder.CreateIndex( name: "IX_Operations_CampaignId", table: "Operations", column: "CampaignId"); migrationBuilder.CreateIndex( name: "IX_Registries_LastSyncOperationId", table: "Registries", column: "LastSyncOperationId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Elements"); migrationBuilder.DropTable( name: "Registries"); migrationBuilder.DropTable( name: "Operations"); migrationBuilder.DropTable( name: "Campaigns"); } } }