using System; using Distribution.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Distribution.Migrations { [DbContext(typeof(AppDBContext))] [Migration("20260821130000_AddSchemeFreeGoodsRuleAndBundleComponents")] /// public partial class AddSchemeFreeGoodsRuleAndBundleComponents : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterColumn( name: "RuleConfig", table: "Schemes", type: "longtext", nullable: true, oldClrType: typeof(string), oldType: "longtext") .Annotation("MySql:CharSet", "utf8mb4") .OldAnnotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "FK_TriggerItemId", table: "Schemes", type: "char(36)", nullable: true, collation: "ascii_general_ci"); migrationBuilder.AddColumn( name: "TriggerQty", table: "Schemes", type: "int", nullable: true); migrationBuilder.AddColumn( name: "FK_FreeItemId", table: "Schemes", type: "char(36)", nullable: true, collation: "ascii_general_ci"); migrationBuilder.AddColumn( name: "FreeQty", table: "Schemes", type: "decimal(65,30)", nullable: true); migrationBuilder.CreateTable( name: "SchemeBundleComponents", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_SchemeId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_ItemId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), Qty = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SchemeBundleComponents", x => x.Id); table.ForeignKey( name: "FK_SchemeBundleComponents_Schemes_FK_SchemeId", column: x => x.FK_SchemeId, principalTable: "Schemes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SchemeBundleComponents_Items_FK_ItemId", column: x => x.FK_ItemId, principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Schemes_FK_TriggerItemId", table: "Schemes", column: "FK_TriggerItemId"); migrationBuilder.CreateIndex( name: "IX_Schemes_FK_FreeItemId", table: "Schemes", column: "FK_FreeItemId"); migrationBuilder.CreateIndex( name: "IX_SchemeBundleComponents_FK_SchemeId_FK_ItemId", table: "SchemeBundleComponents", columns: new[] { "FK_SchemeId", "FK_ItemId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_SchemeBundleComponents_FK_ItemId", table: "SchemeBundleComponents", column: "FK_ItemId"); migrationBuilder.AddForeignKey( name: "FK_Schemes_Items_FK_TriggerItemId", table: "Schemes", column: "FK_TriggerItemId", principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Schemes_Items_FK_FreeItemId", table: "Schemes", column: "FK_FreeItemId", principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "SchemeBundleComponents"); migrationBuilder.DropForeignKey( name: "FK_Schemes_Items_FK_TriggerItemId", table: "Schemes"); migrationBuilder.DropForeignKey( name: "FK_Schemes_Items_FK_FreeItemId", table: "Schemes"); migrationBuilder.DropIndex( name: "IX_Schemes_FK_TriggerItemId", table: "Schemes"); migrationBuilder.DropIndex( name: "IX_Schemes_FK_FreeItemId", table: "Schemes"); migrationBuilder.DropColumn( name: "FK_TriggerItemId", table: "Schemes"); migrationBuilder.DropColumn( name: "TriggerQty", table: "Schemes"); migrationBuilder.DropColumn( name: "FK_FreeItemId", table: "Schemes"); migrationBuilder.DropColumn( name: "FreeQty", table: "Schemes"); migrationBuilder.AlterColumn( name: "RuleConfig", table: "Schemes", type: "longtext", nullable: false, oldClrType: typeof(string), oldType: "longtext", oldNullable: true) .Annotation("MySql:CharSet", "utf8mb4") .OldAnnotation("MySql:CharSet", "utf8mb4"); } } }