Add scheme data model and migrations

This commit is contained in:
2026-08-21 14:10:40 +05:30
parent c9f5006727
commit f7101800cd
8 changed files with 694 additions and 0 deletions
@@ -0,0 +1,170 @@
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")]
/// <inheritdoc />
public partial class AddSchemeFreeGoodsRuleAndBundleComponents : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "RuleConfig",
table: "Schemes",
type: "longtext",
nullable: true,
oldClrType: typeof(string),
oldType: "longtext")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<Guid>(
name: "FK_TriggerItemId",
table: "Schemes",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<int>(
name: "TriggerQty",
table: "Schemes",
type: "int",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "FK_FreeItemId",
table: "Schemes",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<decimal>(
name: "FreeQty",
table: "Schemes",
type: "decimal(65,30)",
nullable: true);
migrationBuilder.CreateTable(
name: "SchemeBundleComponents",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_SchemeId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_ItemId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Qty = table.Column<int>(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);
}
/// <inheritdoc />
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<string>(
name: "RuleConfig",
table: "Schemes",
type: "longtext",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
}
}