using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace DongfangHydro.Dashboard.Api.Data.Migrations { /// public partial class ImportRealBom : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterColumn( name: "PlannedStart", table: "ProductionOrders", type: "datetime2", nullable: true, oldClrType: typeof(DateTime), oldType: "datetime2"); migrationBuilder.AlterColumn( name: "PlannedEnd", table: "ProductionOrders", type: "datetime2", nullable: true, oldClrType: typeof(DateTime), oldType: "datetime2"); migrationBuilder.AddColumn( name: "DataSource", table: "ProductionOrders", type: "nvarchar(32)", maxLength: 32, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "DrawingProductName", table: "ProductionOrders", type: "nvarchar(240)", maxLength: 240, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "ImportedAt", table: "ProductionOrders", type: "datetimeoffset", nullable: true); migrationBuilder.AddColumn( name: "ProjectName", table: "ProductionOrders", type: "nvarchar(200)", maxLength: 200, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "SourceDocumentCode", table: "ProductionOrders", type: "nvarchar(80)", maxLength: 80, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "SourceFileHash", table: "ProductionOrders", type: "nvarchar(64)", maxLength: 64, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "SourceFileName", table: "ProductionOrders", type: "nvarchar(260)", maxLength: 260, nullable: false, defaultValue: ""); migrationBuilder.Sql( "UPDATE [ProductionOrders] SET [DataSource] = 'demo' WHERE [Code] LIKE 'MO-260708-%';"); migrationBuilder.AlterColumn( name: "PlannedStart", table: "ProductionNodes", type: "datetime2", nullable: true, oldClrType: typeof(DateTime), oldType: "datetime2"); migrationBuilder.AlterColumn( name: "PlannedEnd", table: "ProductionNodes", type: "datetime2", nullable: true, oldClrType: typeof(DateTime), oldType: "datetime2"); migrationBuilder.AddColumn( name: "BomQuantity", table: "ProductionNodes", type: "decimal(18,4)", precision: 18, scale: 4, nullable: true); migrationBuilder.AddColumn( name: "BomQuantityText", table: "ProductionNodes", type: "nvarchar(80)", maxLength: 80, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "Material", table: "ProductionNodes", type: "nvarchar(120)", maxLength: 120, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "Remark", table: "ProductionNodes", type: "nvarchar(500)", maxLength: 500, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "SourceRow", table: "ProductionNodes", type: "int", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "SourceSequence", table: "ProductionNodes", type: "nvarchar(40)", maxLength: 40, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "SourceSheet", table: "ProductionNodes", type: "nvarchar(40)", maxLength: 40, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "Specification", table: "ProductionNodes", type: "nvarchar(240)", maxLength: 240, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "TotalWeight", table: "ProductionNodes", type: "decimal(18,4)", precision: 18, scale: 4, nullable: true); migrationBuilder.AddColumn( name: "TotalWeightText", table: "ProductionNodes", type: "nvarchar(80)", maxLength: 80, nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "UnitWeight", table: "ProductionNodes", type: "decimal(18,4)", precision: 18, scale: 4, nullable: true); migrationBuilder.AddColumn( name: "UnitWeightText", table: "ProductionNodes", type: "nvarchar(80)", maxLength: 80, nullable: false, defaultValue: ""); migrationBuilder.CreateTable( name: "MaterialQuotas", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), OrderId = table.Column(type: "uniqueidentifier", nullable: false), Category = table.Column(type: "nvarchar(80)", maxLength: 80, nullable: false), SourceSequence = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), MaterialCode = table.Column(type: "nvarchar(80)", maxLength: 80, nullable: false), MaterialName = table.Column(type: "nvarchar(240)", maxLength: 240, nullable: false), Specification = table.Column(type: "nvarchar(240)", maxLength: 240, nullable: false), Unit = table.Column(type: "nvarchar(24)", maxLength: 24, nullable: false), Quantity = table.Column(type: "decimal(18,4)", precision: 18, scale: 4, nullable: true), NetWeight = table.Column(type: "decimal(18,4)", precision: 18, scale: 4, nullable: true), ConsumptionQuota = table.Column(type: "decimal(18,4)", precision: 18, scale: 4, nullable: true), QuantityText = table.Column(type: "nvarchar(80)", maxLength: 80, nullable: false), NetWeightText = table.Column(type: "nvarchar(80)", maxLength: 80, nullable: false), ConsumptionQuotaText = table.Column(type: "nvarchar(80)", maxLength: 80, nullable: false), Brand = table.Column(type: "nvarchar(120)", maxLength: 120, nullable: false), Remark = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), SourceSheet = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), SourceRow = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MaterialQuotas", x => x.Id); table.ForeignKey( name: "FK_MaterialQuotas_ProductionOrders_OrderId", column: x => x.OrderId, principalTable: "ProductionOrders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ProductionOrders_SourceDocumentCode", table: "ProductionOrders", column: "SourceDocumentCode", unique: true, filter: "[SourceDocumentCode] <> ''"); migrationBuilder.CreateIndex( name: "IX_MaterialQuotas_OrderId_Category_MaterialCode", table: "MaterialQuotas", columns: new[] { "OrderId", "Category", "MaterialCode" }); migrationBuilder.CreateIndex( name: "IX_MaterialQuotas_OrderId_SourceSheet_SourceRow", table: "MaterialQuotas", columns: new[] { "OrderId", "SourceSheet", "SourceRow" }, unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "MaterialQuotas"); migrationBuilder.DropIndex( name: "IX_ProductionOrders_SourceDocumentCode", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "DataSource", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "DrawingProductName", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "ImportedAt", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "ProjectName", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "SourceDocumentCode", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "SourceFileHash", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "SourceFileName", table: "ProductionOrders"); migrationBuilder.DropColumn( name: "BomQuantity", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "BomQuantityText", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "Material", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "Remark", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "SourceRow", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "SourceSequence", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "SourceSheet", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "Specification", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "TotalWeight", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "TotalWeightText", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "UnitWeight", table: "ProductionNodes"); migrationBuilder.DropColumn( name: "UnitWeightText", table: "ProductionNodes"); migrationBuilder.AlterColumn( name: "PlannedStart", table: "ProductionOrders", type: "datetime2", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), oldClrType: typeof(DateTime), oldType: "datetime2", oldNullable: true); migrationBuilder.AlterColumn( name: "PlannedEnd", table: "ProductionOrders", type: "datetime2", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), oldClrType: typeof(DateTime), oldType: "datetime2", oldNullable: true); migrationBuilder.AlterColumn( name: "PlannedStart", table: "ProductionNodes", type: "datetime2", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), oldClrType: typeof(DateTime), oldType: "datetime2", oldNullable: true); migrationBuilder.AlterColumn( name: "PlannedEnd", table: "ProductionNodes", type: "datetime2", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), oldClrType: typeof(DateTime), oldType: "datetime2", oldNullable: true); } } }