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("20260821120000_AddPromotionsSchemes")] /// public partial class AddPromotionsSchemes : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "CostPrice", table: "Items", type: "decimal(65,30)", nullable: true); migrationBuilder.CreateTable( name: "Schemes", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), Name = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), RuleType = table.Column(type: "int", nullable: false), RuleConfig = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), FK_RegionId = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci"), EligibleSegment = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), DateRangeFrom = table.Column(type: "datetime(6)", nullable: false), DateRangeTo = table.Column(type: "datetime(6)", nullable: false), AgentLimitExempt = table.Column(type: "tinyint(1)", nullable: false), BaselineExpectedSales = table.Column(type: "decimal(65,30)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Schemes", x => x.Id); table.ForeignKey( name: "FK_Schemes_Regions_FK_RegionId", column: x => x.FK_RegionId, principalTable: "Regions", principalColumn: "Id"); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "SchemeRedemptions", 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_OrderId = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci"), FieldInvoiceId = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci"), DiscountAmount = table.Column(type: "decimal(65,30)", nullable: true), FK_FreeItemId = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci"), FreeQty = table.Column(type: "decimal(65,30)", nullable: true), FreeItemCostValue = table.Column(type: "decimal(65,30)", nullable: true), RedeemedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SchemeRedemptions", x => x.Id); table.ForeignKey( name: "FK_SchemeRedemptions_Schemes_FK_SchemeId", column: x => x.FK_SchemeId, principalTable: "Schemes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SchemeRedemptions_Orders_FK_OrderId", column: x => x.FK_OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SchemeRedemptions_Items_FK_FreeItemId", column: x => x.FK_FreeItemId, principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Schemes_FK_RegionId", table: "Schemes", column: "FK_RegionId"); migrationBuilder.CreateIndex( name: "IX_SchemeRedemptions_FK_SchemeId", table: "SchemeRedemptions", column: "FK_SchemeId"); migrationBuilder.CreateIndex( name: "IX_SchemeRedemptions_FK_OrderId", table: "SchemeRedemptions", column: "FK_OrderId"); migrationBuilder.CreateIndex( name: "IX_SchemeRedemptions_FK_FreeItemId", table: "SchemeRedemptions", column: "FK_FreeItemId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "SchemeRedemptions"); migrationBuilder.DropTable( name: "Schemes"); migrationBuilder.DropColumn( name: "CostPrice", table: "Items"); } } }